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

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

Issue 9702059: Disk cache: Remove all non essential synchronization from the cache destructor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/entry_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Defines the public interface of the disk cache. For more details see 5 // Defines the public interface of the disk cache. For more details see
6 // http://dev.chromium.org/developers/design-documents/network-stack/disk-cache 6 // http://dev.chromium.org/developers/design-documents/network-stack/disk-cache
7 7
8 #ifndef NET_DISK_CACHE_DISK_CACHE_H_ 8 #ifndef NET_DISK_CACHE_DISK_CACHE_H_
9 #define NET_DISK_CACHE_DISK_CACHE_H_ 9 #define NET_DISK_CACHE_DISK_CACHE_H_
10 #pragma once 10 #pragma once
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // completes (the callback is notified). 51 // completes (the callback is notified).
52 NET_EXPORT int CreateCacheBackend(net::CacheType type, const FilePath& path, 52 NET_EXPORT int CreateCacheBackend(net::CacheType type, const FilePath& path,
53 int max_bytes, bool force, 53 int max_bytes, bool force,
54 base::MessageLoopProxy* thread, 54 base::MessageLoopProxy* thread,
55 net::NetLog* net_log, Backend** backend, 55 net::NetLog* net_log, Backend** backend,
56 const net::CompletionCallback& callback); 56 const net::CompletionCallback& callback);
57 57
58 // The root interface for a disk cache instance. 58 // The root interface for a disk cache instance.
59 class NET_EXPORT Backend { 59 class NET_EXPORT Backend {
60 public: 60 public:
61 typedef net::CompletionCallback CompletionCallback;
gavinp 2012/03/16 17:31:35 This is a great idea! Unfortunately, all of the na
62
61 // If the backend is destroyed when there are operations in progress (any 63 // If the backend is destroyed when there are operations in progress (any
62 // callback that has not been invoked yet), this method cancels said 64 // callback that has not been invoked yet), this method cancels said
63 // operations so the callbacks are not invoked, possibly leaving the work 65 // operations so the callbacks are not invoked, possibly leaving the work
64 // half way (for instance, dooming just a few entries). Note that pending IO 66 // half way (for instance, dooming just a few entries). Note that pending IO
65 // for a given Entry (as opposed to the Backend) will still generate a 67 // for a given Entry (as opposed to the Backend) will still generate a
66 // callback from within this method. 68 // callback from within this method.
67 virtual ~Backend() {} 69 virtual ~Backend() {}
68 70
69 // Returns the number of entries in the cache. 71 // Returns the number of entries in the cache.
70 virtual int32 GetEntryCount() const = 0; 72 virtual int32 GetEntryCount() const = 0;
71 73
72 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry 74 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry
73 // object representing the specified disk cache entry. When the entry pointer 75 // object representing the specified disk cache entry. When the entry pointer
74 // is no longer needed, its Close method should be called. The return value is 76 // is no longer needed, its Close method should be called. The return value is
75 // a net error code. If this method returns ERR_IO_PENDING, the |callback| 77 // a net error code. If this method returns ERR_IO_PENDING, the |callback|
76 // will be invoked when the entry is available. The pointer to receive the 78 // will be invoked when the entry is available. The pointer to receive the
77 // |entry| must remain valid until the operation completes. 79 // |entry| must remain valid until the operation completes.
78 virtual int OpenEntry(const std::string& key, Entry** entry, 80 virtual int OpenEntry(const std::string& key, Entry** entry,
79 const net::CompletionCallback& callback) = 0; 81 const CompletionCallback& callback) = 0;
80 82
81 // Creates a new entry. Upon success, the out param holds a pointer to an 83 // Creates a new entry. Upon success, the out param holds a pointer to an
82 // Entry object representing the newly created disk cache entry. When the 84 // Entry object representing the newly created disk cache entry. When the
83 // entry pointer is no longer needed, its Close method should be called. The 85 // entry pointer is no longer needed, its Close method should be called. The
84 // return value is a net error code. If this method returns ERR_IO_PENDING, 86 // return value is a net error code. If this method returns ERR_IO_PENDING,
85 // the |callback| will be invoked when the entry is available. The pointer to 87 // the |callback| will be invoked when the entry is available. The pointer to
86 // receive the |entry| must remain valid until the operation completes. 88 // receive the |entry| must remain valid until the operation completes.
87 virtual int CreateEntry(const std::string& key, Entry** entry, 89 virtual int CreateEntry(const std::string& key, Entry** entry,
88 const net::CompletionCallback& callback) = 0; 90 const CompletionCallback& callback) = 0;
89 91
90 // Marks the entry, specified by the given key, for deletion. The return value 92 // Marks the entry, specified by the given key, for deletion. The return value
91 // is a net error code. If this method returns ERR_IO_PENDING, the |callback| 93 // is a net error code. If this method returns ERR_IO_PENDING, the |callback|
92 // will be invoked after the entry is doomed. 94 // will be invoked after the entry is doomed.
93 virtual int DoomEntry(const std::string& key, 95 virtual int DoomEntry(const std::string& key,
94 const net::CompletionCallback& callback) = 0; 96 const CompletionCallback& callback) = 0;
95 97
96 // Marks all entries for deletion. The return value is a net error code. If 98 // Marks all entries for deletion. The return value is a net error code. If
97 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the 99 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the
98 // operation completes. 100 // operation completes.
99 virtual int DoomAllEntries(const net::CompletionCallback& callback) = 0; 101 virtual int DoomAllEntries(const CompletionCallback& callback) = 0;
100 102
101 // Marks a range of entries for deletion. This supports unbounded deletes in 103 // Marks a range of entries for deletion. This supports unbounded deletes in
102 // either direction by using null Time values for either argument. The return 104 // either direction by using null Time values for either argument. The return
103 // value is a net error code. If this method returns ERR_IO_PENDING, the 105 // value is a net error code. If this method returns ERR_IO_PENDING, the
104 // |callback| will be invoked when the operation completes. 106 // |callback| will be invoked when the operation completes.
105 virtual int DoomEntriesBetween(const base::Time initial_time, 107 virtual int DoomEntriesBetween(const base::Time initial_time,
106 const base::Time end_time, 108 const base::Time end_time,
107 const net::CompletionCallback& callback) = 0; 109 const CompletionCallback& callback) = 0;
108 110
109 // Marks all entries accessed since |initial_time| for deletion. The return 111 // Marks all entries accessed since |initial_time| for deletion. The return
110 // value is a net error code. If this method returns ERR_IO_PENDING, the 112 // value is a net error code. If this method returns ERR_IO_PENDING, the
111 // |callback| will be invoked when the operation completes. 113 // |callback| will be invoked when the operation completes.
112 virtual int DoomEntriesSince(const base::Time initial_time, 114 virtual int DoomEntriesSince(const base::Time initial_time,
113 const net::CompletionCallback& callback) = 0; 115 const CompletionCallback& callback) = 0;
114 116
115 // Enumerates the cache. Initialize |iter| to NULL before calling this method 117 // Enumerates the cache. Initialize |iter| to NULL before calling this method
116 // the first time. That will cause the enumeration to start at the head of 118 // the first time. That will cause the enumeration to start at the head of
117 // the cache. For subsequent calls, pass the same |iter| pointer again without 119 // the cache. For subsequent calls, pass the same |iter| pointer again without
118 // changing its value. This method returns ERR_FAILED when there are no more 120 // changing its value. This method returns ERR_FAILED when there are no more
119 // entries to enumerate. When the entry pointer is no longer needed, its 121 // entries to enumerate. When the entry pointer is no longer needed, its
120 // Close method should be called. The return value is a net error code. If 122 // Close method should be called. The return value is a net error code. If
121 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the 123 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the
122 // |next_entry| is available. The pointer to receive the |next_entry| must 124 // |next_entry| is available. The pointer to receive the |next_entry| must
123 // remain valid until the operation completes. 125 // remain valid until the operation completes.
124 // 126 //
125 // NOTE: This method does not modify the last_used field of the entry, and 127 // NOTE: This method does not modify the last_used field of the entry, and
126 // therefore it does not impact the eviction ranking of the entry. 128 // therefore it does not impact the eviction ranking of the entry.
127 virtual int OpenNextEntry(void** iter, Entry** next_entry, 129 virtual int OpenNextEntry(void** iter, Entry** next_entry,
128 const net::CompletionCallback& callback) = 0; 130 const CompletionCallback& callback) = 0;
129 131
130 // Releases iter without returning the next entry. Whenever OpenNextEntry() 132 // Releases iter without returning the next entry. Whenever OpenNextEntry()
131 // returns true, but the caller is not interested in continuing the 133 // returns true, but the caller is not interested in continuing the
132 // enumeration by calling OpenNextEntry() again, the enumeration must be 134 // enumeration by calling OpenNextEntry() again, the enumeration must be
133 // ended by calling this method with iter returned by OpenNextEntry(). 135 // ended by calling this method with iter returned by OpenNextEntry().
134 virtual void EndEnumeration(void** iter) = 0; 136 virtual void EndEnumeration(void** iter) = 0;
135 137
136 // Return a list of cache statistics. 138 // Return a list of cache statistics.
137 virtual void GetStats( 139 virtual void GetStats(
138 std::vector<std::pair<std::string, std::string> >* stats) = 0; 140 std::vector<std::pair<std::string, std::string> >* stats) = 0;
139 141
140 // Called whenever an external cache in the system reuses the resource 142 // Called whenever an external cache in the system reuses the resource
141 // referred to by |key|. 143 // referred to by |key|.
142 virtual void OnExternalCacheHit(const std::string& key) = 0; 144 virtual void OnExternalCacheHit(const std::string& key) = 0;
143 }; 145 };
144 146
145 // This interface represents an entry in the disk cache. 147 // This interface represents an entry in the disk cache.
146 class NET_EXPORT Entry { 148 class NET_EXPORT Entry {
147 public: 149 public:
150 typedef net::CompletionCallback CompletionCallback;
151 typedef net::IOBuffer IOBuffer;
152
148 // Marks this cache entry for deletion. 153 // Marks this cache entry for deletion.
149 virtual void Doom() = 0; 154 virtual void Doom() = 0;
150 155
151 // Releases this entry. Calling this method does not cancel pending IO 156 // Releases this entry. Calling this method does not cancel pending IO
152 // operations on this entry. Even after the last reference to this object has 157 // operations on this entry. Even after the last reference to this object has
153 // been released, pending completion callbacks may be invoked. 158 // been released, pending completion callbacks may be invoked.
154 virtual void Close() = 0; 159 virtual void Close() = 0;
155 160
156 // Returns the key associated with this cache entry. 161 // Returns the key associated with this cache entry.
157 virtual std::string GetKey() const = 0; 162 virtual std::string GetKey() const = 0;
(...skipping 11 matching lines...) Expand all
169 // completion_callback is null, then this call blocks until the read 174 // completion_callback is null, then this call blocks until the read
170 // operation is complete. Otherwise, completion_callback will be 175 // operation is complete. Otherwise, completion_callback will be
171 // called on the current thread once the read completes. Returns the 176 // called on the current thread once the read completes. Returns the
172 // number of bytes read or a network error code. If a completion callback is 177 // number of bytes read or a network error code. If a completion callback is
173 // provided then it will be called if this function returns ERR_IO_PENDING, 178 // provided then it will be called if this function returns ERR_IO_PENDING,
174 // and a reference to |buf| will be retained until the callback is called. 179 // and a reference to |buf| will be retained until the callback is called.
175 // Note that the callback will be invoked in any case, even after Close has 180 // Note that the callback will be invoked in any case, even after Close has
176 // been called; in other words, the caller may close this entry without 181 // been called; in other words, the caller may close this entry without
177 // having to wait for all the callbacks, and still rely on the cleanup 182 // having to wait for all the callbacks, and still rely on the cleanup
178 // performed from the callback code. 183 // performed from the callback code.
179 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, 184 virtual int ReadData(int index, int offset, IOBuffer* buf, int buf_len,
180 const net::CompletionCallback& callback) = 0; 185 const CompletionCallback& callback) = 0;
181 186
182 // Copies cache data from the given buffer of length |buf_len|. If 187 // Copies cache data from the given buffer of length |buf_len|. If
183 // completion_callback is null, then this call blocks until the write 188 // completion_callback is null, then this call blocks until the write
184 // operation is complete. Otherwise, completion_callback will be 189 // operation is complete. Otherwise, completion_callback will be
185 // called on the current thread once the write completes. Returns the 190 // called on the current thread once the write completes. Returns the
186 // number of bytes written or a network error code. If a completion callback 191 // number of bytes written or a network error code. If a completion callback
187 // is provided then it will be called if this function returns ERR_IO_PENDING, 192 // is provided then it will be called if this function returns ERR_IO_PENDING,
188 // and a reference to |buf| will be retained until the callback is called. 193 // and a reference to |buf| will be retained until the callback is called.
189 // Note that the callback will be invoked in any case, even after Close has 194 // Note that the callback will be invoked in any case, even after Close has
190 // been called; in other words, the caller may close this entry without 195 // been called; in other words, the caller may close this entry without
191 // having to wait for all the callbacks, and still rely on the cleanup 196 // having to wait for all the callbacks, and still rely on the cleanup
192 // performed from the callback code. 197 // performed from the callback code.
193 // If truncate is true, this call will truncate the stored data at the end of 198 // If truncate is true, this call will truncate the stored data at the end of
194 // what we are writing here. 199 // what we are writing here.
195 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, 200 virtual int WriteData(int index, int offset, IOBuffer* buf, int buf_len,
196 const net::CompletionCallback& callback, 201 const CompletionCallback& callback,
197 bool truncate) = 0; 202 bool truncate) = 0;
198 203
199 // Sparse entries support: 204 // Sparse entries support:
200 // 205 //
201 // A Backend implementation can support sparse entries, so the cache keeps 206 // A Backend implementation can support sparse entries, so the cache keeps
202 // track of which parts of the entry have been written before. The backend 207 // track of which parts of the entry have been written before. The backend
203 // will never return data that was not written previously, so reading from 208 // will never return data that was not written previously, so reading from
204 // such region will return 0 bytes read (or actually the number of bytes read 209 // such region will return 0 bytes read (or actually the number of bytes read
205 // before reaching that region). 210 // before reaching that region).
206 // 211 //
(...skipping 26 matching lines...) Expand all
233 // requirement includes the case when an entry is closed while some operation 238 // requirement includes the case when an entry is closed while some operation
234 // is in progress and another object is instantiated; any IO operation will 239 // is in progress and another object is instantiated; any IO operation will
235 // fail while the previous operation is still in-flight. In order to deal with 240 // fail while the previous operation is still in-flight. In order to deal with
236 // this requirement, the caller could either wait until the operation 241 // this requirement, the caller could either wait until the operation
237 // completes before closing the entry, or call CancelSparseIO() before closing 242 // completes before closing the entry, or call CancelSparseIO() before closing
238 // the entry, and call ReadyForSparseIO() on the new entry and wait for the 243 // the entry, and call ReadyForSparseIO() on the new entry and wait for the
239 // callback before issuing new operations. 244 // callback before issuing new operations.
240 245
241 // Behaves like ReadData() except that this method is used to access sparse 246 // Behaves like ReadData() except that this method is used to access sparse
242 // entries. 247 // entries.
243 virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 248 virtual int ReadSparseData(int64 offset, IOBuffer* buf, int buf_len,
244 const net::CompletionCallback& callback) = 0; 249 const CompletionCallback& callback) = 0;
245 250
246 // Behaves like WriteData() except that this method is used to access sparse 251 // Behaves like WriteData() except that this method is used to access sparse
247 // entries. |truncate| is not part of this interface because a sparse entry 252 // entries. |truncate| is not part of this interface because a sparse entry
248 // is not expected to be reused with new data. To delete the old data and 253 // is not expected to be reused with new data. To delete the old data and
249 // start again, or to reduce the total size of the stream data (which implies 254 // start again, or to reduce the total size of the stream data (which implies
250 // that the content has changed), the whole entry should be doomed and 255 // that the content has changed), the whole entry should be doomed and
251 // re-created. 256 // re-created.
252 virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 257 virtual int WriteSparseData(int64 offset, IOBuffer* buf, int buf_len,
253 const net::CompletionCallback& callback) = 0; 258 const CompletionCallback& callback) = 0;
254 259
255 // Returns information about the currently stored portion of a sparse entry. 260 // Returns information about the currently stored portion of a sparse entry.
256 // |offset| and |len| describe a particular range that should be scanned to 261 // |offset| and |len| describe a particular range that should be scanned to
257 // find out if it is stored or not. |start| will contain the offset of the 262 // find out if it is stored or not. |start| will contain the offset of the
258 // first byte that is stored within this range, and the return value is the 263 // first byte that is stored within this range, and the return value is the
259 // minimum number of consecutive stored bytes. Note that it is possible that 264 // minimum number of consecutive stored bytes. Note that it is possible that
260 // this entry has stored more than the returned value. This method returns a 265 // this entry has stored more than the returned value. This method returns a
261 // net error code whenever the request cannot be completed successfully. If 266 // net error code whenever the request cannot be completed successfully. If
262 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the 267 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the
263 // operation completes, and |start| must remain valid until that point. 268 // operation completes, and |start| must remain valid until that point.
264 virtual int GetAvailableRange(int64 offset, int len, int64* start, 269 virtual int GetAvailableRange(int64 offset, int len, int64* start,
265 const net::CompletionCallback& callback) = 0; 270 const CompletionCallback& callback) = 0;
266 271
267 // Returns true if this entry could be a sparse entry or false otherwise. This 272 // Returns true if this entry could be a sparse entry or false otherwise. This
268 // is a quick test that may return true even if the entry is not really 273 // is a quick test that may return true even if the entry is not really
269 // sparse. This method doesn't modify the state of this entry (it will not 274 // sparse. This method doesn't modify the state of this entry (it will not
270 // create sparse tracking data). GetAvailableRange or ReadSparseData can be 275 // create sparse tracking data). GetAvailableRange or ReadSparseData can be
271 // used to perform a definitive test of whether an existing entry is sparse or 276 // used to perform a definitive test of whether an existing entry is sparse or
272 // not, but that method may modify the current state of the entry (making it 277 // not, but that method may modify the current state of the entry (making it
273 // sparse, for instance). The purpose of this method is to test an existing 278 // sparse, for instance). The purpose of this method is to test an existing
274 // entry, but without generating actual IO to perform a thorough check. 279 // entry, but without generating actual IO to perform a thorough check.
275 virtual bool CouldBeSparse() const = 0; 280 virtual bool CouldBeSparse() const = 0;
276 281
277 // Cancels any pending sparse IO operation (if any). The completion callback 282 // Cancels any pending sparse IO operation (if any). The completion callback
278 // of the operation in question will still be called when the operation 283 // of the operation in question will still be called when the operation
279 // finishes, but the operation will finish sooner when this method is used. 284 // finishes, but the operation will finish sooner when this method is used.
280 virtual void CancelSparseIO() = 0; 285 virtual void CancelSparseIO() = 0;
281 286
282 // Returns OK if this entry can be used immediately. If that is not the 287 // Returns OK if this entry can be used immediately. If that is not the
283 // case, returns ERR_IO_PENDING and invokes the provided callback when this 288 // case, returns ERR_IO_PENDING and invokes the provided callback when this
284 // entry is ready to use. This method always returns OK for non-sparse 289 // entry is ready to use. This method always returns OK for non-sparse
285 // entries, and returns ERR_IO_PENDING when a previous operation was cancelled 290 // entries, and returns ERR_IO_PENDING when a previous operation was cancelled
286 // (by calling CancelSparseIO), but the cache is still busy with it. If there 291 // (by calling CancelSparseIO), but the cache is still busy with it. If there
287 // is a pending operation that has not been cancelled, this method will return 292 // is a pending operation that has not been cancelled, this method will return
288 // OK although another IO operation cannot be issued at this time; in this 293 // OK although another IO operation cannot be issued at this time; in this
289 // case the caller should just wait for the regular callback to be invoked 294 // case the caller should just wait for the regular callback to be invoked
290 // instead of using this method to provide another callback. 295 // instead of using this method to provide another callback.
291 // 296 //
292 // Note that CancelSparseIO may have been called on another instance of this 297 // Note that CancelSparseIO may have been called on another instance of this
293 // object that refers to the same physical disk entry. 298 // object that refers to the same physical disk entry.
294 // Note: This method is deprecated. 299 // Note: This method is deprecated.
295 virtual int ReadyForSparseIO( 300 virtual int ReadyForSparseIO(const CompletionCallback& callback) = 0;
296 const net::CompletionCallback& completion_callback) = 0;
297 301
298 protected: 302 protected:
299 virtual ~Entry() {} 303 virtual ~Entry() {}
300 }; 304 };
301 305
302 } // namespace disk_cache 306 } // namespace disk_cache
303 307
304 #endif // NET_DISK_CACHE_DISK_CACHE_H_ 308 #endif // NET_DISK_CACHE_DISK_CACHE_H_
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698