|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef _nsCacheSession_h_ |
|
8 #define _nsCacheSession_h_ |
|
9 |
|
10 #include "nspr.h" |
|
11 #include "nsError.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsICacheSession.h" |
|
14 #include "nsIFile.h" |
|
15 #include "nsString.h" |
|
16 |
|
17 class nsCacheSession : public nsICacheSession |
|
18 { |
|
19 public: |
|
20 NS_DECL_ISUPPORTS |
|
21 NS_DECL_NSICACHESESSION |
|
22 |
|
23 nsCacheSession(const char * clientID, nsCacheStoragePolicy storagePolicy, bool streamBased); |
|
24 virtual ~nsCacheSession(); |
|
25 |
|
26 nsCString * ClientID() { return &mClientID; } |
|
27 |
|
28 enum SessionInfo { |
|
29 eStoragePolicyMask = 0x000000FF, |
|
30 eStreamBasedMask = 0x00000100, |
|
31 eDoomEntriesIfExpiredMask = 0x00001000, |
|
32 ePrivateMask = 0x00010000 |
|
33 }; |
|
34 |
|
35 void MarkStreamBased() { mInfo |= eStreamBasedMask; } |
|
36 void ClearStreamBased() { mInfo &= ~eStreamBasedMask; } |
|
37 bool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; } |
|
38 |
|
39 void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; } |
|
40 void ClearDoomEntriesIfExpired() { mInfo &= ~eDoomEntriesIfExpiredMask; } |
|
41 bool WillDoomEntriesIfExpired() { return (0 != (mInfo & eDoomEntriesIfExpiredMask)); } |
|
42 |
|
43 void MarkPrivate() { mInfo |= ePrivateMask; } |
|
44 void MarkPublic() { mInfo &= ~ePrivateMask; } |
|
45 bool IsPrivate() { return (mInfo & ePrivateMask) != 0; } |
|
46 nsCacheStoragePolicy StoragePolicy() |
|
47 { |
|
48 return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask); |
|
49 } |
|
50 |
|
51 void SetStoragePolicy(nsCacheStoragePolicy policy) |
|
52 { |
|
53 NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy"); |
|
54 mInfo &= ~eStoragePolicyMask; // clear storage policy bits |
|
55 mInfo |= policy; |
|
56 } |
|
57 |
|
58 nsIFile* ProfileDir() { return mProfileDir; } |
|
59 |
|
60 private: |
|
61 nsCString mClientID; |
|
62 uint32_t mInfo; |
|
63 nsCOMPtr<nsIFile> mProfileDir; |
|
64 }; |
|
65 |
|
66 #endif // _nsCacheSession_h_ |