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/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
| 20 #include "net/base/completion_callback.h" |
19 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
20 | 22 |
21 class Pickle; | 23 class Pickle; |
22 class PickleIterator; | 24 class PickleIterator; |
23 | 25 |
24 namespace base { | 26 namespace base { |
25 class TaskRunner; | 27 class TaskRunner; |
26 } | 28 } |
27 | 29 |
28 namespace disk_cache { | 30 namespace disk_cache { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool UpdateEntrySize(const std::string& key, uint64 entry_size); | 96 bool UpdateEntrySize(const std::string& key, uint64 entry_size); |
95 | 97 |
96 // TODO(felipeg): This way we are storing the hash_key twice, as the | 98 // TODO(felipeg): This way we are storing the hash_key twice, as the |
97 // hash_map::key and as a member of EntryMetadata. We could save space if we | 99 // hash_map::key and as a member of EntryMetadata. We could save space if we |
98 // use a hash_set. | 100 // use a hash_set. |
99 typedef base::hash_map<uint64, EntryMetadata> EntrySet; | 101 typedef base::hash_map<uint64, EntryMetadata> EntrySet; |
100 | 102 |
101 static void InsertInEntrySet(const EntryMetadata& entry_metadata, | 103 static void InsertInEntrySet(const EntryMetadata& entry_metadata, |
102 EntrySet* entry_set); | 104 EntrySet* entry_set); |
103 | 105 |
| 106 // Executes the |callback| when the index is ready. Allows multiple callbacks. |
| 107 int ExecuteWhenReady(const net::CompletionCallback& callback); |
| 108 |
| 109 // Takes out entries from the index that have last accessed time matching the |
| 110 // range between |initial_time| and |end_time| where open intervals are |
| 111 // possible according to the definition given in |DoomEntriesBetween()| in the |
| 112 // disk cache backend interface. Returns the set of hashes taken out. |
| 113 scoped_ptr<std::vector<uint64> > ExtractEntriesBetween( |
| 114 const base::Time initial_time, |
| 115 const base::Time end_time); |
| 116 |
| 117 // Returns number of indexed entries. |
| 118 int32 GetEntryCount() const; |
| 119 |
104 private: | 120 private: |
105 typedef base::Callback<void(scoped_ptr<EntrySet>)> IndexCompletionCallback; | 121 typedef base::Callback<void(scoped_ptr<EntrySet>)> IndexCompletionCallback; |
106 | 122 |
107 virtual ~SimpleIndex(); | 123 virtual ~SimpleIndex(); |
108 | 124 |
109 static void LoadFromDisk( | 125 static void LoadFromDisk( |
110 const base::FilePath& index_filename, | 126 const base::FilePath& index_filename, |
111 const scoped_refptr<base::TaskRunner>& io_thread, | 127 const scoped_refptr<base::TaskRunner>& io_thread, |
112 const IndexCompletionCallback& completion_callback); | 128 const IndexCompletionCallback& completion_callback); |
113 | 129 |
(...skipping 16 matching lines...) Expand all Loading... |
130 bool initialized_; | 146 bool initialized_; |
131 | 147 |
132 base::FilePath index_filename_; | 148 base::FilePath index_filename_; |
133 | 149 |
134 scoped_refptr<base::TaskRunner> cache_thread_; | 150 scoped_refptr<base::TaskRunner> cache_thread_; |
135 scoped_refptr<base::TaskRunner> io_thread_; | 151 scoped_refptr<base::TaskRunner> io_thread_; |
136 | 152 |
137 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 153 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
138 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 154 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
139 base::ThreadChecker io_thread_checker_; | 155 base::ThreadChecker io_thread_checker_; |
| 156 |
| 157 typedef std::list<net::CompletionCallback> CallbackList; |
| 158 CallbackList to_run_when_initialized_; |
140 }; | 159 }; |
141 | 160 |
142 } // namespace disk_cache | 161 } // namespace disk_cache |
143 | 162 |
144 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 163 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
OLD | NEW |