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.
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* functions for restoring saved values at the end of a C++ scope */
8 #ifndef mozilla_AutoRestore_h_
9 #define mozilla_AutoRestore_h_
11 #include "mozilla/Attributes.h" // MOZ_STACK_CLASS
12 #include "mozilla/GuardObjects.h"
14 namespace mozilla {
16 /**
17 * Save the current value of a variable and restore it when the object
18 * goes out of scope. For example:
19 * {
20 * AutoRestore<bool> savePainting(mIsPainting);
21 * mIsPainting = true;
22 *
23 * // ... your code here ...
24 *
25 * // mIsPainting is reset to its old value at the end of this block
26 * }
27 */
28 template <class T>
29 class MOZ_STACK_CLASS AutoRestore
30 {
31 private:
32 T& mLocation;
33 T mValue;
34 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
35 public:
36 AutoRestore(T& aValue MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
37 : mLocation(aValue), mValue(aValue)
38 {
39 MOZ_GUARD_OBJECT_NOTIFIER_INIT;
40 }
41 ~AutoRestore() { mLocation = mValue; }
42 };
44 } // namespace mozilla
46 #endif /* !defined(mozilla_AutoRestore_h_) */