michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: #ifndef _nsDiskCache_h_ michael@0: #define _nsDiskCache_h_ michael@0: michael@0: #include "nsCacheEntry.h" michael@0: michael@0: #ifdef XP_WIN michael@0: #include // for htonl/ntohl michael@0: #endif michael@0: michael@0: michael@0: class nsDiskCache { michael@0: public: michael@0: enum { michael@0: kCurrentVersion = 0x00010013 // format = 16 bits major version/16 bits minor version michael@0: }; michael@0: michael@0: enum { kData, kMetaData }; michael@0: michael@0: // Stores the reason why the cache is corrupt. michael@0: // Note: I'm only listing the enum values explicitly for easy mapping when michael@0: // looking at telemetry data. michael@0: enum CorruptCacheInfo { michael@0: kNotCorrupt = 0, michael@0: kInvalidArgPointer = 1, michael@0: kUnexpectedError = 2, michael@0: kOpenCacheMapError = 3, michael@0: kBlockFilesShouldNotExist = 4, michael@0: kOutOfMemory = 5, michael@0: kCreateCacheSubdirectories = 6, michael@0: kBlockFilesShouldExist = 7, michael@0: kHeaderSizeNotRead = 8, michael@0: kHeaderIsDirty = 9, michael@0: kVersionMismatch = 10, michael@0: kRecordsIncomplete = 11, michael@0: kHeaderIncomplete = 12, michael@0: kNotEnoughToRead = 13, michael@0: kEntryCountIncorrect = 14, michael@0: kCouldNotGetBlockFileForIndex = 15, michael@0: kCouldNotCreateBlockFile = 16, michael@0: kBlockFileSizeError = 17, michael@0: kBlockFileBitMapWriteError = 18, michael@0: kBlockFileSizeLessThanBitMap = 19, michael@0: kBlockFileBitMapReadError = 20, michael@0: kBlockFileEstimatedSizeError = 21, michael@0: kFlushHeaderError = 22, michael@0: kCacheCleanFilePathError = 23, michael@0: kCacheCleanOpenFileError = 24, michael@0: kCacheCleanTimerError = 25 michael@0: }; michael@0: michael@0: // Parameter initval initializes internal state of hash function. Hash values are different michael@0: // for the same text when different initval is used. It can be any random number. michael@0: // michael@0: // It can be used for generating 64-bit hash value: michael@0: // (uint64_t(Hash(key, initval1)) << 32) | Hash(key, initval2) michael@0: // michael@0: // It can be also used to hash multiple strings: michael@0: // h = Hash(string1, 0); michael@0: // h = Hash(string2, h); michael@0: // ... michael@0: static PLDHashNumber Hash(const char* key, PLDHashNumber initval=0); michael@0: static nsresult Truncate(PRFileDesc * fd, uint32_t newEOF); michael@0: }; michael@0: michael@0: #endif // _nsDiskCache_h_