nsCacheSession.h 2.1 KB

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