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 mozStorageBindingParams_h |
michael@0 | 8 | #define mozStorageBindingParams_h |
michael@0 | 9 | |
michael@0 | 10 | #include "nsCOMArray.h" |
michael@0 | 11 | #include "nsIVariant.h" |
michael@0 | 12 | #include "nsInterfaceHashtable.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "mozStorageBindingParamsArray.h" |
michael@0 | 15 | #include "mozStorageStatement.h" |
michael@0 | 16 | #include "mozStorageAsyncStatement.h" |
michael@0 | 17 | |
michael@0 | 18 | #include "mozIStorageBindingParams.h" |
michael@0 | 19 | #include "IStorageBindingParamsInternal.h" |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | namespace storage { |
michael@0 | 23 | |
michael@0 | 24 | class BindingParams : public mozIStorageBindingParams |
michael@0 | 25 | , public IStorageBindingParamsInternal |
michael@0 | 26 | { |
michael@0 | 27 | public: |
michael@0 | 28 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 29 | NS_DECL_MOZISTORAGEBINDINGPARAMS |
michael@0 | 30 | NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * Locks the parameters and prevents further modification to it (such as |
michael@0 | 34 | * binding more elements to it). |
michael@0 | 35 | */ |
michael@0 | 36 | void lock(); |
michael@0 | 37 | |
michael@0 | 38 | /** |
michael@0 | 39 | * Unlocks the parameters and allows modification to it again. |
michael@0 | 40 | * |
michael@0 | 41 | * @param aOwningStatement |
michael@0 | 42 | * The statement that owns us. We cleared this when we were locked, |
michael@0 | 43 | * and our invariant requires us to have this, so you need to tell us |
michael@0 | 44 | * again. |
michael@0 | 45 | */ |
michael@0 | 46 | void unlock(Statement *aOwningStatement); |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * @returns the pointer to the owning BindingParamsArray. Used by a |
michael@0 | 50 | * BindingParamsArray to verify that we belong to it when added. |
michael@0 | 51 | */ |
michael@0 | 52 | const mozIStorageBindingParamsArray *getOwner() const; |
michael@0 | 53 | |
michael@0 | 54 | BindingParams(mozIStorageBindingParamsArray *aOwningArray, |
michael@0 | 55 | Statement *aOwningStatement); |
michael@0 | 56 | virtual ~BindingParams() {} |
michael@0 | 57 | |
michael@0 | 58 | protected: |
michael@0 | 59 | BindingParams(mozIStorageBindingParamsArray *aOwningArray); |
michael@0 | 60 | nsCOMArray<nsIVariant> mParameters; |
michael@0 | 61 | bool mLocked; |
michael@0 | 62 | |
michael@0 | 63 | private: |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Track the BindingParamsArray that created us until we are added to it. |
michael@0 | 67 | * (Once we are added we are locked and no one needs to look up our owner.) |
michael@0 | 68 | * Ref-counted since there is no invariant that guarantees it stays alive |
michael@0 | 69 | * otherwise. This keeps mOwningStatement alive for us too since the array |
michael@0 | 70 | * also holds a reference. |
michael@0 | 71 | */ |
michael@0 | 72 | nsCOMPtr<mozIStorageBindingParamsArray> mOwningArray; |
michael@0 | 73 | /** |
michael@0 | 74 | * Used in the synchronous binding case to map parameter names to indices. |
michael@0 | 75 | * Not reference-counted because this is only non-null as long as mOwningArray |
michael@0 | 76 | * is non-null and mOwningArray also holds a statement reference. |
michael@0 | 77 | */ |
michael@0 | 78 | Statement *mOwningStatement; |
michael@0 | 79 | uint32_t mParamCount; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Adds late resolution of named parameters so they don't get resolved until we |
michael@0 | 84 | * try and bind the parameters on the async thread. We also stop checking |
michael@0 | 85 | * parameter indices for being too big since we just just don't know how many |
michael@0 | 86 | * there are. |
michael@0 | 87 | * |
michael@0 | 88 | * We support *either* binding by name or binding by index. Trying to do both |
michael@0 | 89 | * results in only binding by name at sqlite3_stmt bind time. |
michael@0 | 90 | */ |
michael@0 | 91 | class AsyncBindingParams : public BindingParams |
michael@0 | 92 | { |
michael@0 | 93 | public: |
michael@0 | 94 | NS_IMETHOD BindByName(const nsACString & aName, |
michael@0 | 95 | nsIVariant *aValue); |
michael@0 | 96 | NS_IMETHOD BindByIndex(uint32_t aIndex, nsIVariant *aValue); |
michael@0 | 97 | |
michael@0 | 98 | virtual already_AddRefed<mozIStorageError> bind(sqlite3_stmt * aStatement); |
michael@0 | 99 | |
michael@0 | 100 | AsyncBindingParams(mozIStorageBindingParamsArray *aOwningArray); |
michael@0 | 101 | virtual ~AsyncBindingParams() {} |
michael@0 | 102 | |
michael@0 | 103 | private: |
michael@0 | 104 | nsInterfaceHashtable<nsCStringHashKey, nsIVariant> mNamedParameters; |
michael@0 | 105 | |
michael@0 | 106 | struct NamedParameterIterationClosureThunk |
michael@0 | 107 | { |
michael@0 | 108 | AsyncBindingParams *self; |
michael@0 | 109 | sqlite3_stmt *statement; |
michael@0 | 110 | nsCOMPtr<mozIStorageError> err; |
michael@0 | 111 | }; |
michael@0 | 112 | |
michael@0 | 113 | static PLDHashOperator iterateOverNamedParameters(const nsACString &aName, |
michael@0 | 114 | nsIVariant *aValue, |
michael@0 | 115 | void *voidClosureThunk); |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | } // namespace storage |
michael@0 | 119 | } // namespace mozilla |
michael@0 | 120 | |
michael@0 | 121 | #endif // mozStorageBindingParams_h |