Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | #ifndef _nsDiskCache_h_ |
michael@0 | 9 | #define _nsDiskCache_h_ |
michael@0 | 10 | |
michael@0 | 11 | #include "nsCacheEntry.h" |
michael@0 | 12 | |
michael@0 | 13 | #ifdef XP_WIN |
michael@0 | 14 | #include <winsock.h> // for htonl/ntohl |
michael@0 | 15 | #endif |
michael@0 | 16 | |
michael@0 | 17 | |
michael@0 | 18 | class nsDiskCache { |
michael@0 | 19 | public: |
michael@0 | 20 | enum { |
michael@0 | 21 | kCurrentVersion = 0x00010013 // format = 16 bits major version/16 bits minor version |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | enum { kData, kMetaData }; |
michael@0 | 25 | |
michael@0 | 26 | // Stores the reason why the cache is corrupt. |
michael@0 | 27 | // Note: I'm only listing the enum values explicitly for easy mapping when |
michael@0 | 28 | // looking at telemetry data. |
michael@0 | 29 | enum CorruptCacheInfo { |
michael@0 | 30 | kNotCorrupt = 0, |
michael@0 | 31 | kInvalidArgPointer = 1, |
michael@0 | 32 | kUnexpectedError = 2, |
michael@0 | 33 | kOpenCacheMapError = 3, |
michael@0 | 34 | kBlockFilesShouldNotExist = 4, |
michael@0 | 35 | kOutOfMemory = 5, |
michael@0 | 36 | kCreateCacheSubdirectories = 6, |
michael@0 | 37 | kBlockFilesShouldExist = 7, |
michael@0 | 38 | kHeaderSizeNotRead = 8, |
michael@0 | 39 | kHeaderIsDirty = 9, |
michael@0 | 40 | kVersionMismatch = 10, |
michael@0 | 41 | kRecordsIncomplete = 11, |
michael@0 | 42 | kHeaderIncomplete = 12, |
michael@0 | 43 | kNotEnoughToRead = 13, |
michael@0 | 44 | kEntryCountIncorrect = 14, |
michael@0 | 45 | kCouldNotGetBlockFileForIndex = 15, |
michael@0 | 46 | kCouldNotCreateBlockFile = 16, |
michael@0 | 47 | kBlockFileSizeError = 17, |
michael@0 | 48 | kBlockFileBitMapWriteError = 18, |
michael@0 | 49 | kBlockFileSizeLessThanBitMap = 19, |
michael@0 | 50 | kBlockFileBitMapReadError = 20, |
michael@0 | 51 | kBlockFileEstimatedSizeError = 21, |
michael@0 | 52 | kFlushHeaderError = 22, |
michael@0 | 53 | kCacheCleanFilePathError = 23, |
michael@0 | 54 | kCacheCleanOpenFileError = 24, |
michael@0 | 55 | kCacheCleanTimerError = 25 |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | // Parameter initval initializes internal state of hash function. Hash values are different |
michael@0 | 59 | // for the same text when different initval is used. It can be any random number. |
michael@0 | 60 | // |
michael@0 | 61 | // It can be used for generating 64-bit hash value: |
michael@0 | 62 | // (uint64_t(Hash(key, initval1)) << 32) | Hash(key, initval2) |
michael@0 | 63 | // |
michael@0 | 64 | // It can be also used to hash multiple strings: |
michael@0 | 65 | // h = Hash(string1, 0); |
michael@0 | 66 | // h = Hash(string2, h); |
michael@0 | 67 | // ... |
michael@0 | 68 | static PLDHashNumber Hash(const char* key, PLDHashNumber initval=0); |
michael@0 | 69 | static nsresult Truncate(PRFileDesc * fd, uint32_t newEOF); |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | #endif // _nsDiskCache_h_ |