OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 10 |
| 11 #include <stdint.h> |
| 12 |
11 #include <string> | 13 #include <string> |
12 #include <vector> | 14 #include <vector> |
13 | 15 |
14 #include "base/basictypes.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/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "net/base/cache_type.h" | 20 #include "net/base/cache_type.h" |
20 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
21 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class FilePath; | 25 class FilePath; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // operations so the callbacks are not invoked, possibly leaving the work | 92 // operations so the callbacks are not invoked, possibly leaving the work |
92 // half way (for instance, dooming just a few entries). Note that pending IO | 93 // half way (for instance, dooming just a few entries). Note that pending IO |
93 // for a given Entry (as opposed to the Backend) will still generate a | 94 // for a given Entry (as opposed to the Backend) will still generate a |
94 // callback from within this method. | 95 // callback from within this method. |
95 virtual ~Backend() {} | 96 virtual ~Backend() {} |
96 | 97 |
97 // Returns the type of this cache. | 98 // Returns the type of this cache. |
98 virtual net::CacheType GetCacheType() const = 0; | 99 virtual net::CacheType GetCacheType() const = 0; |
99 | 100 |
100 // Returns the number of entries in the cache. | 101 // Returns the number of entries in the cache. |
101 virtual int32 GetEntryCount() const = 0; | 102 virtual int32_t GetEntryCount() const = 0; |
102 | 103 |
103 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry | 104 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry |
104 // object representing the specified disk cache entry. When the entry pointer | 105 // object representing the specified disk cache entry. When the entry pointer |
105 // is no longer needed, its Close method should be called. The return value is | 106 // is no longer needed, its Close method should be called. The return value is |
106 // a net error code. If this method returns ERR_IO_PENDING, the |callback| | 107 // a net error code. If this method returns ERR_IO_PENDING, the |callback| |
107 // will be invoked when the entry is available. The pointer to receive the | 108 // will be invoked when the entry is available. The pointer to receive the |
108 // |entry| must remain valid until the operation completes. | 109 // |entry| must remain valid until the operation completes. |
109 virtual int OpenEntry(const std::string& key, Entry** entry, | 110 virtual int OpenEntry(const std::string& key, Entry** entry, |
110 const CompletionCallback& callback) = 0; | 111 const CompletionCallback& callback) = 0; |
111 | 112 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // Returns the key associated with this cache entry. | 181 // Returns the key associated with this cache entry. |
181 virtual std::string GetKey() const = 0; | 182 virtual std::string GetKey() const = 0; |
182 | 183 |
183 // Returns the time when this cache entry was last used. | 184 // Returns the time when this cache entry was last used. |
184 virtual base::Time GetLastUsed() const = 0; | 185 virtual base::Time GetLastUsed() const = 0; |
185 | 186 |
186 // Returns the time when this cache entry was last modified. | 187 // Returns the time when this cache entry was last modified. |
187 virtual base::Time GetLastModified() const = 0; | 188 virtual base::Time GetLastModified() const = 0; |
188 | 189 |
189 // Returns the size of the cache data with the given index. | 190 // Returns the size of the cache data with the given index. |
190 virtual int32 GetDataSize(int index) const = 0; | 191 virtual int32_t GetDataSize(int index) const = 0; |
191 | 192 |
192 // Copies cached data into the given buffer of length |buf_len|. Returns the | 193 // Copies cached data into the given buffer of length |buf_len|. Returns the |
193 // number of bytes read or a network error code. If this function returns | 194 // number of bytes read or a network error code. If this function returns |
194 // ERR_IO_PENDING, the completion callback will be called on the current | 195 // ERR_IO_PENDING, the completion callback will be called on the current |
195 // thread when the operation completes, and a reference to |buf| will be | 196 // thread when the operation completes, and a reference to |buf| will be |
196 // retained until the callback is called. Note that as long as the function | 197 // retained until the callback is called. Note that as long as the function |
197 // does not complete immediately, the callback will always be invoked, even | 198 // does not complete immediately, the callback will always be invoked, even |
198 // after Close has been called; in other words, the caller may close this | 199 // after Close has been called; in other words, the caller may close this |
199 // entry without having to wait for all the callbacks, and still rely on the | 200 // entry without having to wait for all the callbacks, and still rely on the |
200 // cleanup performed from the callback code. | 201 // cleanup performed from the callback code. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // requirement includes the case when an entry is closed while some operation | 254 // requirement includes the case when an entry is closed while some operation |
254 // is in progress and another object is instantiated; any IO operation will | 255 // is in progress and another object is instantiated; any IO operation will |
255 // fail while the previous operation is still in-flight. In order to deal with | 256 // fail while the previous operation is still in-flight. In order to deal with |
256 // this requirement, the caller could either wait until the operation | 257 // this requirement, the caller could either wait until the operation |
257 // completes before closing the entry, or call CancelSparseIO() before closing | 258 // completes before closing the entry, or call CancelSparseIO() before closing |
258 // the entry, and call ReadyForSparseIO() on the new entry and wait for the | 259 // the entry, and call ReadyForSparseIO() on the new entry and wait for the |
259 // callback before issuing new operations. | 260 // callback before issuing new operations. |
260 | 261 |
261 // Behaves like ReadData() except that this method is used to access sparse | 262 // Behaves like ReadData() except that this method is used to access sparse |
262 // entries. | 263 // entries. |
263 virtual int ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, | 264 virtual int ReadSparseData(int64_t offset, |
| 265 IOBuffer* buf, |
| 266 int buf_len, |
264 const CompletionCallback& callback) = 0; | 267 const CompletionCallback& callback) = 0; |
265 | 268 |
266 // Behaves like WriteData() except that this method is used to access sparse | 269 // Behaves like WriteData() except that this method is used to access sparse |
267 // entries. |truncate| is not part of this interface because a sparse entry | 270 // entries. |truncate| is not part of this interface because a sparse entry |
268 // is not expected to be reused with new data. To delete the old data and | 271 // is not expected to be reused with new data. To delete the old data and |
269 // start again, or to reduce the total size of the stream data (which implies | 272 // start again, or to reduce the total size of the stream data (which implies |
270 // that the content has changed), the whole entry should be doomed and | 273 // that the content has changed), the whole entry should be doomed and |
271 // re-created. | 274 // re-created. |
272 virtual int WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, | 275 virtual int WriteSparseData(int64_t offset, |
| 276 IOBuffer* buf, |
| 277 int buf_len, |
273 const CompletionCallback& callback) = 0; | 278 const CompletionCallback& callback) = 0; |
274 | 279 |
275 // Returns information about the currently stored portion of a sparse entry. | 280 // Returns information about the currently stored portion of a sparse entry. |
276 // |offset| and |len| describe a particular range that should be scanned to | 281 // |offset| and |len| describe a particular range that should be scanned to |
277 // find out if it is stored or not. |start| will contain the offset of the | 282 // find out if it is stored or not. |start| will contain the offset of the |
278 // first byte that is stored within this range, and the return value is the | 283 // first byte that is stored within this range, and the return value is the |
279 // minimum number of consecutive stored bytes. Note that it is possible that | 284 // minimum number of consecutive stored bytes. Note that it is possible that |
280 // this entry has stored more than the returned value. This method returns a | 285 // this entry has stored more than the returned value. This method returns a |
281 // net error code whenever the request cannot be completed successfully. If | 286 // net error code whenever the request cannot be completed successfully. If |
282 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the | 287 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the |
283 // operation completes, and |start| must remain valid until that point. | 288 // operation completes, and |start| must remain valid until that point. |
284 virtual int GetAvailableRange(int64 offset, int len, int64* start, | 289 virtual int GetAvailableRange(int64_t offset, |
| 290 int len, |
| 291 int64_t* start, |
285 const CompletionCallback& callback) = 0; | 292 const CompletionCallback& callback) = 0; |
286 | 293 |
287 // Returns true if this entry could be a sparse entry or false otherwise. This | 294 // Returns true if this entry could be a sparse entry or false otherwise. This |
288 // is a quick test that may return true even if the entry is not really | 295 // is a quick test that may return true even if the entry is not really |
289 // sparse. This method doesn't modify the state of this entry (it will not | 296 // sparse. This method doesn't modify the state of this entry (it will not |
290 // create sparse tracking data). GetAvailableRange or ReadSparseData can be | 297 // create sparse tracking data). GetAvailableRange or ReadSparseData can be |
291 // used to perform a definitive test of whether an existing entry is sparse or | 298 // used to perform a definitive test of whether an existing entry is sparse or |
292 // not, but that method may modify the current state of the entry (making it | 299 // not, but that method may modify the current state of the entry (making it |
293 // sparse, for instance). The purpose of this method is to test an existing | 300 // sparse, for instance). The purpose of this method is to test an existing |
294 // entry, but without generating actual IO to perform a thorough check. | 301 // entry, but without generating actual IO to perform a thorough check. |
(...skipping 29 matching lines...) Expand all Loading... |
324 entry->Close(); | 331 entry->Close(); |
325 } | 332 } |
326 }; | 333 }; |
327 | 334 |
328 // Automatically closes an entry when it goes out of scope. | 335 // Automatically closes an entry when it goes out of scope. |
329 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; | 336 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; |
330 | 337 |
331 } // namespace disk_cache | 338 } // namespace disk_cache |
332 | 339 |
333 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 340 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
OLD | NEW |