nsDiskCacheEntry.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 _nsDiskCacheEntry_h_
  7. #define _nsDiskCacheEntry_h_
  8. #include "nsDiskCacheMap.h"
  9. #include "nsCacheEntry.h"
  10. /******************************************************************************
  11. * nsDiskCacheEntry
  12. *****************************************************************************/
  13. struct nsDiskCacheEntry {
  14. uint32_t mHeaderVersion; // useful for stand-alone metadata files
  15. uint32_t mMetaLocation; // for verification
  16. int32_t mFetchCount;
  17. uint32_t mLastFetched;
  18. uint32_t mLastModified;
  19. uint32_t mExpirationTime;
  20. uint32_t mDataSize;
  21. uint32_t mKeySize; // includes terminating null byte
  22. uint32_t mMetaDataSize; // includes terminating null byte
  23. // followed by key data (mKeySize bytes)
  24. // followed by meta data (mMetaDataSize bytes)
  25. uint32_t Size() { return sizeof(nsDiskCacheEntry) +
  26. mKeySize + mMetaDataSize;
  27. }
  28. char* Key() { return reinterpret_cast<char*>(this) +
  29. sizeof(nsDiskCacheEntry);
  30. }
  31. char* MetaData()
  32. { return Key() + mKeySize; }
  33. nsCacheEntry * CreateCacheEntry(nsCacheDevice * device);
  34. void Swap() // host to network (memory to disk)
  35. {
  36. #if defined(IS_LITTLE_ENDIAN)
  37. mHeaderVersion = htonl(mHeaderVersion);
  38. mMetaLocation = htonl(mMetaLocation);
  39. mFetchCount = htonl(mFetchCount);
  40. mLastFetched = htonl(mLastFetched);
  41. mLastModified = htonl(mLastModified);
  42. mExpirationTime = htonl(mExpirationTime);
  43. mDataSize = htonl(mDataSize);
  44. mKeySize = htonl(mKeySize);
  45. mMetaDataSize = htonl(mMetaDataSize);
  46. #endif
  47. }
  48. void Unswap() // network to host (disk to memory)
  49. {
  50. #if defined(IS_LITTLE_ENDIAN)
  51. mHeaderVersion = ntohl(mHeaderVersion);
  52. mMetaLocation = ntohl(mMetaLocation);
  53. mFetchCount = ntohl(mFetchCount);
  54. mLastFetched = ntohl(mLastFetched);
  55. mLastModified = ntohl(mLastModified);
  56. mExpirationTime = ntohl(mExpirationTime);
  57. mDataSize = ntohl(mDataSize);
  58. mKeySize = ntohl(mKeySize);
  59. mMetaDataSize = ntohl(mMetaDataSize);
  60. #endif
  61. }
  62. };
  63. /******************************************************************************
  64. * nsDiskCacheEntryInfo
  65. *****************************************************************************/
  66. class nsDiskCacheEntryInfo : public nsICacheEntryInfo {
  67. public:
  68. NS_DECL_ISUPPORTS
  69. NS_DECL_NSICACHEENTRYINFO
  70. nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry)
  71. : mDeviceID(deviceID)
  72. , mDiskEntry(diskEntry)
  73. {
  74. }
  75. const char* Key() { return mDiskEntry->Key(); }
  76. private:
  77. virtual ~nsDiskCacheEntryInfo() {}
  78. const char * mDeviceID;
  79. nsDiskCacheEntry * mDiskEntry;
  80. };
  81. #endif /* _nsDiskCacheEntry_h_ */