OLD | NEW |
---|---|
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 Loading... | |
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 // Conversions between the address of an external file and the address of the | |
112 // control block of that external file. | |
113 Addr AsExternal() const; | |
114 Addr AsBlockFile() const; | |
115 | |
116 static Addr FromEntryAddress(uint32 value) { | |
117 return Addr(kInitializedMask + (BLOCK_ENTRIES << kFileTypeOffset) + value); | |
gavinp
2013/06/13 19:49:00
Can value here have a block count & file selector,
rvargas (doing something else)
2013/06/13 22:46:29
The number of blocks is fixed to 1 (0 on the bit p
| |
118 } | |
119 | |
120 static Addr FromEvictedAddress(uint32 value) { | |
121 return Addr(kInitializedMask + (BLOCK_EVICTED << kFileTypeOffset) + value); | |
122 } | |
123 | |
104 static int BlockSizeForFileType(FileType file_type) { | 124 static int BlockSizeForFileType(FileType file_type) { |
105 switch (file_type) { | 125 switch (file_type) { |
106 case RANKINGS: | 126 case RANKINGS: |
107 return 36; | 127 return 36; |
108 case BLOCK_256: | 128 case BLOCK_256: |
109 return 256; | 129 return 256; |
110 case BLOCK_1K: | 130 case BLOCK_1K: |
111 return 1024; | 131 return 1024; |
112 case BLOCK_4K: | 132 case BLOCK_4K: |
113 return 4096; | 133 return 4096; |
134 case BLOCK_FILES: | |
135 return 8; | |
136 case BLOCK_ENTRIES: | |
137 return 104; | |
138 case BLOCK_EVICTED: | |
139 return 48; | |
114 default: | 140 default: |
115 return 0; | 141 return 0; |
116 } | 142 } |
117 } | 143 } |
118 | 144 |
119 static FileType RequiredFileType(int size) { | 145 static FileType RequiredFileType(int size) { |
120 if (size < 1024) | 146 if (size < 1024) |
121 return BLOCK_256; | 147 return BLOCK_256; |
122 else if (size < 4096) | 148 else if (size < 4096) |
123 return BLOCK_1K; | 149 return BLOCK_1K; |
124 else if (size <= 4096 * 4) | 150 else if (size <= 4096 * 4) |
125 return BLOCK_4K; | 151 return BLOCK_4K; |
126 else | 152 else |
127 return EXTERNAL; | 153 return EXTERNAL; |
128 } | 154 } |
129 | 155 |
130 static int RequiredBlocks(int size, FileType file_type) { | 156 static int RequiredBlocks(int size, FileType file_type) { |
131 int block_size = BlockSizeForFileType(file_type); | 157 int block_size = BlockSizeForFileType(file_type); |
132 return (size + block_size - 1) / block_size; | 158 return (size + block_size - 1) / block_size; |
133 } | 159 } |
134 | 160 |
135 // Returns true if this address looks like a valid one. | 161 // Returns true if this address looks like a valid one. |
136 bool SanityCheck() const; | 162 bool SanityCheckV2() const; |
163 bool SanityCheckV3() const; | |
137 bool SanityCheckForEntryV2() const; | 164 bool SanityCheckForEntryV2() const; |
165 bool SanityCheckForEntryV3() const; | |
138 bool SanityCheckForRankings() const; | 166 bool SanityCheckForRankings() const; |
139 | 167 |
140 private: | 168 private: |
141 static const uint32 kInitializedMask = 0x80000000; | 169 static const uint32 kInitializedMask = 0x80000000; |
142 static const uint32 kFileTypeMask = 0x70000000; | 170 static const uint32 kFileTypeMask = 0x70000000; |
143 static const uint32 kFileTypeOffset = 28; | 171 static const uint32 kFileTypeOffset = 28; |
gavinp
2013/06/13 19:49:00
Here's another good spot for vertical whitespace.
gavinp
2013/06/13 23:38:27
These constants are difficult to understand. They
rvargas (doing something else)
2013/06/14 02:15:44
I'm sorry, but I read your comment and I couldn't
gavinp
2013/06/14 15:15:23
... for every component of the address, except the
rvargas (doing something else)
2013/06/14 19:25:17
And that would be because this is part of the impl
gavinp
2013/06/16 23:44:15
Keeping the definitions all in one place is probab
| |
144 static const uint32 kNumBlocksMask = 0x03000000; | 172 static const uint32 kNumBlocksMask = 0x03000000; |
145 static const uint32 kNumBlocksOffset = 24; | 173 static const uint32 kNumBlocksOffset = 24; |
146 static const uint32 kFileSelectorMask = 0x00ff0000; | 174 static const uint32 kFileSelectorMask = 0x00ff0000; |
147 static const uint32 kFileSelectorOffset = 16; | 175 static const uint32 kFileSelectorOffset = 16; |
148 static const uint32 kStartBlockMask = 0x0000FFFF; | 176 static const uint32 kStartBlockMask = 0x0000FFFF; |
gavinp
2013/06/13 19:49:00
Probably a good idea to put vertical whitespace he
| |
149 static const uint32 kFileNameMask = 0x0FFFFFFF; | 177 static const uint32 kFileNameMask = 0x0FFFFFFF; |
150 | 178 |
151 CacheAddr value_; | 179 CacheAddr value_; |
152 }; | 180 }; |
153 | 181 |
154 } // namespace disk_cache | 182 } // namespace disk_cache |
155 | 183 |
156 #endif // NET_DISK_CACHE_ADDR_H_ | 184 #endif // NET_DISK_CACHE_ADDR_H_ |
OLD | NEW |