netwerk/cache/nsDiskCacheEntry.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial