Chromium Code Reviews| 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 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 int max_bytes, | 64 int max_bytes, |
| 65 bool force, | 65 bool force, |
| 66 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | 66 const scoped_refptr<base::SingleThreadTaskRunner>& thread, |
| 67 net::NetLog* net_log, | 67 net::NetLog* net_log, |
| 68 std::unique_ptr<Backend>* backend, | 68 std::unique_ptr<Backend>* backend, |
| 69 const net::CompletionCallback& callback); | 69 const net::CompletionCallback& callback); |
| 70 | 70 |
| 71 // The root interface for a disk cache instance. | 71 // The root interface for a disk cache instance. |
| 72 class NET_EXPORT Backend { | 72 class NET_EXPORT Backend { |
| 73 public: | 73 public: |
| 74 enum class OracleJudgement { HIT, MISS_AND_DOOM }; | |
| 75 | |
| 74 typedef net::CompletionCallback CompletionCallback; | 76 typedef net::CompletionCallback CompletionCallback; |
| 77 typedef base::Callback<OracleJudgement(uint8_t)> OracleCallback; | |
| 75 | 78 |
| 76 class Iterator { | 79 class Iterator { |
| 77 public: | 80 public: |
| 78 virtual ~Iterator() {} | 81 virtual ~Iterator() {} |
| 79 | 82 |
| 80 // OpenNextEntry returns |net::OK| and provides |next_entry| if there is an | 83 // OpenNextEntry returns |net::OK| and provides |next_entry| if there is an |
| 81 // entry to enumerate. It returns |net::ERR_FAILED| at the end of | 84 // entry to enumerate. It returns |net::ERR_FAILED| at the end of |
| 82 // enumeration. If the function returns |net::ERR_IO_PENDING|, then the | 85 // enumeration. If the function returns |net::ERR_IO_PENDING|, then the |
| 83 // final result will be passed to the provided |callback|, otherwise | 86 // final result will be passed to the provided |callback|, otherwise |
| 84 // |callback| will not be called. If any entry in the cache is modified | 87 // |callback| will not be called. If any entry in the cache is modified |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 109 | 112 |
| 110 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry | 113 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry |
| 111 // object representing the specified disk cache entry. When the entry pointer | 114 // object representing the specified disk cache entry. When the entry pointer |
| 112 // is no longer needed, its Close method should be called. The return value is | 115 // is no longer needed, its Close method should be called. The return value is |
| 113 // a net error code. If this method returns ERR_IO_PENDING, the |callback| | 116 // a net error code. If this method returns ERR_IO_PENDING, the |callback| |
| 114 // will be invoked when the entry is available. The pointer to receive the | 117 // will be invoked when the entry is available. The pointer to receive the |
| 115 // |entry| must remain valid until the operation completes. | 118 // |entry| must remain valid until the operation completes. |
| 116 virtual int OpenEntry(const std::string& key, Entry** entry, | 119 virtual int OpenEntry(const std::string& key, Entry** entry, |
| 117 const CompletionCallback& callback) = 0; | 120 const CompletionCallback& callback) = 0; |
| 118 | 121 |
| 122 // This is a variant of above, which can give the client a chance to quickly | |
| 123 // invalidate the entry w/o fully opening it, by taking a look at a byte | |
| 124 // it has previously passed to Entry::SetOracleByte inside |oracle|. | |
| 125 // | |
| 126 // Default implementation just delegates to OpenEntry. | |
| 127 virtual int OpenEntryWithOracleByte(const std::string& key, | |
|
jkarlin
2017/06/07 20:01:54
I'd rather we have a more general purpose byte in
jkarlin
2017/06/07 20:04:44
Ah, this will have to be an async call won't it be
| |
| 128 Entry** entry, | |
| 129 const OracleCallback& oracle, | |
| 130 const CompletionCallback& callback); | |
| 131 | |
| 119 // Creates a new entry. Upon success, the out param holds a pointer to an | 132 // Creates a new entry. Upon success, the out param holds a pointer to an |
| 120 // Entry object representing the newly created disk cache entry. When the | 133 // Entry object representing the newly created disk cache entry. When the |
| 121 // entry pointer is no longer needed, its Close method should be called. The | 134 // entry pointer is no longer needed, its Close method should be called. The |
| 122 // return value is a net error code. If this method returns ERR_IO_PENDING, | 135 // return value is a net error code. If this method returns ERR_IO_PENDING, |
| 123 // the |callback| will be invoked when the entry is available. The pointer to | 136 // the |callback| will be invoked when the entry is available. The pointer to |
| 124 // receive the |entry| must remain valid until the operation completes. | 137 // receive the |entry| must remain valid until the operation completes. |
| 125 virtual int CreateEntry(const std::string& key, Entry** entry, | 138 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 126 const CompletionCallback& callback) = 0; | 139 const CompletionCallback& callback) = 0; |
| 127 | 140 |
| 128 // Marks the entry, specified by the given key, for deletion. The return value | 141 // Marks the entry, specified by the given key, for deletion. The return value |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 | 218 |
| 206 // Returns the time when this cache entry was last used. | 219 // Returns the time when this cache entry was last used. |
| 207 virtual base::Time GetLastUsed() const = 0; | 220 virtual base::Time GetLastUsed() const = 0; |
| 208 | 221 |
| 209 // Returns the time when this cache entry was last modified. | 222 // Returns the time when this cache entry was last modified. |
| 210 virtual base::Time GetLastModified() const = 0; | 223 virtual base::Time GetLastModified() const = 0; |
| 211 | 224 |
| 212 // Returns the size of the cache data with the given index. | 225 // Returns the size of the cache data with the given index. |
| 213 virtual int32_t GetDataSize(int index) const = 0; | 226 virtual int32_t GetDataSize(int index) const = 0; |
| 214 | 227 |
| 228 // If supported by the backend, stores a byte associated with this entry in a | |
| 229 // way that can be accessed efficiently by OpenEntryWithOracleByte (before | |
| 230 // opening the whole entry). | |
| 231 // TBD non-zero, blah blah. | |
| 232 // TBD. | |
| 233 // | |
| 234 // Default implementation does nothing. | |
| 235 virtual void SetOracleByte(uint8_t); | |
| 236 | |
| 215 // Copies cached data into the given buffer of length |buf_len|. Returns the | 237 // Copies cached data into the given buffer of length |buf_len|. Returns the |
| 216 // number of bytes read or a network error code. If this function returns | 238 // number of bytes read or a network error code. If this function returns |
| 217 // ERR_IO_PENDING, the completion callback will be called on the current | 239 // ERR_IO_PENDING, the completion callback will be called on the current |
| 218 // thread when the operation completes, and a reference to |buf| will be | 240 // thread when the operation completes, and a reference to |buf| will be |
| 219 // retained until the callback is called. Note that as long as the function | 241 // retained until the callback is called. Note that as long as the function |
| 220 // does not complete immediately, the callback will always be invoked, even | 242 // does not complete immediately, the callback will always be invoked, even |
| 221 // after Close has been called; in other words, the caller may close this | 243 // after Close has been called; in other words, the caller may close this |
| 222 // entry without having to wait for all the callbacks, and still rely on the | 244 // entry without having to wait for all the callbacks, and still rely on the |
| 223 // cleanup performed from the callback code. | 245 // cleanup performed from the callback code. |
| 224 virtual int ReadData(int index, int offset, IOBuffer* buf, int buf_len, | 246 virtual int ReadData(int index, int offset, IOBuffer* buf, int buf_len, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 entry->Close(); | 375 entry->Close(); |
| 354 } | 376 } |
| 355 }; | 377 }; |
| 356 | 378 |
| 357 // Automatically closes an entry when it goes out of scope. | 379 // Automatically closes an entry when it goes out of scope. |
| 358 typedef std::unique_ptr<Entry, EntryDeleter> ScopedEntryPtr; | 380 typedef std::unique_ptr<Entry, EntryDeleter> ScopedEntryPtr; |
| 359 | 381 |
| 360 } // namespace disk_cache | 382 } // namespace disk_cache |
| 361 | 383 |
| 362 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 384 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
| OLD | NEW |