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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
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 _nsCacheSession_h_ |
michael@0 | 8 | #define _nsCacheSession_h_ |
michael@0 | 9 | |
michael@0 | 10 | #include "nspr.h" |
michael@0 | 11 | #include "nsError.h" |
michael@0 | 12 | #include "nsCOMPtr.h" |
michael@0 | 13 | #include "nsICacheSession.h" |
michael@0 | 14 | #include "nsIFile.h" |
michael@0 | 15 | #include "nsString.h" |
michael@0 | 16 | |
michael@0 | 17 | class nsCacheSession : public nsICacheSession |
michael@0 | 18 | { |
michael@0 | 19 | public: |
michael@0 | 20 | NS_DECL_ISUPPORTS |
michael@0 | 21 | NS_DECL_NSICACHESESSION |
michael@0 | 22 | |
michael@0 | 23 | nsCacheSession(const char * clientID, nsCacheStoragePolicy storagePolicy, bool streamBased); |
michael@0 | 24 | virtual ~nsCacheSession(); |
michael@0 | 25 | |
michael@0 | 26 | nsCString * ClientID() { return &mClientID; } |
michael@0 | 27 | |
michael@0 | 28 | enum SessionInfo { |
michael@0 | 29 | eStoragePolicyMask = 0x000000FF, |
michael@0 | 30 | eStreamBasedMask = 0x00000100, |
michael@0 | 31 | eDoomEntriesIfExpiredMask = 0x00001000, |
michael@0 | 32 | ePrivateMask = 0x00010000 |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | void MarkStreamBased() { mInfo |= eStreamBasedMask; } |
michael@0 | 36 | void ClearStreamBased() { mInfo &= ~eStreamBasedMask; } |
michael@0 | 37 | bool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; } |
michael@0 | 38 | |
michael@0 | 39 | void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; } |
michael@0 | 40 | void ClearDoomEntriesIfExpired() { mInfo &= ~eDoomEntriesIfExpiredMask; } |
michael@0 | 41 | bool WillDoomEntriesIfExpired() { return (0 != (mInfo & eDoomEntriesIfExpiredMask)); } |
michael@0 | 42 | |
michael@0 | 43 | void MarkPrivate() { mInfo |= ePrivateMask; } |
michael@0 | 44 | void MarkPublic() { mInfo &= ~ePrivateMask; } |
michael@0 | 45 | bool IsPrivate() { return (mInfo & ePrivateMask) != 0; } |
michael@0 | 46 | nsCacheStoragePolicy StoragePolicy() |
michael@0 | 47 | { |
michael@0 | 48 | return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | void SetStoragePolicy(nsCacheStoragePolicy policy) |
michael@0 | 52 | { |
michael@0 | 53 | NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy"); |
michael@0 | 54 | mInfo &= ~eStoragePolicyMask; // clear storage policy bits |
michael@0 | 55 | mInfo |= policy; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | nsIFile* ProfileDir() { return mProfileDir; } |
michael@0 | 59 | |
michael@0 | 60 | private: |
michael@0 | 61 | nsCString mClientID; |
michael@0 | 62 | uint32_t mInfo; |
michael@0 | 63 | nsCOMPtr<nsIFile> mProfileDir; |
michael@0 | 64 | }; |
michael@0 | 65 | |
michael@0 | 66 | #endif // _nsCacheSession_h_ |