Chromium Code Reviews| 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 "base/android/activity_status.h" | |
| 28 #endif | |
| 29 | |
| 26 class Pickle; | 30 class Pickle; |
| 27 class PickleIterator; | 31 class PickleIterator; |
| 28 | 32 |
| 29 namespace base { | 33 namespace base { |
| 30 class SingleThreadTaskRunner; | 34 class SingleThreadTaskRunner; |
| 31 } | 35 } |
| 32 | 36 |
| 33 namespace disk_cache { | 37 namespace disk_cache { |
| 34 | 38 |
| 35 class NET_EXPORT_PRIVATE EntryMetadata { | 39 class NET_EXPORT_PRIVATE EntryMetadata { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 65 // If you want to make calculations/comparisons, you should use the | 69 // If you want to make calculations/comparisons, you should use the |
| 66 // base::Time() class. Use the GetLastUsedTime() method above. | 70 // base::Time() class. Use the GetLastUsedTime() method above. |
| 67 // TODO(felipeg): Use Time() here. | 71 // TODO(felipeg): Use Time() here. |
| 68 int64 last_used_time_; | 72 int64 last_used_time_; |
| 69 | 73 |
| 70 uint64 entry_size_; // Storage size in bytes. | 74 uint64 entry_size_; // Storage size in bytes. |
| 71 }; | 75 }; |
| 72 | 76 |
| 73 // This class is not Thread-safe. | 77 // This class is not Thread-safe. |
| 74 class NET_EXPORT_PRIVATE SimpleIndex | 78 class NET_EXPORT_PRIVATE SimpleIndex |
| 75 : public base::SupportsWeakPtr<SimpleIndex> { | 79 : public base::SupportsWeakPtr<SimpleIndex> |
|
Philippe
2013/05/03 10:11:47
Nit: the brace was happy there :)
gavinp
2013/05/03 12:16:53
Done.
| |
| 80 { | |
| 76 public: | 81 public: |
| 77 SimpleIndex(base::SingleThreadTaskRunner* cache_thread, | 82 SimpleIndex(base::SingleThreadTaskRunner* cache_thread, |
| 78 base::SingleThreadTaskRunner* io_thread, | 83 base::SingleThreadTaskRunner* io_thread, |
| 79 const base::FilePath& path); | 84 const base::FilePath& path); |
| 80 | 85 |
| 81 virtual ~SimpleIndex(); | 86 virtual ~SimpleIndex(); |
| 82 | 87 |
| 83 void Initialize(); | 88 void Initialize(); |
| 84 | 89 |
| 85 bool SetMaxSize(int max_bytes); | 90 bool SetMaxSize(int max_bytes); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 const base::FilePath& index_filename); | 152 const base::FilePath& index_filename); |
| 148 | 153 |
| 149 static void WriteToDiskInternal(const base::FilePath& index_filename, | 154 static void WriteToDiskInternal(const base::FilePath& index_filename, |
| 150 scoped_ptr<Pickle> pickle, | 155 scoped_ptr<Pickle> pickle, |
| 151 const base::TimeTicks& start_time); | 156 const base::TimeTicks& start_time); |
| 152 | 157 |
| 153 // Must run on IO Thread. | 158 // Must run on IO Thread. |
| 154 void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries, | 159 void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries, |
| 155 bool force_index_flush); | 160 bool force_index_flush); |
| 156 | 161 |
| 162 #if defined(OS_ANDROID) | |
| 163 void OnActivityStateChange(base::android::ActivityState state); | |
| 164 #endif | |
| 165 | |
| 157 EntrySet entries_set_; | 166 EntrySet entries_set_; |
| 167 | |
| 168 #if defined(OS_ANDROID) | |
|
felipeg
2013/05/03 10:03:00
I know it would mix member vars with functions, bu
gavinp
2013/05/03 12:16:53
Done.
| |
| 169 base::android::ActivityStatus::Listener activity_status_listener_; | |
| 170 #endif | |
| 171 | |
| 158 uint64 cache_size_; // Total cache storage size in bytes. | 172 uint64 cache_size_; // Total cache storage size in bytes. |
| 159 uint64 max_size_; | 173 uint64 max_size_; |
| 160 uint64 high_watermark_; | 174 uint64 high_watermark_; |
| 161 uint64 low_watermark_; | 175 uint64 low_watermark_; |
| 162 bool eviction_in_progress_; | 176 bool eviction_in_progress_; |
| 163 base::TimeTicks eviction_start_time_; | 177 base::TimeTicks eviction_start_time_; |
| 164 | 178 |
| 165 // This stores all the hash_key of entries that are removed during | 179 // This stores all the hash_key of entries that are removed during |
| 166 // initialization. | 180 // initialization. |
| 167 base::hash_set<uint64> removed_entries_; | 181 base::hash_set<uint64> removed_entries_; |
| 168 bool initialized_; | 182 bool initialized_; |
| 169 | 183 |
| 170 base::FilePath index_filename_; | 184 base::FilePath index_filename_; |
| 171 | 185 |
| 172 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 186 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
| 173 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; | 187 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
| 174 | 188 |
| 175 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 189 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
| 176 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 190 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
| 177 base::ThreadChecker io_thread_checker_; | 191 base::ThreadChecker io_thread_checker_; |
| 178 | 192 |
| 179 // Timestamp of the last time we wrote the index to disk. | 193 // Timestamp of the last time we wrote the index to disk. |
| 180 // PostponeWritingToDisk() may give up postponing and allow the write if it | 194 // PostponeWritingToDisk() may give up postponing and allow the write if it |
| 181 // has been a while since last time we wrote. | 195 // has been a while since last time we wrote. |
| 182 base::Time last_write_to_disk_; | 196 base::Time last_write_to_disk_; |
| 183 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; | 197 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; |
| 184 | 198 |
| 185 typedef std::list<net::CompletionCallback> CallbackList; | 199 typedef std::list<net::CompletionCallback> CallbackList; |
| 186 CallbackList to_run_when_initialized_; | 200 CallbackList to_run_when_initialized_; |
| 201 | |
| 202 // Set to true when the app is on the background. When the app is in the | |
| 203 // background we can write the index much more frequently, to insure fresh | |
| 204 // index on next startup. | |
| 205 bool app_on_background_; | |
| 187 }; | 206 }; |
| 188 | 207 |
| 189 } // namespace disk_cache | 208 } // namespace disk_cache |
| 190 | 209 |
| 191 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 210 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
| OLD | NEW |