summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/disk_cache/addr.cc2
-rw-r--r--net/disk_cache/addr.h4
-rw-r--r--net/disk_cache/backend_impl.cc3
-rw-r--r--net/disk_cache/backend_impl.h2
-rw-r--r--net/disk_cache/block_files.cc5
-rw-r--r--net/disk_cache/disk_format.cc6
-rw-r--r--net/disk_cache/disk_format.h121
-rw-r--r--net/disk_cache/disk_format_base.h170
-rw-r--r--net/disk_cache/entry_impl.cc3
-rw-r--r--net/disk_cache/entry_impl.h3
-rw-r--r--net/disk_cache/eviction.cc1
-rw-r--r--net/disk_cache/eviction.h2
-rw-r--r--net/disk_cache/file_lock.h8
-rw-r--r--net/disk_cache/mapped_file.h1
-rw-r--r--net/disk_cache/rankings.cc1
-rw-r--r--net/disk_cache/rankings.h3
-rw-r--r--net/disk_cache/storage_block.h9
-rw-r--r--net/disk_cache/storage_block_unittest.cc15
-rw-r--r--net/net.gyp1
-rw-r--r--net/tools/dump_cache/dump_files.cc4
20 files changed, 66 insertions, 298 deletions
diff --git a/net/disk_cache/addr.cc b/net/disk_cache/addr.cc
index ac924e9..baea0b4 100644
--- a/net/disk_cache/addr.cc
+++ b/net/disk_cache/addr.cc
@@ -40,7 +40,7 @@ bool Addr::SanityCheck() const {
return !(value_ & kReservedBitsMask);
}
-bool Addr::SanityCheckForEntry() const {
+bool Addr::SanityCheckForEntryV2() const {
if (!SanityCheck() || !is_initialized())
return false;
diff --git a/net/disk_cache/addr.h b/net/disk_cache/addr.h
index d467b8e..bd47368 100644
--- a/net/disk_cache/addr.h
+++ b/net/disk_cache/addr.h
@@ -9,7 +9,7 @@
#define NET_DISK_CACHE_ADDR_H_
#include "net/base/net_export.h"
-#include "net/disk_cache/disk_format.h"
+#include "net/disk_cache/disk_format_base.h"
namespace disk_cache {
@@ -134,7 +134,7 @@ class NET_EXPORT_PRIVATE Addr {
// Returns true if this address looks like a valid one.
bool SanityCheck() const;
- bool SanityCheckForEntry() const;
+ bool SanityCheckForEntryV2() const;
bool SanityCheckForRankings() const;
private:
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 2c80083..f555d59 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -22,6 +22,7 @@
#include "base/timer.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/cache_util.h"
+#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/entry_impl.h"
#include "net/disk_cache/errors.h"
#include "net/disk_cache/experiments.h"
@@ -1470,7 +1471,7 @@ int BackendImpl::NewEntry(Addr address, EntryImpl** entry) {
STRESS_DCHECK(block_files_.IsValid(address));
- if (!address.SanityCheckForEntry()) {
+ if (!address.SanityCheckForEntryV2()) {
LOG(WARNING) << "Wrong entry address.";
STRESS_NOTREACHED();
return ERR_INVALID_ADDRESS;
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 7d0b225..dcdf6e3 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -25,6 +25,8 @@ class NetLog;
namespace disk_cache {
+struct Index;
+
enum BackendFlags {
kNone = 0,
kMask = 1, // A mask (for the index table) was specified.
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc
index 97985ca..6f58c22 100644
--- a/net/disk_cache/block_files.cc
+++ b/net/disk_cache/block_files.cc
@@ -414,6 +414,9 @@ bool BlockFiles::CreateBlockFile(int index, FileType file_type, bool force) {
return false;
BlockFileHeader header;
+ memset(&header, 0, sizeof(header));
+ header.magic = kBlockMagic;
+ header.version = kBlockVersion2;
header.entry_size = Addr::BlockSizeForFileType(file_type);
header.this_file = static_cast<int16>(index);
DCHECK(index <= kint16max && index >= 0);
@@ -443,7 +446,7 @@ bool BlockFiles::OpenBlockFile(int index) {
}
BlockFileHeader* header = reinterpret_cast<BlockFileHeader*>(file->buffer());
- if (kBlockMagic != header->magic || kCurrentVersion != header->version) {
+ if (kBlockMagic != header->magic || kBlockVersion2 != header->version) {
LOG(ERROR) << "Invalid file version or magic " << name.value();
return false;
}
diff --git a/net/disk_cache/disk_format.cc b/net/disk_cache/disk_format.cc
index 5216b50..5b08954 100644
--- a/net/disk_cache/disk_format.cc
+++ b/net/disk_cache/disk_format.cc
@@ -12,10 +12,4 @@ IndexHeader::IndexHeader() {
version = kCurrentVersion;
}
-BlockFileHeader::BlockFileHeader() {
- memset(this, 0, sizeof(BlockFileHeader));
- magic = kBlockMagic;
- version = kCurrentVersion;
-}
-
} // namespace disk_cache
diff --git a/net/disk_cache/disk_format.h b/net/disk_cache/disk_format.h
index df6cabf..5d7597a 100644
--- a/net/disk_cache/disk_format.h
+++ b/net/disk_cache/disk_format.h
@@ -5,9 +5,9 @@
// The cache is stored on disk as a collection of block-files, plus an index
// file plus a collection of external files.
//
-// Any data blob bigger than kMaxBlockSize (net/addr.h) will be stored on a
-// separate file named f_xxx where x is a hexadecimal number. Shorter data will
-// be stored as a series of blocks on a block-file. In any case, CacheAddr
+// Any data blob bigger than kMaxBlockSize (disk_cache/addr.h) will be stored in
+// a separate file named f_xxx where x is a hexadecimal number. Shorter data
+// will be stored as a series of blocks on a block-file. In any case, CacheAddr
// represents the address of the data inside the cache.
//
// The index file is just a simple hash table that maps a particular entry to
@@ -15,18 +15,8 @@
// by the cache entry.
//
// The last element of the cache is the block-file. A block file is a file
-// designed to store blocks of data of a given size. It is able to store data
-// that spans from one to four consecutive "blocks", and it grows as needed to
-// store up to approximately 65000 blocks. It has a fixed size header used for
-// book keeping such as tracking free of blocks on the file. For example, a
-// block-file for 1KB blocks will grow from 8KB when totally empty to about 64MB
-// when completely full. At that point, data blocks of 1KB will be stored on a
-// second block file that will store the next set of 65000 blocks. The first
-// file contains the number of the second file, and the second file contains the
-// number of a third file, created when the second file reaches its limit. It is
-// important to remember that no matter how long the chain of files is, any
-// given block can be located directly by its address, which contains the file
-// number and starting block inside the file.
+// designed to store blocks of data of a given size. For more details see
+// disk_cache/disk_format_base.h
//
// A new cache is initialized with four block files (named data_0 through
// data_3), each one dedicated to store blocks of a given size. The number at
@@ -57,11 +47,10 @@
#include "base/basictypes.h"
#include "net/base/net_export.h"
+#include "net/disk_cache/disk_format_base.h"
namespace disk_cache {
-typedef uint32 CacheAddr;
-
const int kIndexTablesize = 0x10000;
const uint32 kIndexMagic = 0xC103CAC3;
const uint32 kCurrentVersion = 0x20000; // Version 2.0.
@@ -159,104 +148,6 @@ struct RankingsNode {
COMPILE_ASSERT(sizeof(RankingsNode) == 36, bad_RankingsNode);
-const uint32 kBlockMagic = 0xC104CAC3;
-const int kBlockHeaderSize = 8192; // Two pages: almost 64k entries
-const int kMaxBlocks = (kBlockHeaderSize - 80) * 8;
-
-// Bitmap to track used blocks on a block-file.
-typedef uint32 AllocBitmap[kMaxBlocks / 32];
-
-// A block-file is the file used to store information in blocks (could be
-// EntryStore blocks, RankingsNode blocks or user-data blocks).
-// We store entries that can expand for up to 4 consecutive blocks, and keep
-// counters of the number of blocks available for each type of entry. For
-// instance, an entry of 3 blocks is an entry of type 3. We also keep track of
-// where did we find the last entry of that type (to avoid searching the bitmap
-// from the beginning every time).
-// This Structure is the header of a block-file:
-struct NET_EXPORT_PRIVATE BlockFileHeader {
- BlockFileHeader();
-
- uint32 magic;
- uint32 version;
- int16 this_file; // Index of this file.
- int16 next_file; // Next file when this one is full.
- int32 entry_size; // Size of the blocks of this file.
- int32 num_entries; // Number of stored entries.
- int32 max_entries; // Current maximum number of entries.
- int32 empty[4]; // Counters of empty entries for each type.
- int32 hints[4]; // Last used position for each entry type.
- volatile int32 updating; // Keep track of updates to the header.
- int32 user[5];
- AllocBitmap allocation_map;
-};
-
-COMPILE_ASSERT(sizeof(BlockFileHeader) == kBlockHeaderSize, bad_header);
-
-// Sparse data support:
-// We keep a two level hierarchy to enable sparse data for an entry: the first
-// level consists of using separate "child" entries to store ranges of 1 MB,
-// and the second level stores blocks of 1 KB inside each child entry.
-//
-// Whenever we need to access a particular sparse offset, we first locate the
-// child entry that stores that offset, so we discard the 20 least significant
-// bits of the offset, and end up with the child id. For instance, the child id
-// to store the first megabyte is 0, and the child that should store offset
-// 0x410000 has an id of 4.
-//
-// The child entry is stored the same way as any other entry, so it also has a
-// name (key). The key includes a signature to be able to identify children
-// created for different generations of the same resource. In other words, given
-// that a given sparse entry can have a large number of child entries, and the
-// resource can be invalidated and replaced with a new version at any time, it
-// is important to be sure that a given child actually belongs to certain entry.
-//
-// The full name of a child entry is composed with a prefix ("Range_"), and two
-// hexadecimal 64-bit numbers at the end, separated by semicolons. The first
-// number is the signature of the parent key, and the second number is the child
-// id as described previously. The signature itself is also stored internally by
-// the child and the parent entries. For example, a sparse entry with a key of
-// "sparse entry name", and a signature of 0x052AF76, may have a child entry
-// named "Range_sparse entry name:052af76:4", which stores data in the range
-// 0x400000 to 0x4FFFFF.
-//
-// Each child entry keeps track of all the 1 KB blocks that have been written
-// to the entry, but being a regular entry, it will happily return zeros for any
-// read that spans data not written before. The actual sparse data is stored in
-// one of the data streams of the child entry (at index 1), while the control
-// information is stored in another stream (at index 2), both by parents and
-// the children.
-
-// This structure contains the control information for parent and child entries.
-// It is stored at offset 0 of the data stream with index 2.
-// It is possible to write to a child entry in a way that causes the last block
-// to be only partialy filled. In that case, last_block and last_block_len will
-// keep track of that block.
-struct SparseHeader {
- int64 signature; // The parent and children signature.
- uint32 magic; // Structure identifier (equal to kIndexMagic).
- int32 parent_key_len; // Key length for the parent entry.
- int32 last_block; // Index of the last written block.
- int32 last_block_len; // Lenght of the last written block.
- int32 dummy[10];
-};
-
-// The SparseHeader will be followed by a bitmap, as described by this
-// structure.
-struct SparseData {
- SparseHeader header;
- uint32 bitmap[32]; // Bitmap representation of known children (if this
- // is a parent entry), or used blocks (for child
- // entries. The size is fixed for child entries but
- // not for parents; it can be as small as 4 bytes
- // and as large as 8 KB.
-};
-
-// The number of blocks stored by a child entry.
-const int kNumSparseBits = 1024;
-COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8,
- Invalid_SparseData_bitmap);
-
} // namespace disk_cache
#endif // NET_DISK_CACHE_DISK_FORMAT_H_
diff --git a/net/disk_cache/disk_format_base.h b/net/disk_cache/disk_format_base.h
index df6cabf..c8b7490 100644
--- a/net/disk_cache/disk_format_base.h
+++ b/net/disk_cache/disk_format_base.h
@@ -2,58 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// The cache is stored on disk as a collection of block-files, plus an index
-// file plus a collection of external files.
+// For a general description of the files used by the cache see file_format.h.
//
-// Any data blob bigger than kMaxBlockSize (net/addr.h) will be stored on a
-// separate file named f_xxx where x is a hexadecimal number. Shorter data will
-// be stored as a series of blocks on a block-file. In any case, CacheAddr
-// represents the address of the data inside the cache.
-//
-// The index file is just a simple hash table that maps a particular entry to
-// a CacheAddr value. Linking for a given hash bucket is handled internally
-// by the cache entry.
-//
-// The last element of the cache is the block-file. A block file is a file
-// designed to store blocks of data of a given size. It is able to store data
-// that spans from one to four consecutive "blocks", and it grows as needed to
-// store up to approximately 65000 blocks. It has a fixed size header used for
-// book keeping such as tracking free of blocks on the file. For example, a
-// block-file for 1KB blocks will grow from 8KB when totally empty to about 64MB
-// when completely full. At that point, data blocks of 1KB will be stored on a
-// second block file that will store the next set of 65000 blocks. The first
-// file contains the number of the second file, and the second file contains the
-// number of a third file, created when the second file reaches its limit. It is
-// important to remember that no matter how long the chain of files is, any
-// given block can be located directly by its address, which contains the file
-// number and starting block inside the file.
-//
-// A new cache is initialized with four block files (named data_0 through
-// data_3), each one dedicated to store blocks of a given size. The number at
-// the end of the file name is the block file number (in decimal).
-//
-// There are two "special" types of blocks: an entry and a rankings node. An
-// entry keeps track of all the information related to the same cache entry,
-// such as the key, hash value, data pointers etc. A rankings node keeps track
-// of the information that is updated frequently for a given entry, such as its
-// location on the LRU lists, last access time etc.
-//
-// The files that store internal information for the cache (blocks and index)
-// are at least partially memory mapped. They have a location that is signaled
-// every time the internal structures are modified, so it is possible to detect
-// (most of the time) when the process dies in the middle of an update.
-//
-// In order to prevent dirty data to be used as valid (after a crash), every
-// cache entry has a dirty identifier. Each running instance of the cache keeps
-// a separate identifier (maintained on the "this_id" header field) that is used
-// to mark every entry that is created or modified. When the entry is closed,
-// and all the data can be trusted, the dirty flag is cleared from the entry.
-// When the cache encounters an entry whose identifier is different than the one
-// being currently used, it means that the entry was not properly closed on a
-// previous run, so it is discarded.
-
-#ifndef NET_DISK_CACHE_DISK_FORMAT_H_
-#define NET_DISK_CACHE_DISK_FORMAT_H_
+// A block file is a file designed to store blocks of data of a given size. It
+// is able to store data that spans from one to four consecutive "blocks", and
+// it grows as needed to store up to approximately 65000 blocks. It has a fixed
+// size header used for book keeping such as tracking free of blocks on the
+// file. For example, a block-file for 1KB blocks will grow from 8KB when
+// totally empty to about 64MB when completely full. At that point, data blocks
+// of 1KB will be stored on a second block file that will store the next set of
+// 65000 blocks. The first file contains the number of the second file, and the
+// second file contains the number of a third file, created when the second file
+// reaches its limit. It is important to remember that no matter how long the
+// chain of files is, any given block can be located directly by its address,
+// which contains the file number and starting block inside the file.
+
+#ifndef NET_DISK_CACHE_DISK_FORMAT_BASE_H_
+#define NET_DISK_CACHE_DISK_FORMAT_BASE_H_
#include "base/basictypes.h"
#include "net/base/net_export.h"
@@ -62,102 +27,7 @@ namespace disk_cache {
typedef uint32 CacheAddr;
-const int kIndexTablesize = 0x10000;
-const uint32 kIndexMagic = 0xC103CAC3;
-const uint32 kCurrentVersion = 0x20000; // Version 2.0.
-
-struct LruData {
- int32 pad1[2];
- int32 filled; // Flag to tell when we filled the cache.
- int32 sizes[5];
- CacheAddr heads[5];
- CacheAddr tails[5];
- CacheAddr transaction; // In-flight operation target.
- int32 operation; // Actual in-flight operation.
- int32 operation_list; // In-flight operation list.
- int32 pad2[7];
-};
-
-// Header for the master index file.
-struct NET_EXPORT_PRIVATE IndexHeader {
- IndexHeader();
-
- uint32 magic;
- uint32 version;
- int32 num_entries; // Number of entries currently stored.
- int32 num_bytes; // Total size of the stored data.
- int32 last_file; // Last external file created.
- int32 this_id; // Id for all entries being changed (dirty flag).
- CacheAddr stats; // Storage for usage data.
- int32 table_len; // Actual size of the table (0 == kIndexTablesize).
- int32 crash; // Signals a previous crash.
- int32 experiment; // Id of an ongoing test.
- uint64 create_time; // Creation time for this set of files.
- int32 pad[52];
- LruData lru; // Eviction control data.
-};
-
-// The structure of the whole index file.
-struct Index {
- IndexHeader header;
- CacheAddr table[kIndexTablesize]; // Default size. Actual size controlled
- // by header.table_len.
-};
-
-// Main structure for an entry on the backing storage. If the key is longer than
-// what can be stored on this structure, it will be extended on consecutive
-// blocks (adding 256 bytes each time), up to 4 blocks (1024 - 32 - 1 chars).
-// After that point, the whole key will be stored as a data block or external
-// file.
-struct EntryStore {
- uint32 hash; // Full hash of the key.
- CacheAddr next; // Next entry with the same hash or bucket.
- CacheAddr rankings_node; // Rankings node for this entry.
- int32 reuse_count; // How often is this entry used.
- int32 refetch_count; // How often is this fetched from the net.
- int32 state; // Current state.
- uint64 creation_time;
- int32 key_len;
- CacheAddr long_key; // Optional address of a long key.
- int32 data_size[4]; // We can store up to 4 data streams for each
- CacheAddr data_addr[4]; // entry.
- uint32 flags; // Any combination of EntryFlags.
- int32 pad[4];
- uint32 self_hash; // The hash of EntryStore up to this point.
- char key[256 - 24 * 4]; // null terminated
-};
-
-COMPILE_ASSERT(sizeof(EntryStore) == 256, bad_EntyStore);
-const int kMaxInternalKeyLength = 4 * sizeof(EntryStore) -
- offsetof(EntryStore, key) - 1;
-
-// Possible states for a given entry.
-enum EntryState {
- ENTRY_NORMAL = 0,
- ENTRY_EVICTED, // The entry was recently evicted from the cache.
- ENTRY_DOOMED // The entry was doomed.
-};
-
-// Flags that can be applied to an entry.
-enum EntryFlags {
- PARENT_ENTRY = 1, // This entry has children (sparse) entries.
- CHILD_ENTRY = 1 << 1 // Child entry that stores sparse data.
-};
-
-#pragma pack(push, 4)
-// Rankings information for a given entry.
-struct RankingsNode {
- uint64 last_used; // LRU info.
- uint64 last_modified; // LRU info.
- CacheAddr next; // LRU list.
- CacheAddr prev; // LRU list.
- CacheAddr contents; // Address of the EntryStore.
- int32 dirty; // The entry is being modifyied.
- uint32 self_hash; // RankingsNode's hash.
-};
-#pragma pack(pop)
-
-COMPILE_ASSERT(sizeof(RankingsNode) == 36, bad_RankingsNode);
+const uint32 kBlockVersion2 = 0x20000; // Version 2.0.
const uint32 kBlockMagic = 0xC104CAC3;
const int kBlockHeaderSize = 8192; // Two pages: almost 64k entries
@@ -174,9 +44,7 @@ typedef uint32 AllocBitmap[kMaxBlocks / 32];
// where did we find the last entry of that type (to avoid searching the bitmap
// from the beginning every time).
// This Structure is the header of a block-file:
-struct NET_EXPORT_PRIVATE BlockFileHeader {
- BlockFileHeader();
-
+struct BlockFileHeader {
uint32 magic;
uint32 version;
int16 this_file; // Index of this file.
@@ -259,4 +127,4 @@ COMPILE_ASSERT(sizeof(SparseData) == sizeof(SparseHeader) + kNumSparseBits / 8,
} // namespace disk_cache
-#endif // NET_DISK_CACHE_DISK_FORMAT_H_
+#endif // NET_DISK_CACHE_DISK_FORMAT_BASE_H_
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index 205a2ddb..3ce746d 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -13,6 +13,7 @@
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/bitmap.h"
#include "net/disk_cache/cache_util.h"
+#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/histogram_macros.h"
#include "net/disk_cache/net_log_parameters.h"
#include "net/disk_cache/sparse_control.h"
@@ -581,7 +582,7 @@ bool EntryImpl::SanityCheck() {
return false;
Addr next_addr(stored->next);
- if (next_addr.is_initialized() && !next_addr.SanityCheckForEntry()) {
+ if (next_addr.is_initialized() && !next_addr.SanityCheckForEntryV2()) {
STRESS_NOTREACHED();
return false;
}
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index 92217dc..13d077c 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "net/base/net_log.h"
#include "net/disk_cache/disk_cache.h"
+#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/storage_block.h"
#include "net/disk_cache/storage_block-inl.h"
@@ -16,6 +17,8 @@ namespace disk_cache {
class BackendImpl;
class InFlightBackendIO;
class SparseControl;
+typedef StorageBlock<EntryStore> CacheEntryBlock;
+typedef StorageBlock<RankingsNode> CacheRankingsBlock;
// This class implements the Entry interface. An object of this
// class represents a single entry on the cache.
diff --git a/net/disk_cache/eviction.cc b/net/disk_cache/eviction.cc
index 4906dfe..9ebb320 100644
--- a/net/disk_cache/eviction.cc
+++ b/net/disk_cache/eviction.cc
@@ -35,6 +35,7 @@
#include "base/string_util.h"
#include "base/time.h"
#include "net/disk_cache/backend_impl.h"
+#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/entry_impl.h"
#include "net/disk_cache/experiments.h"
#include "net/disk_cache/histogram_macros.h"
diff --git a/net/disk_cache/eviction.h b/net/disk_cache/eviction.h
index 060db43..f6224a9 100644
--- a/net/disk_cache/eviction.h
+++ b/net/disk_cache/eviction.h
@@ -7,13 +7,13 @@
#include "base/basictypes.h"
#include "base/memory/weak_ptr.h"
-#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/rankings.h"
namespace disk_cache {
class BackendImpl;
class EntryImpl;
+struct IndexHeader;
// This class implements the eviction algorithm for the cache and it is tightly
// integrated with BackendImpl.
diff --git a/net/disk_cache/file_lock.h b/net/disk_cache/file_lock.h
index a51067e..7fcf75d 100644
--- a/net/disk_cache/file_lock.h
+++ b/net/disk_cache/file_lock.h
@@ -4,11 +4,11 @@
// See net/disk_cache/disk_cache.h for the public interface of the cache.
-#ifndef NET_DISK_CACHE_FILE_LOCK_H__
-#define NET_DISK_CACHE_FILE_LOCK_H__
+#ifndef NET_DISK_CACHE_FILE_LOCK_H_
+#define NET_DISK_CACHE_FILE_LOCK_H_
#include "net/base/net_export.h"
-#include "net/disk_cache/disk_format.h"
+#include "net/disk_cache/disk_format_base.h"
namespace disk_cache {
@@ -42,4 +42,4 @@ class NET_EXPORT_PRIVATE FileLock {
} // namespace disk_cache
-#endif // NET_DISK_CACHE_FILE_LOCK_H__
+#endif // NET_DISK_CACHE_FILE_LOCK_H_
diff --git a/net/disk_cache/mapped_file.h b/net/disk_cache/mapped_file.h
index 6190997..4649b90 100644
--- a/net/disk_cache/mapped_file.h
+++ b/net/disk_cache/mapped_file.h
@@ -8,7 +8,6 @@
#define NET_DISK_CACHE_MAPPED_FILE_H_
#include "net/base/net_export.h"
-#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/file.h"
#include "net/disk_cache/file_block.h"
diff --git a/net/disk_cache/rankings.cc b/net/disk_cache/rankings.cc
index e14ee02..072d8d5 100644
--- a/net/disk_cache/rankings.cc
+++ b/net/disk_cache/rankings.cc
@@ -6,6 +6,7 @@
#include "base/metrics/histogram.h"
#include "net/disk_cache/backend_impl.h"
+#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/entry_impl.h"
#include "net/disk_cache/errors.h"
#include "net/disk_cache/histogram_macros.h"
diff --git a/net/disk_cache/rankings.h b/net/disk_cache/rankings.h
index eaa6c2f..cd94eaf 100644
--- a/net/disk_cache/rankings.h
+++ b/net/disk_cache/rankings.h
@@ -17,6 +17,9 @@
namespace disk_cache {
class BackendImpl;
+struct LruData;
+struct RankingsNode;
+typedef StorageBlock<RankingsNode> CacheRankingsBlock;
// Type of crashes generated for the unit tests.
enum RankCrashes {
diff --git a/net/disk_cache/storage_block.h b/net/disk_cache/storage_block.h
index c967c2d..65c67fc 100644
--- a/net/disk_cache/storage_block.h
+++ b/net/disk_cache/storage_block.h
@@ -4,8 +4,8 @@
// See net/disk_cache/disk_cache.h for the public interface.
-#ifndef NET_DISK_CACHE_STORAGE_BLOCK_H__
-#define NET_DISK_CACHE_STORAGE_BLOCK_H__
+#ifndef NET_DISK_CACHE_STORAGE_BLOCK_H_
+#define NET_DISK_CACHE_STORAGE_BLOCK_H_
#include "net/disk_cache/addr.h"
#include "net/disk_cache/mapped_file.h"
@@ -90,9 +90,6 @@ class StorageBlock : public FileBlock {
DISALLOW_COPY_AND_ASSIGN(StorageBlock);
};
-typedef StorageBlock<EntryStore> CacheEntryBlock;
-typedef StorageBlock<RankingsNode> CacheRankingsBlock;
-
} // namespace disk_cache
-#endif // NET_DISK_CACHE_STORAGE_BLOCK_H__
+#endif // NET_DISK_CACHE_STORAGE_BLOCK_H_
diff --git a/net/disk_cache/storage_block_unittest.cc b/net/disk_cache/storage_block_unittest.cc
index 6ad8189..f91b2b9 100644
--- a/net/disk_cache/storage_block_unittest.cc
+++ b/net/disk_cache/storage_block_unittest.cc
@@ -3,19 +3,22 @@
// found in the LICENSE file.
#include "base/files/file_path.h"
+#include "net/disk_cache/disk_format.h"
#include "net/disk_cache/storage_block.h"
#include "net/disk_cache/storage_block-inl.h"
#include "net/disk_cache/disk_cache_test_base.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+typedef disk_cache::StorageBlock<disk_cache::EntryStore> CacheEntryBlock;
+
TEST_F(DiskCacheTest, StorageBlock_LoadStore) {
base::FilePath filename = cache_path_.AppendASCII("a_test");
scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
- disk_cache::CacheEntryBlock entry1(file.get(), disk_cache::Addr(0xa0010001));
+ CacheEntryBlock entry1(file.get(), disk_cache::Addr(0xa0010001));
memset(entry1.Data(), 0, sizeof(disk_cache::EntryStore));
entry1.Data()->hash = 0xaa5555aa;
entry1.Data()->rankings_node = 0xa0010002;
@@ -35,10 +38,10 @@ TEST_F(DiskCacheTest, StorageBlock_SetData) {
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
- disk_cache::CacheEntryBlock entry1(file.get(), disk_cache::Addr(0xa0010001));
+ CacheEntryBlock entry1(file.get(), disk_cache::Addr(0xa0010001));
entry1.Data()->hash = 0xaa5555aa;
- disk_cache::CacheEntryBlock entry2(file.get(), disk_cache::Addr(0xa0010002));
+ CacheEntryBlock entry2(file.get(), disk_cache::Addr(0xa0010002));
EXPECT_TRUE(entry2.Load());
EXPECT_TRUE(entry2.Data() != NULL);
EXPECT_TRUE(0 == entry2.Data()->hash);
@@ -55,15 +58,15 @@ TEST_F(DiskCacheTest, StorageBlock_SetModified) {
ASSERT_TRUE(CreateCacheTestFile(filename));
ASSERT_TRUE(file->Init(filename, 8192));
- disk_cache::CacheEntryBlock* entry1 =
- new disk_cache::CacheEntryBlock(file.get(), disk_cache::Addr(0xa0010003));
+ CacheEntryBlock* entry1 =
+ new CacheEntryBlock(file.get(), disk_cache::Addr(0xa0010003));
EXPECT_TRUE(entry1->Load());
EXPECT_TRUE(0 == entry1->Data()->hash);
entry1->Data()->hash = 0x45687912;
entry1->set_modified();
delete entry1;
- disk_cache::CacheEntryBlock entry2(file.get(), disk_cache::Addr(0xa0010003));
+ CacheEntryBlock entry2(file.get(), disk_cache::Addr(0xa0010003));
EXPECT_TRUE(entry2.Load());
EXPECT_TRUE(0x45687912 == entry2.Data()->hash);
}
diff --git a/net/net.gyp b/net/net.gyp
index 0265d31..a779c56 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -336,6 +336,7 @@
'disk_cache/disk_cache.h',
'disk_cache/disk_format.cc',
'disk_cache/disk_format.h',
+ 'disk_cache/disk_format_base.h',
'disk_cache/entry_impl.cc',
'disk_cache/entry_impl.h',
'disk_cache/errors.h',
diff --git a/net/tools/dump_cache/dump_files.cc b/net/tools/dump_cache/dump_files.cc
index f495115..ffef1c8 100644
--- a/net/tools/dump_cache/dump_files.cc
+++ b/net/tools/dump_cache/dump_files.cc
@@ -237,7 +237,7 @@ bool CacheDumper::LoadEntry(disk_cache::CacheAddr addr,
if (!file)
return false;
- disk_cache::CacheEntryBlock entry_block(file, address);
+ disk_cache::StorageBlock<disk_cache::EntryStore> entry_block(file, address);
if (!entry_block.Load())
return false;
@@ -262,7 +262,7 @@ bool CacheDumper::LoadRankings(disk_cache::CacheAddr addr,
if (!file)
return false;
- disk_cache::CacheRankingsBlock rank_block(file, address);
+ disk_cache::StorageBlock<disk_cache::RankingsNode> rank_block(file, address);
if (!rank_block.Load())
return false;