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