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 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "net/base/cache_type.h" | 18 #include "net/base/cache_type.h" |
| 18 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
| 19 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class FilePath; | 23 class FilePath; |
| 23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 24 } | 25 } |
| 25 | 26 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 55 int max_bytes, | 56 int max_bytes, |
| 56 bool force, | 57 bool force, |
| 57 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | 58 const scoped_refptr<base::SingleThreadTaskRunner>& thread, |
| 58 net::NetLog* net_log, | 59 net::NetLog* net_log, |
| 59 scoped_ptr<Backend>* backend, | 60 scoped_ptr<Backend>* backend, |
| 60 const net::CompletionCallback& callback); | 61 const net::CompletionCallback& callback); |
| 61 | 62 |
| 62 // The root interface for a disk cache instance. | 63 // The root interface for a disk cache instance. |
| 63 class NET_EXPORT Backend { | 64 class NET_EXPORT Backend { |
| 64 public: | 65 public: |
| 66 class EnumerationState { | |
| 67 public: | |
| 68 virtual ~EnumerationState() = 0; | |
| 69 }; | |
| 70 typedef scoped_ptr<EnumerationState> Iterator; | |
|
rvargas (doing something else)
2014/09/05 02:01:29
I don't think we need (or want) an extra typedef t
gavinp
2014/09/11 23:57:04
The latest upload removes the typedef.
| |
| 65 typedef net::CompletionCallback CompletionCallback; | 71 typedef net::CompletionCallback CompletionCallback; |
| 66 | 72 |
| 67 // If the backend is destroyed when there are operations in progress (any | 73 // If the backend is destroyed when there are operations in progress (any |
| 68 // callback that has not been invoked yet), this method cancels said | 74 // callback that has not been invoked yet), this method cancels said |
| 69 // operations so the callbacks are not invoked, possibly leaving the work | 75 // operations so the callbacks are not invoked, possibly leaving the work |
| 70 // half way (for instance, dooming just a few entries). Note that pending IO | 76 // half way (for instance, dooming just a few entries). Note that pending IO |
| 71 // for a given Entry (as opposed to the Backend) will still generate a | 77 // for a given Entry (as opposed to the Backend) will still generate a |
| 72 // callback from within this method. | 78 // callback from within this method. |
| 73 virtual ~Backend() {} | 79 virtual ~Backend(); |
| 74 | 80 |
| 75 // Returns the type of this cache. | 81 // Returns the type of this cache. |
| 76 virtual net::CacheType GetCacheType() const = 0; | 82 virtual net::CacheType GetCacheType() const = 0; |
| 77 | 83 |
| 78 // Returns the number of entries in the cache. | 84 // Returns the number of entries in the cache. |
| 79 virtual int32 GetEntryCount() const = 0; | 85 virtual int32 GetEntryCount() const = 0; |
| 80 | 86 |
| 81 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry | 87 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry |
| 82 // object representing the specified disk cache entry. When the entry pointer | 88 // object representing the specified disk cache entry. When the entry pointer |
| 83 // is no longer needed, its Close method should be called. The return value is | 89 // is no longer needed, its Close method should be called. The return value is |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 base::Time end_time, | 122 base::Time end_time, |
| 117 const CompletionCallback& callback) = 0; | 123 const CompletionCallback& callback) = 0; |
| 118 | 124 |
| 119 // Marks all entries accessed since |initial_time| for deletion. The return | 125 // Marks all entries accessed since |initial_time| for deletion. The return |
| 120 // value is a net error code. If this method returns ERR_IO_PENDING, the | 126 // value is a net error code. If this method returns ERR_IO_PENDING, the |
| 121 // |callback| will be invoked when the operation completes. | 127 // |callback| will be invoked when the operation completes. |
| 122 // Entries with |initial_time| <= access time are deleted. | 128 // Entries with |initial_time| <= access time are deleted. |
| 123 virtual int DoomEntriesSince(base::Time initial_time, | 129 virtual int DoomEntriesSince(base::Time initial_time, |
| 124 const CompletionCallback& callback) = 0; | 130 const CompletionCallback& callback) = 0; |
| 125 | 131 |
| 126 // Enumerates the cache. Initialize |iter| to NULL before calling this method | 132 // Enumerates the cache. Initialize |iter| to NULL for the first call, and |
| 127 // the first time. That will cause the enumeration to start at the head of | 133 // provide it again for subsequent calls. For each successful step of |
| 128 // the cache. For subsequent calls, pass the same |iter| pointer again without | 134 // enumeration, OpenNextEntry returns OK and provides |next_entry|, which is |
| 129 // changing its value. This method returns ERR_FAILED when there are no more | 135 // open and should be closed by the caller. This method returns ERR_FAILED at |
| 130 // entries to enumerate. When the entry pointer is no longer needed, its | 136 // the end of enumeration. If any entry in a cache is modified during |
| 131 // Close method should be called. The return value is a net error code. If | 137 // iteration, then the result of this function is thereafter undefined. |
| 132 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the | 138 virtual int OpenNextEntry(Iterator* iter, Entry** next_entry, |
|
rvargas (doing something else)
2014/09/05 02:01:29
So far I'm unconvinced about the API change.
The
gavinp
2014/09/11 23:57:04
The existing pattern of using a void** is neither
| |
| 133 // |next_entry| is available. The pointer to receive the |next_entry| must | |
| 134 // remain valid until the operation completes. | |
| 135 // | |
| 136 // NOTE: This method does not modify the last_used field of the entry, and | |
| 137 // therefore it does not impact the eviction ranking of the entry. However, | |
| 138 // an enumeration will go through all entries on the cache only if the cache | |
| 139 // is not modified while the enumeration is taking place. Significantly | |
| 140 // altering the entry pointed by |iter| (for example, deleting the entry) will | |
| 141 // invalidate |iter|. Performing operations on an entry that modify the entry | |
| 142 // may result in loops in the iteration, skipped entries or similar. | |
| 143 virtual int OpenNextEntry(void** iter, Entry** next_entry, | |
| 144 const CompletionCallback& callback) = 0; | 139 const CompletionCallback& callback) = 0; |
| 145 | 140 |
| 146 // Releases iter without returning the next entry. Whenever OpenNextEntry() | |
| 147 // returns true, but the caller is not interested in continuing the | |
| 148 // enumeration by calling OpenNextEntry() again, the enumeration must be | |
| 149 // ended by calling this method with iter returned by OpenNextEntry(). | |
| 150 virtual void EndEnumeration(void** iter) = 0; | |
| 151 | |
| 152 // Return a list of cache statistics. | 141 // Return a list of cache statistics. |
| 153 virtual void GetStats( | 142 virtual void GetStats( |
| 154 std::vector<std::pair<std::string, std::string> >* stats) = 0; | 143 std::vector<std::pair<std::string, std::string> >* stats) = 0; |
| 155 | 144 |
| 156 // Called whenever an external cache in the system reuses the resource | 145 // Called whenever an external cache in the system reuses the resource |
| 157 // referred to by |key|. | 146 // referred to by |key|. |
| 158 virtual void OnExternalCacheHit(const std::string& key) = 0; | 147 virtual void OnExternalCacheHit(const std::string& key) = 0; |
| 159 }; | 148 }; |
| 160 | 149 |
| 161 // This interface represents an entry in the disk cache. | 150 // This interface represents an entry in the disk cache. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 // OK although another IO operation cannot be issued at this time; in this | 292 // OK although another IO operation cannot be issued at this time; in this |
| 304 // case the caller should just wait for the regular callback to be invoked | 293 // case the caller should just wait for the regular callback to be invoked |
| 305 // instead of using this method to provide another callback. | 294 // instead of using this method to provide another callback. |
| 306 // | 295 // |
| 307 // Note that CancelSparseIO may have been called on another instance of this | 296 // Note that CancelSparseIO may have been called on another instance of this |
| 308 // object that refers to the same physical disk entry. | 297 // object that refers to the same physical disk entry. |
| 309 // Note: This method is deprecated. | 298 // Note: This method is deprecated. |
| 310 virtual int ReadyForSparseIO(const CompletionCallback& callback) = 0; | 299 virtual int ReadyForSparseIO(const CompletionCallback& callback) = 0; |
| 311 | 300 |
| 312 protected: | 301 protected: |
| 313 virtual ~Entry() {} | 302 virtual ~Entry(); |
| 314 }; | 303 }; |
| 315 | 304 |
| 316 struct EntryDeleter { | 305 struct EntryDeleter { |
| 317 void operator()(Entry* entry) { | 306 void operator()(Entry* entry) { |
| 318 // Note that |entry| is ref-counted. | 307 // Note that |entry| is ref-counted. |
| 319 entry->Close(); | 308 entry->Close(); |
| 320 } | 309 } |
| 321 }; | 310 }; |
| 322 | 311 |
| 323 // Automatically closes an entry when it goes out of scope. | 312 // Automatically closes an entry when it goes out of scope. |
| 324 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; | 313 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; |
| 325 | 314 |
| 326 } // namespace disk_cache | 315 } // namespace disk_cache |
| 327 | 316 |
| 328 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 317 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
| OLD | NEW |