Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozStorageBindingParamsArray_h |
michael@0 | 8 | #define mozStorageBindingParamsArray_h |
michael@0 | 9 | |
michael@0 | 10 | #include "nsAutoPtr.h" |
michael@0 | 11 | #include "nsTArray.h" |
michael@0 | 12 | #include "mozilla/Attributes.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "mozIStorageBindingParamsArray.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace storage { |
michael@0 | 18 | |
michael@0 | 19 | class StorageBaseStatementInternal; |
michael@0 | 20 | |
michael@0 | 21 | class BindingParamsArray MOZ_FINAL : public mozIStorageBindingParamsArray |
michael@0 | 22 | { |
michael@0 | 23 | typedef nsTArray< nsCOMPtr<mozIStorageBindingParams> > array_type; |
michael@0 | 24 | |
michael@0 | 25 | public: |
michael@0 | 26 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 27 | NS_DECL_MOZISTORAGEBINDINGPARAMSARRAY |
michael@0 | 28 | |
michael@0 | 29 | BindingParamsArray(StorageBaseStatementInternal *aOwningStatement); |
michael@0 | 30 | |
michael@0 | 31 | typedef array_type::size_type size_type; |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * Locks the array and prevents further modification to it (such as adding |
michael@0 | 35 | * more elements to it). |
michael@0 | 36 | */ |
michael@0 | 37 | void lock(); |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * @return the pointer to the owning BindingParamsArray. |
michael@0 | 41 | */ |
michael@0 | 42 | const StorageBaseStatementInternal *getOwner() const; |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * @return the number of elemets the array contains. |
michael@0 | 46 | */ |
michael@0 | 47 | const size_type length() const { return mArray.Length(); } |
michael@0 | 48 | |
michael@0 | 49 | class iterator { |
michael@0 | 50 | public: |
michael@0 | 51 | iterator(BindingParamsArray *aArray, |
michael@0 | 52 | uint32_t aIndex) |
michael@0 | 53 | : mArray(aArray) |
michael@0 | 54 | , mIndex(aIndex) |
michael@0 | 55 | { |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | iterator &operator++(int) |
michael@0 | 59 | { |
michael@0 | 60 | mIndex++; |
michael@0 | 61 | return *this; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | bool operator==(const iterator &aOther) const |
michael@0 | 65 | { |
michael@0 | 66 | return mIndex == aOther.mIndex; |
michael@0 | 67 | } |
michael@0 | 68 | bool operator!=(const iterator &aOther) const |
michael@0 | 69 | { |
michael@0 | 70 | return !(*this == aOther); |
michael@0 | 71 | } |
michael@0 | 72 | mozIStorageBindingParams *operator*() |
michael@0 | 73 | { |
michael@0 | 74 | NS_ASSERTION(mIndex < mArray->length(), |
michael@0 | 75 | "Dereferenceing an invalid value!"); |
michael@0 | 76 | return mArray->mArray[mIndex].get(); |
michael@0 | 77 | } |
michael@0 | 78 | private: |
michael@0 | 79 | void operator--() { } |
michael@0 | 80 | BindingParamsArray *mArray; |
michael@0 | 81 | uint32_t mIndex; |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Obtains an iterator pointing to the beginning of the array. |
michael@0 | 86 | */ |
michael@0 | 87 | inline iterator begin() |
michael@0 | 88 | { |
michael@0 | 89 | NS_ASSERTION(length() != 0, |
michael@0 | 90 | "Obtaining an iterator to the beginning with no elements!"); |
michael@0 | 91 | return iterator(this, 0); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * Obtains an iterator pointing to the end of the array. |
michael@0 | 96 | */ |
michael@0 | 97 | inline iterator end() |
michael@0 | 98 | { |
michael@0 | 99 | NS_ASSERTION(mLocked, |
michael@0 | 100 | "Obtaining an iterator to the end when we are not locked!"); |
michael@0 | 101 | return iterator(this, length()); |
michael@0 | 102 | } |
michael@0 | 103 | private: |
michael@0 | 104 | nsCOMPtr<StorageBaseStatementInternal> mOwningStatement; |
michael@0 | 105 | array_type mArray; |
michael@0 | 106 | bool mLocked; |
michael@0 | 107 | |
michael@0 | 108 | friend class iterator; |
michael@0 | 109 | }; |
michael@0 | 110 | |
michael@0 | 111 | } // namespace storage |
michael@0 | 112 | } // namespace mozilla |
michael@0 | 113 | |
michael@0 | 114 | #endif // mozStorageBindingParamsArray_h |