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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Note that the callback will be invoked in any case, even after Close has | 147 // Note that the callback will be invoked in any case, even after Close has |
148 // been called; in other words, the caller may close this entry without | 148 // been called; in other words, the caller may close this entry without |
149 // having to wait for all the callbacks, and still rely on the cleanup | 149 // having to wait for all the callbacks, and still rely on the cleanup |
150 // performed from the callback code. | 150 // performed from the callback code. |
151 // If truncate is true, this call will truncate the stored data at the end of | 151 // If truncate is true, this call will truncate the stored data at the end of |
152 // what we are writing here. | 152 // what we are writing here. |
153 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | 153 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
154 net::CompletionCallback* completion_callback, | 154 net::CompletionCallback* completion_callback, |
155 bool truncate) = 0; | 155 bool truncate) = 0; |
156 | 156 |
| 157 // Sparse entries support: |
| 158 // |
| 159 // A Backend implementation can support sparse entries, so the cache keeps |
| 160 // track of which parts of the entry have been written before. The backend |
| 161 // will never return data that was not written previously, so reading from |
| 162 // such region will return 0 bytes read (or actually the number of bytes read |
| 163 // before reaching that region). |
| 164 // |
| 165 // There are only two streams for sparse entries: a regular control stream |
| 166 // (index 0) that must be accessed through the regular API (ReadData and |
| 167 // WriteData), and one sparse stream that must me accessed through the sparse- |
| 168 // aware API that follows. Calling a non-sparse aware method with an index |
| 169 // argument other than 0 is a mistake that results in implementation specific |
| 170 // behavior. Using a sparse-aware method with an entry that was not stored |
| 171 // using the same API, or with a backend that doesn't support sparse entries |
| 172 // will return ERR_CACHE_INVALID_REQUEST. |
| 173 // |
| 174 // The storage granularity of the implementation should be at least 1 KB. In |
| 175 // other words, storing less than 1 KB may result in an implementation |
| 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 |
| 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 |
| 180 // (the second one starts where the first one ended), and there is no other |
| 181 // write between them. |
| 182 // |
| 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 |
| 185 // as bad as it sounds. |
| 186 |
| 187 // Behaves like ReadData() except that this method is used to access sparse |
| 188 // entries. |
| 189 virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
| 190 net::CompletionCallback* completion_callback) = 0; |
| 191 |
| 192 // 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 |
| 194 // 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 |
| 196 // that the content has changed), the whole entry should be doomed and |
| 197 // re-created. |
| 198 virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
| 199 net::CompletionCallback* completion_callback) = 0; |
| 200 |
| 201 // Returns information about the currently stored portion of a sparse entry. |
| 202 // |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 |
| 204 // 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 |
| 206 // this entry has stored more than the returned value. This method returns a |
| 207 // net error code whenever the request cannot be completed successfully. |
| 208 virtual int GetAvailableRange(int64 offset, int len, int64* start) = 0; |
| 209 |
157 protected: | 210 protected: |
158 virtual ~Entry() {} | 211 virtual ~Entry() {} |
159 }; | 212 }; |
160 | 213 |
161 } // namespace disk_cache | 214 } // namespace disk_cache |
162 | 215 |
163 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 216 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
OLD | NEW |