| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after 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; | |
| 83 | 81 |
| 84 // Creates a new entry. Upon success, the out param holds a pointer to an | 82 // Creates a new entry. Upon success, the out param holds a pointer to an |
| 85 // Entry object representing the newly created disk cache entry. When the | 83 // Entry object representing the newly created disk cache entry. When the |
| 86 // entry pointer is no longer needed, its Close method should be called. The | 84 // entry pointer is no longer needed, its Close method should be called. The |
| 87 // return value is a net error code. If this method returns ERR_IO_PENDING, | 85 // return value is a net error code. If this method returns ERR_IO_PENDING, |
| 88 // the |callback| will be invoked when the entry is available. The pointer to | 86 // the |callback| will be invoked when the entry is available. The pointer to |
| 89 // receive the |entry| must remain valid until the operation completes. | 87 // receive the |entry| must remain valid until the operation completes. |
| 90 virtual int CreateEntry(const std::string& key, Entry** entry, | 88 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 91 OldCompletionCallback* callback) = 0; | 89 OldCompletionCallback* callback) = 0; |
| 92 virtual int CreateEntry(const std::string& key, Entry** entry, | |
| 93 const net::CompletionCallback& callback) = 0; | |
| 94 | 90 |
| 95 // Marks the entry, specified by the given key, for deletion. The return value | 91 // Marks the entry, specified by the given key, for deletion. The return value |
| 96 // is a net error code. If this method returns ERR_IO_PENDING, the |callback| | 92 // is a net error code. If this method returns ERR_IO_PENDING, the |callback| |
| 97 // will be invoked after the entry is doomed. | 93 // will be invoked after the entry is doomed. |
| 98 virtual int DoomEntry(const std::string& key, | 94 virtual int DoomEntry(const std::string& key, |
| 99 OldCompletionCallback* callback) = 0; | 95 OldCompletionCallback* callback) = 0; |
| 100 | 96 |
| 101 // Marks all entries for deletion. The return value is a net error code. If | 97 // Marks all entries for deletion. The return value is a net error code. If |
| 102 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the | 98 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the |
| 103 // operation completes. | 99 // operation completes. |
| 104 virtual int DoomAllEntries(OldCompletionCallback* callback) = 0; | 100 virtual int DoomAllEntries(OldCompletionCallback* callback) = 0; |
| 105 virtual int DoomAllEntries(const net::CompletionCallback& callback) = 0; | |
| 106 | 101 |
| 107 // Marks a range of entries for deletion. This supports unbounded deletes in | 102 // Marks a range of entries for deletion. This supports unbounded deletes in |
| 108 // either direction by using null Time values for either argument. The return | 103 // either direction by using null Time values for either argument. The return |
| 109 // value is a net error code. If this method returns ERR_IO_PENDING, the | 104 // value is a net error code. If this method returns ERR_IO_PENDING, the |
| 110 // |callback| will be invoked when the operation completes. | 105 // |callback| will be invoked when the operation completes. |
| 111 virtual int DoomEntriesBetween(const base::Time initial_time, | 106 virtual int DoomEntriesBetween(const base::Time initial_time, |
| 112 const base::Time end_time, | 107 const base::Time end_time, |
| 113 OldCompletionCallback* callback) = 0; | 108 OldCompletionCallback* callback) = 0; |
| 114 virtual int DoomEntriesBetween(const base::Time initial_time, | |
| 115 const base::Time end_time, | |
| 116 const net::CompletionCallback& callback) = 0; | |
| 117 | 109 |
| 118 // Marks all entries accessed since |initial_time| for deletion. The return | 110 // Marks all entries accessed since |initial_time| for deletion. The return |
| 119 // value is a net error code. If this method returns ERR_IO_PENDING, the | 111 // value is a net error code. If this method returns ERR_IO_PENDING, the |
| 120 // |callback| will be invoked when the operation completes. | 112 // |callback| will be invoked when the operation completes. |
| 121 virtual int DoomEntriesSince(const base::Time initial_time, | 113 virtual int DoomEntriesSince(const base::Time initial_time, |
| 122 OldCompletionCallback* callback) = 0; | 114 OldCompletionCallback* callback) = 0; |
| 123 | 115 |
| 124 // Enumerates the cache. Initialize |iter| to NULL before calling this method | 116 // Enumerates the cache. Initialize |iter| to NULL before calling this method |
| 125 // the first time. That will cause the enumeration to start at the head of | 117 // the first time. That will cause the enumeration to start at the head of |
| 126 // the cache. For subsequent calls, pass the same |iter| pointer again without | 118 // the cache. For subsequent calls, pass the same |iter| pointer again without |
| 127 // changing its value. This method returns ERR_FAILED when there are no more | 119 // changing its value. This method returns ERR_FAILED when there are no more |
| 128 // entries to enumerate. When the entry pointer is no longer needed, its | 120 // entries to enumerate. When the entry pointer is no longer needed, its |
| 129 // Close method should be called. The return value is a net error code. If | 121 // Close method should be called. The return value is a net error code. If |
| 130 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the | 122 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the |
| 131 // |next_entry| is available. The pointer to receive the |next_entry| must | 123 // |next_entry| is available. The pointer to receive the |next_entry| must |
| 132 // remain valid until the operation completes. | 124 // remain valid until the operation completes. |
| 133 // | 125 // |
| 134 // NOTE: This method does not modify the last_used field of the entry, and | 126 // NOTE: This method does not modify the last_used field of the entry, and |
| 135 // therefore it does not impact the eviction ranking of the entry. | 127 // therefore it does not impact the eviction ranking of the entry. |
| 136 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 128 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
| 137 OldCompletionCallback* callback) = 0; | 129 OldCompletionCallback* callback) = 0; |
| 138 virtual int OpenNextEntry(void** iter, Entry** next_entry, | |
| 139 const net::CompletionCallback& callback) = 0; | |
| 140 | 130 |
| 141 // Releases iter without returning the next entry. Whenever OpenNextEntry() | 131 // Releases iter without returning the next entry. Whenever OpenNextEntry() |
| 142 // returns true, but the caller is not interested in continuing the | 132 // returns true, but the caller is not interested in continuing the |
| 143 // enumeration by calling OpenNextEntry() again, the enumeration must be | 133 // enumeration by calling OpenNextEntry() again, the enumeration must be |
| 144 // ended by calling this method with iter returned by OpenNextEntry(). | 134 // ended by calling this method with iter returned by OpenNextEntry(). |
| 145 virtual void EndEnumeration(void** iter) = 0; | 135 virtual void EndEnumeration(void** iter) = 0; |
| 146 | 136 |
| 147 // Return a list of cache statistics. | 137 // Return a list of cache statistics. |
| 148 virtual void GetStats( | 138 virtual void GetStats( |
| 149 std::vector<std::pair<std::string, std::string> >* stats) = 0; | 139 std::vector<std::pair<std::string, std::string> >* stats) = 0; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // called on the current thread once the read completes. Returns the | 172 // called on the current thread once the read completes. Returns the |
| 183 // number of bytes read or a network error code. If a completion callback is | 173 // number of bytes read or a network error code. If a completion callback is |
| 184 // provided then it will be called if this function returns ERR_IO_PENDING, | 174 // provided then it will be called if this function returns ERR_IO_PENDING, |
| 185 // and a reference to |buf| will be retained until the callback is called. | 175 // and a reference to |buf| will be retained until the callback is called. |
| 186 // Note that the callback will be invoked in any case, even after Close has | 176 // Note that the callback will be invoked in any case, even after Close has |
| 187 // been called; in other words, the caller may close this entry without | 177 // been called; in other words, the caller may close this entry without |
| 188 // having to wait for all the callbacks, and still rely on the cleanup | 178 // having to wait for all the callbacks, and still rely on the cleanup |
| 189 // performed from the callback code. | 179 // performed from the callback code. |
| 190 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, | 180 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, |
| 191 OldCompletionCallback* completion_callback) = 0; | 181 OldCompletionCallback* completion_callback) = 0; |
| 192 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, | |
| 193 const net::CompletionCallback& completion_callback) = 0; | |
| 194 | 182 |
| 195 // Copies cache data from the given buffer of length |buf_len|. If | 183 // Copies cache data from the given buffer of length |buf_len|. If |
| 196 // completion_callback is null, then this call blocks until the write | 184 // completion_callback is null, then this call blocks until the write |
| 197 // operation is complete. Otherwise, completion_callback will be | 185 // operation is complete. Otherwise, completion_callback will be |
| 198 // called on the current thread once the write completes. Returns the | 186 // called on the current thread once the write completes. Returns the |
| 199 // number of bytes written or a network error code. If a completion callback | 187 // number of bytes written or a network error code. If a completion callback |
| 200 // is provided then it will be called if this function returns ERR_IO_PENDING, | 188 // is provided then it will be called if this function returns ERR_IO_PENDING, |
| 201 // and a reference to |buf| will be retained until the callback is called. | 189 // and a reference to |buf| will be retained until the callback is called. |
| 202 // Note that the callback will be invoked in any case, even after Close has | 190 // Note that the callback will be invoked in any case, even after Close has |
| 203 // been called; in other words, the caller may close this entry without | 191 // been called; in other words, the caller may close this entry without |
| 204 // having to wait for all the callbacks, and still rely on the cleanup | 192 // having to wait for all the callbacks, and still rely on the cleanup |
| 205 // performed from the callback code. | 193 // performed from the callback code. |
| 206 // If truncate is true, this call will truncate the stored data at the end of | 194 // If truncate is true, this call will truncate the stored data at the end of |
| 207 // what we are writing here. | 195 // what we are writing here. |
| 208 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | 196 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
| 209 OldCompletionCallback* completion_callback, | 197 OldCompletionCallback* completion_callback, |
| 210 bool truncate) = 0; | 198 bool truncate) = 0; |
| 211 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | |
| 212 const net::CompletionCallback& completion_callback, | |
| 213 bool truncate) = 0; | |
| 214 | 199 |
| 215 // Sparse entries support: | 200 // Sparse entries support: |
| 216 // | 201 // |
| 217 // A Backend implementation can support sparse entries, so the cache keeps | 202 // A Backend implementation can support sparse entries, so the cache keeps |
| 218 // track of which parts of the entry have been written before. The backend | 203 // track of which parts of the entry have been written before. The backend |
| 219 // will never return data that was not written previously, so reading from | 204 // will never return data that was not written previously, so reading from |
| 220 // such region will return 0 bytes read (or actually the number of bytes read | 205 // such region will return 0 bytes read (or actually the number of bytes read |
| 221 // before reaching that region). | 206 // before reaching that region). |
| 222 // | 207 // |
| 223 // There are only two streams for sparse entries: a regular control stream | 208 // 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... |
| 310 // Note: This method is deprecated. | 295 // Note: This method is deprecated. |
| 311 virtual int ReadyForSparseIO(OldCompletionCallback* completion_callback) = 0; | 296 virtual int ReadyForSparseIO(OldCompletionCallback* completion_callback) = 0; |
| 312 | 297 |
| 313 protected: | 298 protected: |
| 314 virtual ~Entry() {} | 299 virtual ~Entry() {} |
| 315 }; | 300 }; |
| 316 | 301 |
| 317 } // namespace disk_cache | 302 } // namespace disk_cache |
| 318 | 303 |
| 319 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 304 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
| OLD | NEW |