OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_SIMPLE_SIMPLE_INDEX_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
| 11 #include <unordered_map> |
| 12 #include <unordered_set> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/callback.h" | 15 #include "base/callback.h" |
14 #include "base/containers/hash_tables.h" | |
15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
16 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 #include "base/timer/timer.h" | 24 #include "base/timer/timer.h" |
24 #include "net/base/cache_type.h" | 25 #include "net/base/cache_type.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // iff the entry exist in the index. | 111 // iff the entry exist in the index. |
111 bool UseIfExists(uint64_t entry_hash); | 112 bool UseIfExists(uint64_t entry_hash); |
112 | 113 |
113 void WriteToDisk(); | 114 void WriteToDisk(); |
114 | 115 |
115 // Update the size (in bytes) of an entry, in the metadata stored in the | 116 // Update the size (in bytes) of an entry, in the metadata stored in the |
116 // index. This should be the total disk-file size including all streams of the | 117 // index. This should be the total disk-file size including all streams of the |
117 // entry. | 118 // entry. |
118 bool UpdateEntrySize(uint64_t entry_hash, int64_t entry_size); | 119 bool UpdateEntrySize(uint64_t entry_hash, int64_t entry_size); |
119 | 120 |
120 typedef base::hash_map<uint64_t, EntryMetadata> EntrySet; | 121 using EntrySet = std::unordered_map<uint64_t, EntryMetadata>; |
121 | 122 |
122 static void InsertInEntrySet(uint64_t entry_hash, | 123 static void InsertInEntrySet(uint64_t entry_hash, |
123 const EntryMetadata& entry_metadata, | 124 const EntryMetadata& entry_metadata, |
124 EntrySet* entry_set); | 125 EntrySet* entry_set); |
125 | 126 |
126 // Executes the |callback| when the index is ready. Allows multiple callbacks. | 127 // Executes the |callback| when the index is ready. Allows multiple callbacks. |
127 int ExecuteWhenReady(const net::CompletionCallback& callback); | 128 int ExecuteWhenReady(const net::CompletionCallback& callback); |
128 | 129 |
129 // Returns entries from the index that have last accessed time matching the | 130 // Returns entries from the index that have last accessed time matching the |
130 // range between |initial_time| and |end_time| where open intervals are | 131 // range between |initial_time| and |end_time| where open intervals are |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 const net::CacheType cache_type_; | 180 const net::CacheType cache_type_; |
180 uint64_t cache_size_; // Total cache storage size in bytes. | 181 uint64_t cache_size_; // Total cache storage size in bytes. |
181 uint64_t max_size_; | 182 uint64_t max_size_; |
182 uint64_t high_watermark_; | 183 uint64_t high_watermark_; |
183 uint64_t low_watermark_; | 184 uint64_t low_watermark_; |
184 bool eviction_in_progress_; | 185 bool eviction_in_progress_; |
185 base::TimeTicks eviction_start_time_; | 186 base::TimeTicks eviction_start_time_; |
186 | 187 |
187 // This stores all the entry_hash of entries that are removed during | 188 // This stores all the entry_hash of entries that are removed during |
188 // initialization. | 189 // initialization. |
189 base::hash_set<uint64_t> removed_entries_; | 190 std::unordered_set<uint64_t> removed_entries_; |
190 bool initialized_; | 191 bool initialized_; |
191 IndexInitMethod init_method_; | 192 IndexInitMethod init_method_; |
192 | 193 |
193 scoped_ptr<SimpleIndexFile> index_file_; | 194 scoped_ptr<SimpleIndexFile> index_file_; |
194 | 195 |
195 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; | 196 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
196 | 197 |
197 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 198 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
198 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 199 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
199 base::ThreadChecker io_thread_checker_; | 200 base::ThreadChecker io_thread_checker_; |
(...skipping 11 matching lines...) Expand all Loading... |
211 | 212 |
212 // Set to true when the app is on the background. When the app is in the | 213 // Set to true when the app is on the background. When the app is in the |
213 // background we can write the index much more frequently, to insure fresh | 214 // background we can write the index much more frequently, to insure fresh |
214 // index on next startup. | 215 // index on next startup. |
215 bool app_on_background_; | 216 bool app_on_background_; |
216 }; | 217 }; |
217 | 218 |
218 } // namespace disk_cache | 219 } // namespace disk_cache |
219 | 220 |
220 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 221 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
OLD | NEW |