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