OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef NET_DISK_CACHE_BLOCKFILE_INDEX_TABLE_V3_H_ | 5 #ifndef NET_DISK_CACHE_BLOCKFILE_INDEX_TABLE_V3_H_ |
6 #define NET_DISK_CACHE_BLOCKFILE_INDEX_TABLE_V3_H_ | 6 #define NET_DISK_CACHE_BLOCKFILE_INDEX_TABLE_V3_H_ |
7 | 7 |
8 // The IndexTable class is in charge of handling all the details about the main | 8 // The IndexTable class is in charge of handling all the details about the main |
9 // index table of the cache. It provides methods to locate entries in the cache, | 9 // index table of the cache. It provides methods to locate entries in the cache, |
10 // create new entries and modify existing entries. It hides the fact that the | 10 // create new entries and modify existing entries. It hides the fact that the |
11 // table is backed up across multiple physical files, and that the files can | 11 // table is backed up across multiple physical files, and that the files can |
12 // grow and be remapped while the cache is in use. However, note that this class | 12 // grow and be remapped while the cache is in use. However, note that this class |
13 // doesn't do any direct management of the backing files, and it operates only | 13 // doesn't do any direct management of the backing files, and it operates only |
14 // with the tables in memory. | 14 // with the tables in memory. |
15 // | 15 // |
16 // When the current index needs to grow, the backend is notified so that files | 16 // When the current index needs to grow, the backend is notified so that files |
17 // are extended and remapped as needed. After that, the IndexTable should be | 17 // are extended and remapped as needed. After that, the IndexTable should be |
18 // re-initialized with the new structures. Note that the IndexTable instance is | 18 // re-initialized with the new structures. Note that the IndexTable instance is |
19 // still functional while the backend performs file IO. | 19 // still functional while the backend performs file IO. |
20 | 20 |
21 #include <stddef.h> | 21 #include <stddef.h> |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 | 23 |
| 24 #include <memory> |
24 #include <vector> | 25 #include <vector> |
25 | 26 |
26 #include "base/macros.h" | 27 #include "base/macros.h" |
27 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
28 #include "base/memory/scoped_ptr.h" | |
29 #include "base/time/time.h" | 29 #include "base/time/time.h" |
30 #include "net/base/net_export.h" | 30 #include "net/base/net_export.h" |
31 #include "net/disk_cache/blockfile/addr.h" | 31 #include "net/disk_cache/blockfile/addr.h" |
32 #include "net/disk_cache/blockfile/bitmap.h" | 32 #include "net/disk_cache/blockfile/bitmap.h" |
33 #include "net/disk_cache/blockfile/disk_format_v3.h" | 33 #include "net/disk_cache/blockfile/disk_format_v3.h" |
34 | 34 |
35 namespace net { | 35 namespace net { |
36 class IOBuffer; | 36 class IOBuffer; |
37 } | 37 } |
38 | 38 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 // The data required to initialize an index. Note that not all fields have to | 160 // The data required to initialize an index. Note that not all fields have to |
161 // be provided when growing the tables. | 161 // be provided when growing the tables. |
162 struct NET_EXPORT_PRIVATE IndexTableInitData { | 162 struct NET_EXPORT_PRIVATE IndexTableInitData { |
163 IndexTableInitData(); | 163 IndexTableInitData(); |
164 ~IndexTableInitData(); | 164 ~IndexTableInitData(); |
165 | 165 |
166 IndexBitmap* index_bitmap; | 166 IndexBitmap* index_bitmap; |
167 IndexBucket* main_table; | 167 IndexBucket* main_table; |
168 IndexBucket* extra_table; | 168 IndexBucket* extra_table; |
169 scoped_ptr<IndexHeaderV3> backup_header; | 169 std::unique_ptr<IndexHeaderV3> backup_header; |
170 scoped_ptr<uint32_t[]> backup_bitmap; | 170 std::unique_ptr<uint32_t[]> backup_bitmap; |
171 }; | 171 }; |
172 | 172 |
173 // See the description at the top of this file. | 173 // See the description at the top of this file. |
174 class NET_EXPORT_PRIVATE IndexTable { | 174 class NET_EXPORT_PRIVATE IndexTable { |
175 public: | 175 public: |
176 explicit IndexTable(IndexTableBackend* backend); | 176 explicit IndexTable(IndexTableBackend* backend); |
177 ~IndexTable(); | 177 ~IndexTable(); |
178 | 178 |
179 // Initializes the object, or re-initializes it when the backing files grow. | 179 // Initializes the object, or re-initializes it when the backing files grow. |
180 // Note that the only supported way to initialize this objeect is using | 180 // Note that the only supported way to initialize this objeect is using |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void CheckBucketList(int bucket_id); | 260 void CheckBucketList(int bucket_id); |
261 | 261 |
262 uint32_t GetLocation(const IndexCell& cell); | 262 uint32_t GetLocation(const IndexCell& cell); |
263 uint32_t GetHashValue(const IndexCell& cell); | 263 uint32_t GetHashValue(const IndexCell& cell); |
264 uint32_t GetFullHash(const IndexCell& cell, uint32_t lower_part); | 264 uint32_t GetFullHash(const IndexCell& cell, uint32_t lower_part); |
265 bool IsHashMatch(const IndexCell& cell, uint32_t hash); | 265 bool IsHashMatch(const IndexCell& cell, uint32_t hash); |
266 bool MisplacedHash(const IndexCell& cell, uint32_t hash); | 266 bool MisplacedHash(const IndexCell& cell, uint32_t hash); |
267 | 267 |
268 IndexTableBackend* backend_; | 268 IndexTableBackend* backend_; |
269 IndexHeaderV3* header_; | 269 IndexHeaderV3* header_; |
270 scoped_ptr<Bitmap> bitmap_; | 270 std::unique_ptr<Bitmap> bitmap_; |
271 scoped_ptr<Bitmap> backup_bitmap_; | 271 std::unique_ptr<Bitmap> backup_bitmap_; |
272 scoped_ptr<uint32_t[]> backup_bitmap_storage_; | 272 std::unique_ptr<uint32_t[]> backup_bitmap_storage_; |
273 scoped_ptr<IndexHeaderV3> backup_header_; | 273 std::unique_ptr<IndexHeaderV3> backup_header_; |
274 IndexBucket* main_table_; | 274 IndexBucket* main_table_; |
275 IndexBucket* extra_table_; | 275 IndexBucket* extra_table_; |
276 uint32_t mask_; // Binary mask to map a hash to the hash table. | 276 uint32_t mask_; // Binary mask to map a hash to the hash table. |
277 int extra_bits_; // How many bits are in mask_ above the default value. | 277 int extra_bits_; // How many bits are in mask_ above the default value. |
278 bool modified_; | 278 bool modified_; |
279 bool small_table_; | 279 bool small_table_; |
280 | 280 |
281 DISALLOW_COPY_AND_ASSIGN(IndexTable); | 281 DISALLOW_COPY_AND_ASSIGN(IndexTable); |
282 }; | 282 }; |
283 | 283 |
284 } // namespace disk_cache | 284 } // namespace disk_cache |
285 | 285 |
286 #endif // NET_DISK_CACHE_BLOCKFILE_INDEX_TABLE_V3_H_ | 286 #endif // NET_DISK_CACHE_BLOCKFILE_INDEX_TABLE_V3_H_ |
OLD | NEW |