Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: net/disk_cache/addr.h

Issue 16837003: Disk cache: Update Addr to handle file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/addr.cc » ('j') | net/disk_cache/addr.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This is an internal class that handles the address of a cache record. 5 // This is an internal class that handles the address of a cache record.
6 // See net/disk_cache/disk_cache.h for the public interface of the cache. 6 // See net/disk_cache/disk_cache.h for the public interface of the cache.
7 7
8 #ifndef NET_DISK_CACHE_ADDR_H_ 8 #ifndef NET_DISK_CACHE_ADDR_H_
9 #define NET_DISK_CACHE_ADDR_H_ 9 #define NET_DISK_CACHE_ADDR_H_
10 10
11 #include "net/base/net_export.h" 11 #include "net/base/net_export.h"
12 #include "net/disk_cache/disk_format_base.h" 12 #include "net/disk_cache/disk_format_base.h"
13 13
14 namespace disk_cache { 14 namespace disk_cache {
15 15
16 enum FileType { 16 enum FileType {
17 EXTERNAL = 0, 17 EXTERNAL = 0,
18 RANKINGS = 1, 18 RANKINGS = 1,
19 BLOCK_256, 19 BLOCK_256 = 2,
20 BLOCK_1K, 20 BLOCK_1K = 3,
21 BLOCK_4K, 21 BLOCK_4K = 4,
22 BLOCK_FILES = 5,
23 BLOCK_ENTRIES = 6,
24 BLOCK_EVICTED = 7
22 }; 25 };
23 26
24 const int kMaxBlockSize = 4096 * 4; 27 const int kMaxBlockSize = 4096 * 4;
25 const int kMaxBlockFile = 255; 28 const int kMaxBlockFile = 255;
26 const int kMaxNumBlocks = 4; 29 const int kMaxNumBlocks = 4;
27 const int kFirstAdditionalBlockFile = 4; 30 const int kFirstAdditionalBlockFile = 4;
31 const int kFirstAdditionalBlockFileV3 = 7;
28 32
29 // Defines a storage address for a cache record 33 // Defines a storage address for a cache record
30 // 34 //
31 // Header: 35 // Header:
32 // 1000 0000 0000 0000 0000 0000 0000 0000 : initialized bit 36 // 1000 0000 0000 0000 0000 0000 0000 0000 : initialized bit
33 // 0111 0000 0000 0000 0000 0000 0000 0000 : file type 37 // 0111 0000 0000 0000 0000 0000 0000 0000 : file type
34 // 38 //
35 // File type values: 39 // File type values:
36 // 0 = separate file on disk 40 // 0 = separate file on disk
37 // 1 = rankings block file 41 // 1 = rankings block file
38 // 2 = 256 byte block file 42 // 2 = 256 byte block file
39 // 3 = 1k byte block file 43 // 3 = 1k byte block file
40 // 4 = 4k byte block file 44 // 4 = 4k byte block file
45 // 5 = external files block file
46 // 6 = active entries block file
47 // 7 = evicted entries block file
41 // 48 //
42 // If separate file: 49 // If separate file:
43 // 0000 1111 1111 1111 1111 1111 1111 1111 : file# 0 - 268,435,456 (2^28) 50 // 0000 1111 1111 1111 1111 1111 1111 1111 : file# 0 - 268,435,456 (2^28)
44 // 51 //
45 // If block file: 52 // If block file:
46 // 0000 1100 0000 0000 0000 0000 0000 0000 : reserved bits 53 // 0000 1100 0000 0000 0000 0000 0000 0000 : reserved bits
47 // 0000 0011 0000 0000 0000 0000 0000 0000 : number of contiguous blocks 1-4 54 // 0000 0011 0000 0000 0000 0000 0000 0000 : number of contiguous blocks 1-4
48 // 0000 0000 1111 1111 0000 0000 0000 0000 : file selector 0 - 255 55 // 0000 0000 1111 1111 0000 0000 0000 0000 : file selector 0 - 255
49 // 0000 0000 0000 0000 1111 1111 1111 1111 : block# 0 - 65,535 (2^16) 56 // 0000 0000 0000 0000 1111 1111 1111 1111 : block# 0 - 65,535 (2^16)
50 class NET_EXPORT_PRIVATE Addr { 57 class NET_EXPORT_PRIVATE Addr {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 101 }
95 102
96 bool operator==(Addr other) const { 103 bool operator==(Addr other) const {
97 return value_ == other.value_; 104 return value_ == other.value_;
98 } 105 }
99 106
100 bool operator!=(Addr other) const { 107 bool operator!=(Addr other) const {
101 return value_ != other.value_; 108 return value_ != other.value_;
102 } 109 }
103 110
111 static Addr FromEntryAddress(uint32 value) {
112 return Addr(kInitializedMask + (BLOCK_ENTRIES << kFileTypeOffset) + value);
113 }
114
115 static Addr FromEvictedAddress(uint32 value) {
116 return Addr(kInitializedMask + (BLOCK_EVICTED << kFileTypeOffset) + value);
117 }
118
104 static int BlockSizeForFileType(FileType file_type) { 119 static int BlockSizeForFileType(FileType file_type) {
105 switch (file_type) { 120 switch (file_type) {
106 case RANKINGS: 121 case RANKINGS:
107 return 36; 122 return 36;
108 case BLOCK_256: 123 case BLOCK_256:
109 return 256; 124 return 256;
110 case BLOCK_1K: 125 case BLOCK_1K:
111 return 1024; 126 return 1024;
112 case BLOCK_4K: 127 case BLOCK_4K:
113 return 4096; 128 return 4096;
129 case BLOCK_FILES:
130 return 8;
131 case BLOCK_ENTRIES:
132 return 104;
133 case BLOCK_EVICTED:
134 return 48;
114 default: 135 default:
115 return 0; 136 return 0;
116 } 137 }
117 } 138 }
118 139
119 static FileType RequiredFileType(int size) { 140 static FileType RequiredFileType(int size) {
120 if (size < 1024) 141 if (size < 1024)
121 return BLOCK_256; 142 return BLOCK_256;
122 else if (size < 4096) 143 else if (size < 4096)
123 return BLOCK_1K; 144 return BLOCK_1K;
124 else if (size <= 4096 * 4) 145 else if (size <= 4096 * 4)
125 return BLOCK_4K; 146 return BLOCK_4K;
126 else 147 else
127 return EXTERNAL; 148 return EXTERNAL;
128 } 149 }
129 150
130 static int RequiredBlocks(int size, FileType file_type) { 151 static int RequiredBlocks(int size, FileType file_type) {
131 int block_size = BlockSizeForFileType(file_type); 152 int block_size = BlockSizeForFileType(file_type);
132 return (size + block_size - 1) / block_size; 153 return (size + block_size - 1) / block_size;
133 } 154 }
134 155
135 // Returns true if this address looks like a valid one. 156 // Returns true if this address looks like a valid one.
136 bool SanityCheck() const; 157 bool SanityCheckV2() const;
158 bool SanityCheckV3() const;
137 bool SanityCheckForEntryV2() const; 159 bool SanityCheckForEntryV2() const;
160 bool SanityCheckForEntryV3() const;
138 bool SanityCheckForRankings() const; 161 bool SanityCheckForRankings() const;
139 162
140 private: 163 private:
141 static const uint32 kInitializedMask = 0x80000000; 164 static const uint32 kInitializedMask = 0x80000000;
142 static const uint32 kFileTypeMask = 0x70000000; 165 static const uint32 kFileTypeMask = 0x70000000;
143 static const uint32 kFileTypeOffset = 28; 166 static const uint32 kFileTypeOffset = 28;
144 static const uint32 kNumBlocksMask = 0x03000000; 167 static const uint32 kNumBlocksMask = 0x03000000;
145 static const uint32 kNumBlocksOffset = 24; 168 static const uint32 kNumBlocksOffset = 24;
146 static const uint32 kFileSelectorMask = 0x00ff0000; 169 static const uint32 kFileSelectorMask = 0x00ff0000;
147 static const uint32 kFileSelectorOffset = 16; 170 static const uint32 kFileSelectorOffset = 16;
148 static const uint32 kStartBlockMask = 0x0000FFFF; 171 static const uint32 kStartBlockMask = 0x0000FFFF;
149 static const uint32 kFileNameMask = 0x0FFFFFFF; 172 static const uint32 kFileNameMask = 0x0FFFFFFF;
150 173
151 CacheAddr value_; 174 CacheAddr value_;
152 }; 175 };
153 176
154 } // namespace disk_cache 177 } // namespace disk_cache
155 178
156 #endif // NET_DISK_CACHE_ADDR_H_ 179 #endif // NET_DISK_CACHE_ADDR_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/addr.cc » ('j') | net/disk_cache/addr.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698