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