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 <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/hash_tables.h" | 16 #include "base/hash_tables.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "base/timer.h" | 22 #include "base/timer.h" |
23 #include "net/base/completion_callback.h" | 23 #include "net/base/completion_callback.h" |
24 #include "net/base/net_export.h" | 24 #include "net/base/net_export.h" |
25 | 25 |
26 #if defined(OS_ANDROID) | |
27 #include "net/android/simple_cache_activity_status_notifier.h" | |
28 #endif | |
29 | |
30 class Pickle; | 26 class Pickle; |
31 class PickleIterator; | 27 class PickleIterator; |
32 | 28 |
33 namespace base { | 29 namespace base { |
34 class SingleThreadTaskRunner; | 30 class SingleThreadTaskRunner; |
35 } | 31 } |
36 | 32 |
37 namespace disk_cache { | 33 namespace disk_cache { |
38 | 34 |
39 class NET_EXPORT_PRIVATE EntryMetadata { | 35 class NET_EXPORT_PRIVATE EntryMetadata { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 const base::FilePath& index_filename); | 147 const base::FilePath& index_filename); |
152 | 148 |
153 static void WriteToDiskInternal(const base::FilePath& index_filename, | 149 static void WriteToDiskInternal(const base::FilePath& index_filename, |
154 scoped_ptr<Pickle> pickle, | 150 scoped_ptr<Pickle> pickle, |
155 const base::TimeTicks& start_time); | 151 const base::TimeTicks& start_time); |
156 | 152 |
157 // Must run on IO Thread. | 153 // Must run on IO Thread. |
158 void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries, | 154 void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries, |
159 bool force_index_flush); | 155 bool force_index_flush); |
160 | 156 |
161 #if defined(OS_ANDROID) | |
162 void ActivityStatusChanged( | |
163 net::SimpleCacheActivityStatusNotifier::ActivityStatus activity_status); | |
164 #endif | |
165 | |
166 EntrySet entries_set_; | 157 EntrySet entries_set_; |
167 uint64 cache_size_; // Total cache storage size in bytes. | 158 uint64 cache_size_; // Total cache storage size in bytes. |
168 uint64 max_size_; | 159 uint64 max_size_; |
169 uint64 high_watermark_; | 160 uint64 high_watermark_; |
170 uint64 low_watermark_; | 161 uint64 low_watermark_; |
171 bool eviction_in_progress_; | 162 bool eviction_in_progress_; |
172 base::TimeTicks eviction_start_time_; | 163 base::TimeTicks eviction_start_time_; |
173 | 164 |
174 // This stores all the hash_key of entries that are removed during | 165 // This stores all the hash_key of entries that are removed during |
175 // initialization. | 166 // initialization. |
176 base::hash_set<uint64> removed_entries_; | 167 base::hash_set<uint64> removed_entries_; |
177 bool initialized_; | 168 bool initialized_; |
178 | 169 |
179 base::FilePath index_filename_; | 170 base::FilePath index_filename_; |
180 | 171 |
181 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 172 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
182 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; | 173 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
183 | 174 |
184 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 175 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
185 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 176 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
186 base::ThreadChecker io_thread_checker_; | 177 base::ThreadChecker io_thread_checker_; |
187 | 178 |
| 179 // Timestamp of the last time we wrote the index to disk. |
| 180 // PostponeWritingToDisk() may give up postponing and allow the write if it |
| 181 // has been a while since last time we wrote. |
| 182 base::Time last_write_to_disk_; |
188 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; | 183 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; |
189 | 184 |
190 typedef std::list<net::CompletionCallback> CallbackList; | 185 typedef std::list<net::CompletionCallback> CallbackList; |
191 CallbackList to_run_when_initialized_; | 186 CallbackList to_run_when_initialized_; |
192 | |
193 #if defined(OS_ANDROID) | |
194 net::SimpleCacheActivityStatusNotifier activity_status_notifier_; | |
195 #endif | |
196 bool app_on_background_; | |
197 }; | 187 }; |
198 | 188 |
199 } // namespace disk_cache | 189 } // namespace disk_cache |
200 | 190 |
201 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 191 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
OLD | NEW |