1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/cache/nsDiskCacheEntry.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef _nsDiskCacheEntry_h_ 1.11 +#define _nsDiskCacheEntry_h_ 1.12 + 1.13 +#include "nsDiskCacheMap.h" 1.14 + 1.15 +#include "nsCacheEntry.h" 1.16 + 1.17 + 1.18 +/****************************************************************************** 1.19 + * nsDiskCacheEntry 1.20 + *****************************************************************************/ 1.21 +struct nsDiskCacheEntry { 1.22 + uint32_t mHeaderVersion; // useful for stand-alone metadata files 1.23 + uint32_t mMetaLocation; // for verification 1.24 + int32_t mFetchCount; 1.25 + uint32_t mLastFetched; 1.26 + uint32_t mLastModified; 1.27 + uint32_t mExpirationTime; 1.28 + uint32_t mDataSize; 1.29 + uint32_t mKeySize; // includes terminating null byte 1.30 + uint32_t mMetaDataSize; // includes terminating null byte 1.31 + // followed by key data (mKeySize bytes) 1.32 + // followed by meta data (mMetaDataSize bytes) 1.33 + 1.34 + uint32_t Size() { return sizeof(nsDiskCacheEntry) + 1.35 + mKeySize + mMetaDataSize; 1.36 + } 1.37 + 1.38 + char* Key() { return reinterpret_cast<char*const>(this) + 1.39 + sizeof(nsDiskCacheEntry); 1.40 + } 1.41 + 1.42 + char* MetaData() 1.43 + { return Key() + mKeySize; } 1.44 + 1.45 + nsCacheEntry * CreateCacheEntry(nsCacheDevice * device); 1.46 + 1.47 + void Swap() // host to network (memory to disk) 1.48 + { 1.49 +#if defined(IS_LITTLE_ENDIAN) 1.50 + mHeaderVersion = htonl(mHeaderVersion); 1.51 + mMetaLocation = htonl(mMetaLocation); 1.52 + mFetchCount = htonl(mFetchCount); 1.53 + mLastFetched = htonl(mLastFetched); 1.54 + mLastModified = htonl(mLastModified); 1.55 + mExpirationTime = htonl(mExpirationTime); 1.56 + mDataSize = htonl(mDataSize); 1.57 + mKeySize = htonl(mKeySize); 1.58 + mMetaDataSize = htonl(mMetaDataSize); 1.59 +#endif 1.60 + } 1.61 + 1.62 + void Unswap() // network to host (disk to memory) 1.63 + { 1.64 +#if defined(IS_LITTLE_ENDIAN) 1.65 + mHeaderVersion = ntohl(mHeaderVersion); 1.66 + mMetaLocation = ntohl(mMetaLocation); 1.67 + mFetchCount = ntohl(mFetchCount); 1.68 + mLastFetched = ntohl(mLastFetched); 1.69 + mLastModified = ntohl(mLastModified); 1.70 + mExpirationTime = ntohl(mExpirationTime); 1.71 + mDataSize = ntohl(mDataSize); 1.72 + mKeySize = ntohl(mKeySize); 1.73 + mMetaDataSize = ntohl(mMetaDataSize); 1.74 +#endif 1.75 + } 1.76 +}; 1.77 + 1.78 + 1.79 +/****************************************************************************** 1.80 + * nsDiskCacheEntryInfo 1.81 + *****************************************************************************/ 1.82 +class nsDiskCacheEntryInfo : public nsICacheEntryInfo { 1.83 +public: 1.84 + NS_DECL_ISUPPORTS 1.85 + NS_DECL_NSICACHEENTRYINFO 1.86 + 1.87 + nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry) 1.88 + : mDeviceID(deviceID) 1.89 + , mDiskEntry(diskEntry) 1.90 + { 1.91 + } 1.92 + 1.93 + virtual ~nsDiskCacheEntryInfo() {} 1.94 + 1.95 + const char* Key() { return mDiskEntry->Key(); } 1.96 + 1.97 +private: 1.98 + const char * mDeviceID; 1.99 + nsDiskCacheEntry * mDiskEntry; 1.100 +}; 1.101 + 1.102 + 1.103 +#endif /* _nsDiskCacheEntry_h_ */