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_BACKEND_IMPL_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
28 class TaskRunner; | 28 class TaskRunner; |
29 } | 29 } |
30 | 30 |
31 namespace disk_cache { | 31 namespace disk_cache { |
32 | 32 |
33 // SimpleBackendImpl is a new cache backend that stores entries in individual | 33 // SimpleBackendImpl is a new cache backend that stores entries in individual |
34 // files. | 34 // files. |
35 // See http://www.chromium.org/developers/design-documents/network-stack/disk-ca
che/very-simple-backend | 35 // See |
| 36 // http://www.chromium.org/developers/design-documents/network-stack/disk-cache/
very-simple-backend |
36 // | 37 // |
37 // The non-static functions below must be called on the IO thread unless | 38 // The non-static functions below must be called on the IO thread unless |
38 // otherwise stated. | 39 // otherwise stated. |
39 | 40 |
40 class SimpleEntryImpl; | 41 class SimpleEntryImpl; |
41 class SimpleIndex; | 42 class SimpleIndex; |
42 | 43 |
43 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, | 44 class NET_EXPORT_PRIVATE SimpleBackendImpl |
44 public SimpleIndexDelegate, | 45 : public Backend, |
45 public base::SupportsWeakPtr<SimpleBackendImpl> { | 46 public SimpleIndexDelegate, |
| 47 public base::SupportsWeakPtr<SimpleBackendImpl> { |
46 public: | 48 public: |
47 SimpleBackendImpl(const base::FilePath& path, int max_bytes, | 49 SimpleBackendImpl(const base::FilePath& path, |
| 50 int max_bytes, |
48 net::CacheType cache_type, | 51 net::CacheType cache_type, |
49 base::SingleThreadTaskRunner* cache_thread, | 52 base::SingleThreadTaskRunner* cache_thread, |
50 net::NetLog* net_log); | 53 net::NetLog* net_log); |
51 | 54 |
52 virtual ~SimpleBackendImpl(); | 55 virtual ~SimpleBackendImpl(); |
53 | 56 |
54 net::CacheType cache_type() const { return cache_type_; } | 57 net::CacheType cache_type() const { return cache_type_; } |
55 SimpleIndex* index() { return index_.get(); } | 58 SimpleIndex* index() { return index_.get(); } |
56 | 59 |
57 base::TaskRunner* worker_pool() { return worker_pool_.get(); } | 60 base::TaskRunner* worker_pool() { return worker_pool_.get(); } |
(...skipping 22 matching lines...) Expand all Loading... |
80 // doom completed. | 83 // doom completed. |
81 void OnDoomComplete(uint64 entry_hash); | 84 void OnDoomComplete(uint64 entry_hash); |
82 | 85 |
83 // SimpleIndexDelegate: | 86 // SimpleIndexDelegate: |
84 virtual void DoomEntries(std::vector<uint64>* entry_hashes, | 87 virtual void DoomEntries(std::vector<uint64>* entry_hashes, |
85 const CompletionCallback& callback) OVERRIDE; | 88 const CompletionCallback& callback) OVERRIDE; |
86 | 89 |
87 // Backend: | 90 // Backend: |
88 virtual net::CacheType GetCacheType() const OVERRIDE; | 91 virtual net::CacheType GetCacheType() const OVERRIDE; |
89 virtual int32 GetEntryCount() const OVERRIDE; | 92 virtual int32 GetEntryCount() const OVERRIDE; |
90 virtual int OpenEntry(const std::string& key, Entry** entry, | 93 virtual int OpenEntry(const std::string& key, |
| 94 Entry** entry, |
91 const CompletionCallback& callback) OVERRIDE; | 95 const CompletionCallback& callback) OVERRIDE; |
92 virtual int CreateEntry(const std::string& key, Entry** entry, | 96 virtual int CreateEntry(const std::string& key, |
| 97 Entry** entry, |
93 const CompletionCallback& callback) OVERRIDE; | 98 const CompletionCallback& callback) OVERRIDE; |
94 virtual int DoomEntry(const std::string& key, | 99 virtual int DoomEntry(const std::string& key, |
95 const CompletionCallback& callback) OVERRIDE; | 100 const CompletionCallback& callback) OVERRIDE; |
96 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 101 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
97 virtual int DoomEntriesBetween(base::Time initial_time, | 102 virtual int DoomEntriesBetween(base::Time initial_time, |
98 base::Time end_time, | 103 base::Time end_time, |
99 const CompletionCallback& callback) OVERRIDE; | 104 const CompletionCallback& callback) OVERRIDE; |
100 virtual int DoomEntriesSince(base::Time initial_time, | 105 virtual int DoomEntriesSince(base::Time initial_time, |
101 const CompletionCallback& callback) OVERRIDE; | 106 const CompletionCallback& callback) OVERRIDE; |
102 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 107 virtual int OpenNextEntry(void** iter, |
| 108 Entry** next_entry, |
103 const CompletionCallback& callback) OVERRIDE; | 109 const CompletionCallback& callback) OVERRIDE; |
104 virtual void EndEnumeration(void** iter) OVERRIDE; | 110 virtual void EndEnumeration(void** iter) OVERRIDE; |
105 virtual void GetStats( | 111 virtual void GetStats( |
106 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; | 112 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; |
107 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 113 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
108 | 114 |
109 private: | 115 private: |
110 typedef base::hash_map<uint64, base::WeakPtr<SimpleEntryImpl> > EntryMap; | 116 typedef base::hash_map<uint64, base::WeakPtr<SimpleEntryImpl> > EntryMap; |
111 | 117 |
112 typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)> | 118 typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // corresponding to |hash| in the map of active entries, opens it. Otherwise, | 151 // corresponding to |hash| in the map of active entries, opens it. Otherwise, |
146 // a new empty Entry will be created, opened and filled with information from | 152 // a new empty Entry will be created, opened and filled with information from |
147 // the disk. | 153 // the disk. |
148 int OpenEntryFromHash(uint64 entry_hash, | 154 int OpenEntryFromHash(uint64 entry_hash, |
149 Entry** entry, | 155 Entry** entry, |
150 const CompletionCallback& callback); | 156 const CompletionCallback& callback); |
151 | 157 |
152 // Doom the entry corresponding to |entry_hash|, if it's active or currently | 158 // Doom the entry corresponding to |entry_hash|, if it's active or currently |
153 // pending doom. This function does not block if there is an active entry, | 159 // pending doom. This function does not block if there is an active entry, |
154 // which is very important to prevent races in DoomEntries() above. | 160 // which is very important to prevent races in DoomEntries() above. |
155 int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback & callback); | 161 int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback& callback); |
156 | 162 |
157 // Called when the index is initilized to find the next entry in the iterator | 163 // Called when the index is initilized to find the next entry in the iterator |
158 // |iter|. If there are no more hashes in the iterator list, net::ERR_FAILED | 164 // |iter|. If there are no more hashes in the iterator list, net::ERR_FAILED |
159 // is returned. Otherwise, calls OpenEntryFromHash. | 165 // is returned. Otherwise, calls OpenEntryFromHash. |
160 void GetNextEntryInIterator(void** iter, | 166 void GetNextEntryInIterator(void** iter, |
161 Entry** next_entry, | 167 Entry** next_entry, |
162 const CompletionCallback& callback, | 168 const CompletionCallback& callback, |
163 int error_code); | 169 int error_code); |
164 | 170 |
165 // Called when we tried to open an entry with hash alone. When a blank entry | 171 // Called when we tried to open an entry with hash alone. When a blank entry |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // is complete. The base::Closure map target is used to store deferred | 216 // is complete. The base::Closure map target is used to store deferred |
211 // operations to be run at the completion of the Doom. | 217 // operations to be run at the completion of the Doom. |
212 base::hash_map<uint64, std::vector<base::Closure> > entries_pending_doom_; | 218 base::hash_map<uint64, std::vector<base::Closure> > entries_pending_doom_; |
213 | 219 |
214 net::NetLog* const net_log_; | 220 net::NetLog* const net_log_; |
215 }; | 221 }; |
216 | 222 |
217 } // namespace disk_cache | 223 } // namespace disk_cache |
218 | 224 |
219 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 225 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
OLD | NEW |