| 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 <map> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/hash_tables.h" | 15 #include "base/hash_tables.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 19 #include "base/time.h" | 20 #include "base/time.h" |
| 20 #include "base/timer.h" | 21 #include "base/timer.h" |
| 22 #include "net/base/completion_callback.h" |
| 21 #include "net/base/net_export.h" | 23 #include "net/base/net_export.h" |
| 22 | 24 |
| 23 class Pickle; | 25 class Pickle; |
| 24 class PickleIterator; | 26 class PickleIterator; |
| 25 | 27 |
| 26 namespace base { | 28 namespace base { |
| 27 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
| 28 } | 30 } |
| 29 | 31 |
| 30 namespace disk_cache { | 32 namespace disk_cache { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 bool UpdateEntrySize(const std::string& key, uint64 entry_size); | 99 bool UpdateEntrySize(const std::string& key, uint64 entry_size); |
| 98 | 100 |
| 99 // TODO(felipeg): This way we are storing the hash_key twice, as the | 101 // TODO(felipeg): This way we are storing the hash_key twice, as the |
| 100 // hash_map::key and as a member of EntryMetadata. We could save space if we | 102 // hash_map::key and as a member of EntryMetadata. We could save space if we |
| 101 // use a hash_set. | 103 // use a hash_set. |
| 102 typedef base::hash_map<uint64, EntryMetadata> EntrySet; | 104 typedef base::hash_map<uint64, EntryMetadata> EntrySet; |
| 103 | 105 |
| 104 static void InsertInEntrySet(const EntryMetadata& entry_metadata, | 106 static void InsertInEntrySet(const EntryMetadata& entry_metadata, |
| 105 EntrySet* entry_set); | 107 EntrySet* entry_set); |
| 106 | 108 |
| 109 // Executes the |callback| when the index is ready. Allows multiple callbacks. |
| 110 int ExecuteWhenReady(const net::CompletionCallback& callback); |
| 111 |
| 112 // Takes out entries from the index that have last accessed time matching the |
| 113 // range between |initial_time| and |end_time| where open intervals are |
| 114 // possible according to the definition given in |DoomEntriesBetween()| in the |
| 115 // disk cache backend interface. Returns the set of hashes taken out. |
| 116 scoped_ptr<std::vector<uint64> > RemoveEntriesBetween( |
| 117 const base::Time initial_time, |
| 118 const base::Time end_time); |
| 119 |
| 120 // Returns number of indexed entries. |
| 121 int32 GetEntryCount() const; |
| 122 |
| 107 private: | 123 private: |
| 108 typedef base::Callback<void(scoped_ptr<EntrySet>, bool force_index_flush)> | 124 typedef base::Callback<void(scoped_ptr<EntrySet>, bool force_index_flush)> |
| 109 IndexCompletionCallback; | 125 IndexCompletionCallback; |
| 110 | 126 |
| 111 void PostponeWritingToDisk(); | 127 void PostponeWritingToDisk(); |
| 112 | 128 |
| 113 static void LoadFromDisk( | 129 static void LoadFromDisk( |
| 114 const base::FilePath& index_filename, | 130 const base::FilePath& index_filename, |
| 115 base::SingleThreadTaskRunner* io_thread, | 131 base::SingleThreadTaskRunner* io_thread, |
| 116 const IndexCompletionCallback& completion_callback); | 132 const IndexCompletionCallback& completion_callback); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 141 | 157 |
| 142 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 158 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
| 143 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 159 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
| 144 base::ThreadChecker io_thread_checker_; | 160 base::ThreadChecker io_thread_checker_; |
| 145 | 161 |
| 146 // Timestamp of the last time we wrote the index to disk. | 162 // Timestamp of the last time we wrote the index to disk. |
| 147 // PostponeWritingToDisk() may give up postponing and allow the write if it | 163 // PostponeWritingToDisk() may give up postponing and allow the write if it |
| 148 // has been a while since last time we wrote. | 164 // has been a while since last time we wrote. |
| 149 base::Time last_write_to_disk_; | 165 base::Time last_write_to_disk_; |
| 150 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; | 166 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; |
| 167 |
| 168 typedef std::list<net::CompletionCallback> CallbackList; |
| 169 CallbackList to_run_when_initialized_; |
| 151 }; | 170 }; |
| 152 | 171 |
| 153 } // namespace disk_cache | 172 } // namespace disk_cache |
| 154 | 173 |
| 155 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 174 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
| OLD | NEW |