OLD | NEW |
---|---|
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 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 class IOBuffer; | 28 class IOBuffer; |
29 class NetLog; | 29 class NetLog; |
30 } | 30 } |
31 | 31 |
32 namespace disk_cache { | 32 namespace disk_cache { |
33 | 33 |
34 class Entry; | 34 class Entry; |
35 class Backend; | 35 class Backend; |
36 typedef net::OldCompletionCallback OldCompletionCallback; | 36 typedef net::OldCompletionCallback OldCompletionCallback; |
csilv
2011/12/06 00:56:08
(comment-only) I'm trying to decide if this is co
James Hawkins
2011/12/06 17:25:12
It's lame, but removing it now would be a mess.
| |
37 | 37 |
38 // Returns an instance of a Backend of the given |type|. |path| points to a | 38 // Returns an instance of a Backend of the given |type|. |path| points to a |
39 // folder where the cached data will be stored (if appropriate). This cache | 39 // folder where the cached data will be stored (if appropriate). This cache |
40 // instance must be the only object that will be reading or writing files to | 40 // instance must be the only object that will be reading or writing files to |
41 // that folder. The returned object should be deleted when not needed anymore. | 41 // that folder. The returned object should be deleted when not needed anymore. |
42 // If |force| is true, and there is a problem with the cache initialization, the | 42 // If |force| is true, and there is a problem with the cache initialization, the |
43 // files will be deleted and a new set will be created. |max_bytes| is the | 43 // files will be deleted and a new set will be created. |max_bytes| is the |
44 // maximum size the cache can grow to. If zero is passed in as |max_bytes|, the | 44 // maximum size the cache can grow to. If zero is passed in as |max_bytes|, the |
45 // cache will determine the value to use. |thread| can be used to perform IO | 45 // cache will determine the value to use. |thread| can be used to perform IO |
46 // operations if a dedicated thread is required; a valid value is expected for | 46 // operations if a dedicated thread is required; a valid value is expected for |
(...skipping 24 matching lines...) Expand all Loading... | |
71 virtual int32 GetEntryCount() const = 0; | 71 virtual int32 GetEntryCount() const = 0; |
72 | 72 |
73 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry | 73 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry |
74 // object representing the specified disk cache entry. When the entry pointer | 74 // object representing the specified disk cache entry. When the entry pointer |
75 // is no longer needed, its Close method should be called. The return value is | 75 // is no longer needed, its Close method should be called. The return value is |
76 // a net error code. If this method returns ERR_IO_PENDING, the |callback| | 76 // a net error code. If this method returns ERR_IO_PENDING, the |callback| |
77 // will be invoked when the entry is available. The pointer to receive the | 77 // will be invoked when the entry is available. The pointer to receive the |
78 // |entry| must remain valid until the operation completes. | 78 // |entry| must remain valid until the operation completes. |
79 virtual int OpenEntry(const std::string& key, Entry** entry, | 79 virtual int OpenEntry(const std::string& key, Entry** entry, |
80 OldCompletionCallback* callback) = 0; | 80 OldCompletionCallback* callback) = 0; |
81 virtual int OpenEntry(const std::string& key, Entry** entry, | |
82 const net::CompletionCallback& callback) = 0; | |
81 | 83 |
82 // Creates a new entry. Upon success, the out param holds a pointer to an | 84 // Creates a new entry. Upon success, the out param holds a pointer to an |
83 // Entry object representing the newly created disk cache entry. When the | 85 // Entry object representing the newly created disk cache entry. When the |
84 // entry pointer is no longer needed, its Close method should be called. The | 86 // entry pointer is no longer needed, its Close method should be called. The |
85 // return value is a net error code. If this method returns ERR_IO_PENDING, | 87 // return value is a net error code. If this method returns ERR_IO_PENDING, |
86 // the |callback| will be invoked when the entry is available. The pointer to | 88 // the |callback| will be invoked when the entry is available. The pointer to |
87 // receive the |entry| must remain valid until the operation completes. | 89 // receive the |entry| must remain valid until the operation completes. |
88 virtual int CreateEntry(const std::string& key, Entry** entry, | 90 virtual int CreateEntry(const std::string& key, Entry** entry, |
89 OldCompletionCallback* callback) = 0; | 91 OldCompletionCallback* callback) = 0; |
92 virtual int CreateEntry(const std::string& key, Entry** entry, | |
93 const net::CompletionCallback& callback) = 0; | |
90 | 94 |
91 // Marks the entry, specified by the given key, for deletion. The return value | 95 // Marks the entry, specified by the given key, for deletion. The return value |
92 // is a net error code. If this method returns ERR_IO_PENDING, the |callback| | 96 // is a net error code. If this method returns ERR_IO_PENDING, the |callback| |
93 // will be invoked after the entry is doomed. | 97 // will be invoked after the entry is doomed. |
94 virtual int DoomEntry(const std::string& key, | 98 virtual int DoomEntry(const std::string& key, |
95 OldCompletionCallback* callback) = 0; | 99 OldCompletionCallback* callback) = 0; |
96 | 100 |
97 // Marks all entries for deletion. The return value is a net error code. If | 101 // Marks all entries for deletion. The return value is a net error code. If |
98 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the | 102 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the |
99 // operation completes. | 103 // operation completes. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 // called on the current thread once the read completes. Returns the | 176 // called on the current thread once the read completes. Returns the |
173 // 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 |
174 // 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, |
175 // 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. |
176 // 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 |
177 // 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 |
178 // 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 |
179 // performed from the callback code. | 183 // performed from the callback code. |
180 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, | 184 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, |
181 OldCompletionCallback* completion_callback) = 0; | 185 OldCompletionCallback* completion_callback) = 0; |
186 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, | |
187 const net::CompletionCallback& completion_callback) = 0; | |
182 | 188 |
183 // Copies cache data from the given buffer of length |buf_len|. If | 189 // Copies cache data from the given buffer of length |buf_len|. If |
184 // completion_callback is null, then this call blocks until the write | 190 // completion_callback is null, then this call blocks until the write |
185 // operation is complete. Otherwise, completion_callback will be | 191 // operation is complete. Otherwise, completion_callback will be |
186 // called on the current thread once the write completes. Returns the | 192 // called on the current thread once the write completes. Returns the |
187 // number of bytes written or a network error code. If a completion callback | 193 // number of bytes written or a network error code. If a completion callback |
188 // is provided then it will be called if this function returns ERR_IO_PENDING, | 194 // is provided then it will be called if this function returns ERR_IO_PENDING, |
189 // and a reference to |buf| will be retained until the callback is called. | 195 // and a reference to |buf| will be retained until the callback is called. |
190 // Note that the callback will be invoked in any case, even after Close has | 196 // Note that the callback will be invoked in any case, even after Close has |
191 // been called; in other words, the caller may close this entry without | 197 // been called; in other words, the caller may close this entry without |
192 // having to wait for all the callbacks, and still rely on the cleanup | 198 // having to wait for all the callbacks, and still rely on the cleanup |
193 // performed from the callback code. | 199 // performed from the callback code. |
194 // If truncate is true, this call will truncate the stored data at the end of | 200 // If truncate is true, this call will truncate the stored data at the end of |
195 // what we are writing here. | 201 // what we are writing here. |
196 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | 202 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
197 OldCompletionCallback* completion_callback, | 203 OldCompletionCallback* completion_callback, |
198 bool truncate) = 0; | 204 bool truncate) = 0; |
205 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | |
206 const net::CompletionCallback& completion_callback, | |
207 bool truncate) = 0; | |
199 | 208 |
200 // Sparse entries support: | 209 // Sparse entries support: |
201 // | 210 // |
202 // A Backend implementation can support sparse entries, so the cache keeps | 211 // A Backend implementation can support sparse entries, so the cache keeps |
203 // track of which parts of the entry have been written before. The backend | 212 // track of which parts of the entry have been written before. The backend |
204 // will never return data that was not written previously, so reading from | 213 // will never return data that was not written previously, so reading from |
205 // such region will return 0 bytes read (or actually the number of bytes read | 214 // such region will return 0 bytes read (or actually the number of bytes read |
206 // before reaching that region). | 215 // before reaching that region). |
207 // | 216 // |
208 // There are only two streams for sparse entries: a regular control stream | 217 // There are only two streams for sparse entries: a regular control stream |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 // Note: This method is deprecated. | 304 // Note: This method is deprecated. |
296 virtual int ReadyForSparseIO(OldCompletionCallback* completion_callback) = 0; | 305 virtual int ReadyForSparseIO(OldCompletionCallback* completion_callback) = 0; |
297 | 306 |
298 protected: | 307 protected: |
299 virtual ~Entry() {} | 308 virtual ~Entry() {} |
300 }; | 309 }; |
301 | 310 |
302 } // namespace disk_cache | 311 } // namespace disk_cache |
303 | 312 |
304 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 313 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
OLD | NEW |