Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: net/disk_cache/simple/simple_backend_impl.h

Issue 542733002: Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: now even less dumb Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
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 http://www.chromium.org/developers/design-documents/network-stack/disk-ca che/very-simple-backend
36 // 36 //
37 // The SimpleBackendImpl provides safe iteration; mutating entries during
38 // iteration cannot cause a crash. It is undefined whether entries created or
39 // destroyed during the iteration will be included in any pre-existing
40 // iterations.
41 //
37 // The non-static functions below must be called on the IO thread unless 42 // The non-static functions below must be called on the IO thread unless
38 // otherwise stated. 43 // otherwise stated.
39 44
40 class SimpleEntryImpl; 45 class SimpleEntryImpl;
41 class SimpleIndex; 46 class SimpleIndex;
42 47
43 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, 48 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
44 public SimpleIndexDelegate, 49 public SimpleIndexDelegate,
45 public base::SupportsWeakPtr<SimpleBackendImpl> { 50 public base::SupportsWeakPtr<SimpleBackendImpl> {
46 public: 51 public:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 virtual int CreateEntry(const std::string& key, Entry** entry, 95 virtual int CreateEntry(const std::string& key, Entry** entry,
91 const CompletionCallback& callback) OVERRIDE; 96 const CompletionCallback& callback) OVERRIDE;
92 virtual int DoomEntry(const std::string& key, 97 virtual int DoomEntry(const std::string& key,
93 const CompletionCallback& callback) OVERRIDE; 98 const CompletionCallback& callback) OVERRIDE;
94 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; 99 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE;
95 virtual int DoomEntriesBetween(base::Time initial_time, 100 virtual int DoomEntriesBetween(base::Time initial_time,
96 base::Time end_time, 101 base::Time end_time,
97 const CompletionCallback& callback) OVERRIDE; 102 const CompletionCallback& callback) OVERRIDE;
98 virtual int DoomEntriesSince(base::Time initial_time, 103 virtual int DoomEntriesSince(base::Time initial_time,
99 const CompletionCallback& callback) OVERRIDE; 104 const CompletionCallback& callback) OVERRIDE;
100 virtual int OpenNextEntry(void** iter, Entry** next_entry, 105 virtual scoped_ptr<Iterator> CreateIterator() OVERRIDE;
101 const CompletionCallback& callback) OVERRIDE;
102 virtual void EndEnumeration(void** iter) OVERRIDE;
103 virtual void GetStats( 106 virtual void GetStats(
104 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; 107 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE;
105 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; 108 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE;
106 109
107 private: 110 private:
111 class SimpleIterator;
112 friend class SimpleIterator;
113
108 typedef base::hash_map<uint64, SimpleEntryImpl*> EntryMap; 114 typedef base::hash_map<uint64, SimpleEntryImpl*> EntryMap;
109 115
110 typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)> 116 typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)>
111 InitializeIndexCallback; 117 InitializeIndexCallback;
112 118
113 class ActiveEntryProxy; 119 class ActiveEntryProxy;
114 friend class ActiveEntryProxy; 120 friend class ActiveEntryProxy;
115 121
116 // Return value of InitCacheStructureOnDisk(). 122 // Return value of InitCacheStructureOnDisk().
117 struct DiskStatResult { 123 struct DiskStatResult {
(...skipping 30 matching lines...) Expand all
148 // the disk. 154 // the disk.
149 int OpenEntryFromHash(uint64 entry_hash, 155 int OpenEntryFromHash(uint64 entry_hash,
150 Entry** entry, 156 Entry** entry,
151 const CompletionCallback& callback); 157 const CompletionCallback& callback);
152 158
153 // Doom the entry corresponding to |entry_hash|, if it's active or currently 159 // Doom the entry corresponding to |entry_hash|, if it's active or currently
154 // pending doom. This function does not block if there is an active entry, 160 // pending doom. This function does not block if there is an active entry,
155 // which is very important to prevent races in DoomEntries() above. 161 // which is very important to prevent races in DoomEntries() above.
156 int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback & callback); 162 int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback & callback);
157 163
158 // Called when the index is initilized to find the next entry in the iterator
159 // |iter|. If there are no more hashes in the iterator list, net::ERR_FAILED
160 // is returned. Otherwise, calls OpenEntryFromHash.
161 void GetNextEntryInIterator(void** iter,
162 Entry** next_entry,
163 const CompletionCallback& callback,
164 int error_code);
165
166 // Called when we tried to open an entry with hash alone. When a blank entry 164 // Called when we tried to open an entry with hash alone. When a blank entry
167 // has been created and filled in with information from the disk - based on a 165 // has been created and filled in with information from the disk - based on a
168 // hash alone - this checks that a duplicate active entry was not created 166 // hash alone - this checks that a duplicate active entry was not created
169 // using a key in the meantime. 167 // using a key in the meantime.
170 void OnEntryOpenedFromHash(uint64 hash, 168 void OnEntryOpenedFromHash(uint64 hash,
171 Entry** entry, 169 Entry** entry,
172 const scoped_refptr<SimpleEntryImpl>& simple_entry, 170 const scoped_refptr<SimpleEntryImpl>& simple_entry,
173 const CompletionCallback& callback, 171 const CompletionCallback& callback,
174 int error_code); 172 int error_code);
175 173
176 // Called when we tried to open an entry from key. When the entry has been 174 // Called when we tried to open an entry from key. When the entry has been
177 // opened, a check for key mismatch is performed. 175 // opened, a check for key mismatch is performed.
178 void OnEntryOpenedFromKey(const std::string key, 176 void OnEntryOpenedFromKey(const std::string key,
179 Entry** entry, 177 Entry** entry,
180 const scoped_refptr<SimpleEntryImpl>& simple_entry, 178 const scoped_refptr<SimpleEntryImpl>& simple_entry,
181 const CompletionCallback& callback, 179 const CompletionCallback& callback,
182 int error_code); 180 int error_code);
183 181
184 // Called at the end of the asynchronous operation triggered by
185 // OpenEntryFromHash. Makes sure to continue iterating if the open entry was
186 // not a success.
187 void CheckIterationReturnValue(void** iter,
188 Entry** entry,
189 const CompletionCallback& callback,
190 int error_code);
191
192 // A callback thunk used by DoomEntries to clear the |entries_pending_doom_| 182 // A callback thunk used by DoomEntries to clear the |entries_pending_doom_|
193 // after a mass doom. 183 // after a mass doom.
194 void DoomEntriesComplete(scoped_ptr<std::vector<uint64> > entry_hashes, 184 void DoomEntriesComplete(scoped_ptr<std::vector<uint64> > entry_hashes,
195 const CompletionCallback& callback, 185 const CompletionCallback& callback,
196 int result); 186 int result);
197 187
198 const base::FilePath path_; 188 const base::FilePath path_;
199 const net::CacheType cache_type_; 189 const net::CacheType cache_type_;
200 scoped_ptr<SimpleIndex> index_; 190 scoped_ptr<SimpleIndex> index_;
201 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; 191 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_;
202 scoped_refptr<base::TaskRunner> worker_pool_; 192 scoped_refptr<base::TaskRunner> worker_pool_;
203 193
204 int orig_max_size_; 194 int orig_max_size_;
205 const SimpleEntryImpl::OperationsMode entry_operations_mode_; 195 const SimpleEntryImpl::OperationsMode entry_operations_mode_;
206 196
207 EntryMap active_entries_; 197 EntryMap active_entries_;
208 198
209 // The set of all entries which are currently being doomed. To avoid races, 199 // The set of all entries which are currently being doomed. To avoid races,
210 // these entries cannot have Doom/Create/Open operations run until the doom 200 // these entries cannot have Doom/Create/Open operations run until the doom
211 // is complete. The base::Closure map target is used to store deferred 201 // is complete. The base::Closure map target is used to store deferred
212 // operations to be run at the completion of the Doom. 202 // operations to be run at the completion of the Doom.
213 base::hash_map<uint64, std::vector<base::Closure> > entries_pending_doom_; 203 base::hash_map<uint64, std::vector<base::Closure> > entries_pending_doom_;
214 204
215 net::NetLog* const net_log_; 205 net::NetLog* const net_log_;
216 }; 206 };
217 207
218 } // namespace disk_cache 208 } // namespace disk_cache
219 209
220 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ 210 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698