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_BLOCKFILE_ADDR_H_ | 8 #ifndef NET_DISK_CACHE_BLOCKFILE_ADDR_H_ |
9 #define NET_DISK_CACHE_BLOCKFILE_ADDR_H_ | 9 #define NET_DISK_CACHE_BLOCKFILE_ADDR_H_ |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 BLOCK_4K = 4, | 24 BLOCK_4K = 4, |
25 BLOCK_FILES = 5, | 25 BLOCK_FILES = 5, |
26 BLOCK_ENTRIES = 6, | 26 BLOCK_ENTRIES = 6, |
27 BLOCK_EVICTED = 7 | 27 BLOCK_EVICTED = 7 |
28 }; | 28 }; |
29 | 29 |
30 const int kMaxBlockSize = 4096 * 4; | 30 const int kMaxBlockSize = 4096 * 4; |
31 const int16_t kMaxBlockFile = 255; | 31 const int16_t kMaxBlockFile = 255; |
32 const int kMaxNumBlocks = 4; | 32 const int kMaxNumBlocks = 4; |
33 const int16_t kFirstAdditionalBlockFile = 4; | 33 const int16_t kFirstAdditionalBlockFile = 4; |
34 const size_t kFirstAdditionalBlockFileV3 = 7; | |
35 | 34 |
36 // Defines a storage address for a cache record | 35 // Defines a storage address for a cache record |
37 // | 36 // |
38 // Header: | 37 // Header: |
39 // 1000 0000 0000 0000 0000 0000 0000 0000 : initialized bit | 38 // 1000 0000 0000 0000 0000 0000 0000 0000 : initialized bit |
40 // 0111 0000 0000 0000 0000 0000 0000 0000 : file type | 39 // 0111 0000 0000 0000 0000 0000 0000 0000 : file type |
41 // | 40 // |
42 // File type values: | 41 // File type values: |
43 // 0 = separate file on disk | 42 // 0 = separate file on disk |
44 // 1 = rankings block file | 43 // 1 = rankings block file |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 else | 153 else |
155 return EXTERNAL; | 154 return EXTERNAL; |
156 } | 155 } |
157 | 156 |
158 static int RequiredBlocks(int size, FileType file_type) { | 157 static int RequiredBlocks(int size, FileType file_type) { |
159 int block_size = BlockSizeForFileType(file_type); | 158 int block_size = BlockSizeForFileType(file_type); |
160 return (size + block_size - 1) / block_size; | 159 return (size + block_size - 1) / block_size; |
161 } | 160 } |
162 | 161 |
163 // Returns true if this address looks like a valid one. | 162 // Returns true if this address looks like a valid one. |
164 bool SanityCheckV2() const; | 163 bool SanityCheck() const; |
165 bool SanityCheckV3() const; | 164 bool SanityCheckForEntry() const; |
166 bool SanityCheckForEntryV2() const; | |
167 bool SanityCheckForEntryV3() const; | |
168 bool SanityCheckForRankings() const; | 165 bool SanityCheckForRankings() const; |
169 | 166 |
170 private: | 167 private: |
171 uint32_t reserved_bits() const { return value_ & kReservedBitsMask; } | 168 uint32_t reserved_bits() const { return value_ & kReservedBitsMask; } |
172 | 169 |
173 static const uint32_t kInitializedMask = 0x80000000; | 170 static const uint32_t kInitializedMask = 0x80000000; |
174 static const uint32_t kFileTypeMask = 0x70000000; | 171 static const uint32_t kFileTypeMask = 0x70000000; |
175 static const uint32_t kFileTypeOffset = 28; | 172 static const uint32_t kFileTypeOffset = 28; |
176 static const uint32_t kReservedBitsMask = 0x0c000000; | 173 static const uint32_t kReservedBitsMask = 0x0c000000; |
177 static const uint32_t kNumBlocksMask = 0x03000000; | 174 static const uint32_t kNumBlocksMask = 0x03000000; |
178 static const uint32_t kNumBlocksOffset = 24; | 175 static const uint32_t kNumBlocksOffset = 24; |
179 static const uint32_t kFileSelectorMask = 0x00ff0000; | 176 static const uint32_t kFileSelectorMask = 0x00ff0000; |
180 static const uint32_t kFileSelectorOffset = 16; | 177 static const uint32_t kFileSelectorOffset = 16; |
181 static const uint32_t kStartBlockMask = 0x0000FFFF; | 178 static const uint32_t kStartBlockMask = 0x0000FFFF; |
182 static const uint32_t kFileNameMask = 0x0FFFFFFF; | 179 static const uint32_t kFileNameMask = 0x0FFFFFFF; |
183 | 180 |
184 CacheAddr value_; | 181 CacheAddr value_; |
185 }; | 182 }; |
186 | 183 |
187 } // namespace disk_cache | 184 } // namespace disk_cache |
188 | 185 |
189 #endif // NET_DISK_CACHE_BLOCKFILE_ADDR_H_ | 186 #endif // NET_DISK_CACHE_BLOCKFILE_ADDR_H_ |
OLD | NEW |