|
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/. */ |
|
6 |
|
7 |
|
8 #ifndef _nsDiskCache_h_ |
|
9 #define _nsDiskCache_h_ |
|
10 |
|
11 #include "nsCacheEntry.h" |
|
12 |
|
13 #ifdef XP_WIN |
|
14 #include <winsock.h> // for htonl/ntohl |
|
15 #endif |
|
16 |
|
17 |
|
18 class nsDiskCache { |
|
19 public: |
|
20 enum { |
|
21 kCurrentVersion = 0x00010013 // format = 16 bits major version/16 bits minor version |
|
22 }; |
|
23 |
|
24 enum { kData, kMetaData }; |
|
25 |
|
26 // Stores the reason why the cache is corrupt. |
|
27 // Note: I'm only listing the enum values explicitly for easy mapping when |
|
28 // looking at telemetry data. |
|
29 enum CorruptCacheInfo { |
|
30 kNotCorrupt = 0, |
|
31 kInvalidArgPointer = 1, |
|
32 kUnexpectedError = 2, |
|
33 kOpenCacheMapError = 3, |
|
34 kBlockFilesShouldNotExist = 4, |
|
35 kOutOfMemory = 5, |
|
36 kCreateCacheSubdirectories = 6, |
|
37 kBlockFilesShouldExist = 7, |
|
38 kHeaderSizeNotRead = 8, |
|
39 kHeaderIsDirty = 9, |
|
40 kVersionMismatch = 10, |
|
41 kRecordsIncomplete = 11, |
|
42 kHeaderIncomplete = 12, |
|
43 kNotEnoughToRead = 13, |
|
44 kEntryCountIncorrect = 14, |
|
45 kCouldNotGetBlockFileForIndex = 15, |
|
46 kCouldNotCreateBlockFile = 16, |
|
47 kBlockFileSizeError = 17, |
|
48 kBlockFileBitMapWriteError = 18, |
|
49 kBlockFileSizeLessThanBitMap = 19, |
|
50 kBlockFileBitMapReadError = 20, |
|
51 kBlockFileEstimatedSizeError = 21, |
|
52 kFlushHeaderError = 22, |
|
53 kCacheCleanFilePathError = 23, |
|
54 kCacheCleanOpenFileError = 24, |
|
55 kCacheCleanTimerError = 25 |
|
56 }; |
|
57 |
|
58 // Parameter initval initializes internal state of hash function. Hash values are different |
|
59 // for the same text when different initval is used. It can be any random number. |
|
60 // |
|
61 // It can be used for generating 64-bit hash value: |
|
62 // (uint64_t(Hash(key, initval1)) << 32) | Hash(key, initval2) |
|
63 // |
|
64 // It can be also used to hash multiple strings: |
|
65 // h = Hash(string1, 0); |
|
66 // h = Hash(string2, h); |
|
67 // ... |
|
68 static PLDHashNumber Hash(const char* key, PLDHashNumber initval=0); |
|
69 static nsresult Truncate(PRFileDesc * fd, uint32_t newEOF); |
|
70 }; |
|
71 |
|
72 #endif // _nsDiskCache_h_ |