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 | #include "mozStorageBindingParamsArray.h" |
michael@0 | 8 | #include "mozStorageBindingParams.h" |
michael@0 | 9 | #include "StorageBaseStatementInternal.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace storage { |
michael@0 | 13 | |
michael@0 | 14 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 15 | //// BindingParamsArray |
michael@0 | 16 | |
michael@0 | 17 | BindingParamsArray::BindingParamsArray( |
michael@0 | 18 | StorageBaseStatementInternal *aOwningStatement |
michael@0 | 19 | ) |
michael@0 | 20 | : mOwningStatement(aOwningStatement) |
michael@0 | 21 | , mLocked(false) |
michael@0 | 22 | { |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | void |
michael@0 | 26 | BindingParamsArray::lock() |
michael@0 | 27 | { |
michael@0 | 28 | NS_ASSERTION(mLocked == false, "Array has already been locked!"); |
michael@0 | 29 | mLocked = true; |
michael@0 | 30 | |
michael@0 | 31 | // We also no longer need to hold a reference to our statement since it owns |
michael@0 | 32 | // us. |
michael@0 | 33 | mOwningStatement = nullptr; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | const StorageBaseStatementInternal * |
michael@0 | 37 | BindingParamsArray::getOwner() const |
michael@0 | 38 | { |
michael@0 | 39 | return mOwningStatement; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | NS_IMPL_ISUPPORTS( |
michael@0 | 43 | BindingParamsArray, |
michael@0 | 44 | mozIStorageBindingParamsArray |
michael@0 | 45 | ) |
michael@0 | 46 | |
michael@0 | 47 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 48 | //// mozIStorageBindingParamsArray |
michael@0 | 49 | |
michael@0 | 50 | NS_IMETHODIMP |
michael@0 | 51 | BindingParamsArray::NewBindingParams(mozIStorageBindingParams **_params) |
michael@0 | 52 | { |
michael@0 | 53 | NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED); |
michael@0 | 54 | |
michael@0 | 55 | nsCOMPtr<mozIStorageBindingParams> params( |
michael@0 | 56 | mOwningStatement->newBindingParams(this)); |
michael@0 | 57 | NS_ENSURE_TRUE(params, NS_ERROR_UNEXPECTED); |
michael@0 | 58 | |
michael@0 | 59 | params.forget(_params); |
michael@0 | 60 | return NS_OK; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | NS_IMETHODIMP |
michael@0 | 64 | BindingParamsArray::AddParams(mozIStorageBindingParams *aParameters) |
michael@0 | 65 | { |
michael@0 | 66 | NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED); |
michael@0 | 67 | |
michael@0 | 68 | BindingParams *params = static_cast<BindingParams *>(aParameters); |
michael@0 | 69 | |
michael@0 | 70 | // Check to make sure that this set of parameters was created with us. |
michael@0 | 71 | if (params->getOwner() != this) |
michael@0 | 72 | return NS_ERROR_UNEXPECTED; |
michael@0 | 73 | |
michael@0 | 74 | NS_ENSURE_TRUE(mArray.AppendElement(params), NS_ERROR_OUT_OF_MEMORY); |
michael@0 | 75 | |
michael@0 | 76 | // Lock the parameters only after we've successfully added them. |
michael@0 | 77 | params->lock(); |
michael@0 | 78 | |
michael@0 | 79 | return NS_OK; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | NS_IMETHODIMP |
michael@0 | 83 | BindingParamsArray::GetLength(uint32_t *_length) |
michael@0 | 84 | { |
michael@0 | 85 | *_length = length(); |
michael@0 | 86 | return NS_OK; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | } // namespace storage |
michael@0 | 90 | } // namespace mozilla |