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> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 FRIEND_TEST_ALL_PREFIXES(SimpleIndexTest, IsIndexFileStale); | 128 FRIEND_TEST_ALL_PREFIXES(SimpleIndexTest, IsIndexFileStale); |
129 FRIEND_TEST_ALL_PREFIXES(SimpleIndexTest, IndexSizeCorrectOnMerge); | 129 FRIEND_TEST_ALL_PREFIXES(SimpleIndexTest, IndexSizeCorrectOnMerge); |
130 typedef base::Callback<void(scoped_ptr<EntrySet>, bool force_index_flush)> | 130 typedef base::Callback<void(scoped_ptr<EntrySet>, bool force_index_flush)> |
131 IndexCompletionCallback; | 131 IndexCompletionCallback; |
132 | 132 |
133 void StartEvictionIfNeeded(); | 133 void StartEvictionIfNeeded(); |
134 void EvictionDone(scoped_ptr<int> result); | 134 void EvictionDone(scoped_ptr<int> result); |
135 | 135 |
136 void PostponeWritingToDisk(); | 136 void PostponeWritingToDisk(); |
137 | 137 |
| 138 void UpdateEntryIteratorSize(EntrySet::iterator* it, uint64 entry_size); |
| 139 |
138 // Using the mtime of the file and its mtime, detects if the index file is | 140 // Using the mtime of the file and its mtime, detects if the index file is |
139 // stale. | 141 // stale. |
140 static bool IsIndexFileStale(const base::FilePath& index_filename); | 142 static bool IsIndexFileStale(const base::FilePath& index_filename); |
141 | 143 |
142 static void InitializeInternal( | 144 static void InitializeInternal( |
143 const base::FilePath& index_filename, | 145 const base::FilePath& index_filename, |
144 base::SingleThreadTaskRunner* io_thread, | 146 base::SingleThreadTaskRunner* io_thread, |
145 const IndexCompletionCallback& completion_callback); | 147 const IndexCompletionCallback& completion_callback); |
146 | 148 |
147 // Enumerates all entries' files on disk and regenerates the index. | 149 // Enumerates all entries' files on disk and regenerates the index. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; | 185 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
184 | 186 |
185 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 187 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
186 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 188 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
187 base::ThreadChecker io_thread_checker_; | 189 base::ThreadChecker io_thread_checker_; |
188 | 190 |
189 // Timestamp of the last time we wrote the index to disk. | 191 // Timestamp of the last time we wrote the index to disk. |
190 // PostponeWritingToDisk() may give up postponing and allow the write if it | 192 // PostponeWritingToDisk() may give up postponing and allow the write if it |
191 // has been a while since last time we wrote. | 193 // has been a while since last time we wrote. |
192 base::TimeTicks last_write_to_disk_; | 194 base::TimeTicks last_write_to_disk_; |
| 195 |
193 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; | 196 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; |
| 197 base::Closure write_to_disk_cb_; |
194 | 198 |
195 typedef std::list<net::CompletionCallback> CallbackList; | 199 typedef std::list<net::CompletionCallback> CallbackList; |
196 CallbackList to_run_when_initialized_; | 200 CallbackList to_run_when_initialized_; |
197 | 201 |
198 // Set to true when the app is on the background. When the app is in the | 202 // Set to true when the app is on the background. When the app is in the |
199 // background we can write the index much more frequently, to insure fresh | 203 // background we can write the index much more frequently, to insure fresh |
200 // index on next startup. | 204 // index on next startup. |
201 bool app_on_background_; | 205 bool app_on_background_; |
202 }; | 206 }; |
203 | 207 |
204 } // namespace disk_cache | 208 } // namespace disk_cache |
205 | 209 |
206 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 210 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
OLD | NEW |