netwerk/cache/nsDiskCache.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cache/nsDiskCache.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     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 +
    1.11 +#ifndef _nsDiskCache_h_
    1.12 +#define _nsDiskCache_h_
    1.13 +
    1.14 +#include "nsCacheEntry.h"
    1.15 +
    1.16 +#ifdef XP_WIN
    1.17 +#include <winsock.h>  // for htonl/ntohl
    1.18 +#endif
    1.19 +
    1.20 +
    1.21 +class nsDiskCache {
    1.22 +public:
    1.23 +    enum {
    1.24 +            kCurrentVersion = 0x00010013      // format = 16 bits major version/16 bits minor version
    1.25 +    };
    1.26 +
    1.27 +    enum { kData, kMetaData };
    1.28 +
    1.29 +    // Stores the reason why the cache is corrupt.
    1.30 +    // Note: I'm only listing the enum values explicitly for easy mapping when
    1.31 +    // looking at telemetry data.
    1.32 +    enum CorruptCacheInfo {
    1.33 +      kNotCorrupt = 0,
    1.34 +      kInvalidArgPointer = 1,
    1.35 +      kUnexpectedError = 2,
    1.36 +      kOpenCacheMapError = 3,
    1.37 +      kBlockFilesShouldNotExist = 4,
    1.38 +      kOutOfMemory = 5,
    1.39 +      kCreateCacheSubdirectories = 6,
    1.40 +      kBlockFilesShouldExist = 7,
    1.41 +      kHeaderSizeNotRead = 8,
    1.42 +      kHeaderIsDirty = 9,
    1.43 +      kVersionMismatch = 10,
    1.44 +      kRecordsIncomplete = 11,
    1.45 +      kHeaderIncomplete = 12,
    1.46 +      kNotEnoughToRead = 13,
    1.47 +      kEntryCountIncorrect = 14,
    1.48 +      kCouldNotGetBlockFileForIndex = 15,
    1.49 +      kCouldNotCreateBlockFile = 16,
    1.50 +      kBlockFileSizeError = 17,
    1.51 +      kBlockFileBitMapWriteError = 18,
    1.52 +      kBlockFileSizeLessThanBitMap = 19,
    1.53 +      kBlockFileBitMapReadError = 20,
    1.54 +      kBlockFileEstimatedSizeError = 21,
    1.55 +      kFlushHeaderError = 22,
    1.56 +      kCacheCleanFilePathError = 23,
    1.57 +      kCacheCleanOpenFileError = 24,
    1.58 +      kCacheCleanTimerError = 25
    1.59 +    };
    1.60 +
    1.61 +    // Parameter initval initializes internal state of hash function. Hash values are different
    1.62 +    // for the same text when different initval is used. It can be any random number.
    1.63 +    // 
    1.64 +    // It can be used for generating 64-bit hash value:
    1.65 +    //   (uint64_t(Hash(key, initval1)) << 32) | Hash(key, initval2)
    1.66 +    //
    1.67 +    // It can be also used to hash multiple strings:
    1.68 +    //   h = Hash(string1, 0);
    1.69 +    //   h = Hash(string2, h);
    1.70 +    //   ... 
    1.71 +    static PLDHashNumber    Hash(const char* key, PLDHashNumber initval=0);
    1.72 +    static nsresult         Truncate(PRFileDesc *  fd, uint32_t  newEOF);
    1.73 +};
    1.74 +
    1.75 +#endif // _nsDiskCache_h_

mercurial