OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/disk-cache | 6 // http://dev.chromium.org/developers/design-documents/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 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // dropping the data completely, and writing at offsets not aligned with 1 KB, | 176 // dropping the data completely, and writing at offsets not aligned with 1 KB, |
177 // or with lengths not a multiple of 1 KB may result in the first or last part | 177 // or with lengths not a multiple of 1 KB may result in the first or last part |
178 // of the data being discarded. However, two consecutive writes should not | 178 // of the data being discarded. However, two consecutive writes should not |
179 // result in a hole in between the two parts as long as they are sequential | 179 // result in a hole in between the two parts as long as they are sequential |
180 // (the second one starts where the first one ended), and there is no other | 180 // (the second one starts where the first one ended), and there is no other |
181 // write between them. | 181 // write between them. |
182 // | 182 // |
183 // The Backend implementation is free to evict any range from the cache at any | 183 // The Backend implementation is free to evict any range from the cache at any |
184 // moment, so in practice, the previously stated granularity of 1 KB is not | 184 // moment, so in practice, the previously stated granularity of 1 KB is not |
185 // as bad as it sounds. | 185 // as bad as it sounds. |
| 186 // |
| 187 // The sparse methods don't support multiple simultaneous IO operations to the |
| 188 // same physical entry, so in practice a single object should be instantiated |
| 189 // for a given key at any given time. Once an operation has been issued, the |
| 190 // caller should wait until it completes before starting another one. This |
| 191 // requirement includes the case when an entry is closed while some operation |
| 192 // is in progress and another object is instantiated; any IO operation will |
| 193 // fail while the previous operation is still in-flight. In order to deal with |
| 194 // this requirement, the caller could either wait until the operation |
| 195 // completes before closing the entry, or call CancelSparseIO() before closing |
| 196 // the entry, and call ReadyForSparseIO() on the new entry and wait for the |
| 197 // callback before issuing new operations. |
186 | 198 |
187 // Behaves like ReadData() except that this method is used to access sparse | 199 // Behaves like ReadData() except that this method is used to access sparse |
188 // entries. | 200 // entries. |
189 virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, | 201 virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
190 net::CompletionCallback* completion_callback) = 0; | 202 net::CompletionCallback* completion_callback) = 0; |
191 | 203 |
192 // Behaves like WriteData() except that this method is used to access sparse | 204 // Behaves like WriteData() except that this method is used to access sparse |
193 // entries. |truncate| is not part of this interface because a sparse entry | 205 // entries. |truncate| is not part of this interface because a sparse entry |
194 // is not expected to be reused with new data. To delete the old data and | 206 // is not expected to be reused with new data. To delete the old data and |
195 // start again, or to reduce the total size of the stream data (which implies | 207 // start again, or to reduce the total size of the stream data (which implies |
196 // that the content has changed), the whole entry should be doomed and | 208 // that the content has changed), the whole entry should be doomed and |
197 // re-created. | 209 // re-created. |
198 virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, | 210 virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
199 net::CompletionCallback* completion_callback) = 0; | 211 net::CompletionCallback* completion_callback) = 0; |
200 | 212 |
201 // Returns information about the currently stored portion of a sparse entry. | 213 // Returns information about the currently stored portion of a sparse entry. |
202 // |offset| and |len| describe a particular range that should be scanned to | 214 // |offset| and |len| describe a particular range that should be scanned to |
203 // find out if it is stored or not. |start| will contain the offset of the | 215 // find out if it is stored or not. |start| will contain the offset of the |
204 // first byte that is stored within this range, and the return value is the | 216 // first byte that is stored within this range, and the return value is the |
205 // minimum number of consecutive stored bytes. Note that it is possible that | 217 // minimum number of consecutive stored bytes. Note that it is possible that |
206 // this entry has stored more than the returned value. This method returns a | 218 // this entry has stored more than the returned value. This method returns a |
207 // net error code whenever the request cannot be completed successfully. | 219 // net error code whenever the request cannot be completed successfully. |
208 virtual int GetAvailableRange(int64 offset, int len, int64* start) = 0; | 220 virtual int GetAvailableRange(int64 offset, int len, int64* start) = 0; |
209 | 221 |
| 222 // Cancels any pending sparse IO operation (if any). The completion callback |
| 223 // of the operation in question will still be called when the operation |
| 224 // finishes, but the operation will finish sooner when this method is used. |
| 225 virtual void CancelSparseIO() = 0; |
| 226 |
| 227 // Returns OK if this entry can be used immediately. If that is not the |
| 228 // case, returns ERR_IO_PENDING and invokes the provided callback when this |
| 229 // entry is ready to use. This method always returns OK for non-sparse |
| 230 // entries, and returns ERR_IO_PENDING when a previous operation was cancelled |
| 231 // (by calling CancelSparseIO), but the cache is still busy with it. If there |
| 232 // is a pending operation that has not been cancelled, this method will return |
| 233 // OK although another IO operation cannot be issued at this time; in this |
| 234 // case the caller should just wait for the regular callback to be invoked |
| 235 // instead of using this method to provide another callback. |
| 236 // |
| 237 // Note that CancelSparseIO may have been called on another instance of this |
| 238 // object that refers to the same physical disk entry. |
| 239 virtual int ReadyForSparseIO( |
| 240 net::CompletionCallback* completion_callback) = 0; |
| 241 |
210 protected: | 242 protected: |
211 virtual ~Entry() {} | 243 virtual ~Entry() {} |
212 }; | 244 }; |
213 | 245 |
214 } // namespace disk_cache | 246 } // namespace disk_cache |
215 | 247 |
216 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 248 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
OLD | NEW |