| 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" | |
| 17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 18 #include "net/base/cache_type.h" | 17 #include "net/base/cache_type.h" |
| 19 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
| 20 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class FilePath; | 22 class FilePath; |
| 24 class SingleThreadTaskRunner; | 23 class SingleThreadTaskRunner; |
| 25 } | 24 } |
| 26 | 25 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | 57 const scoped_refptr<base::SingleThreadTaskRunner>& thread, |
| 59 net::NetLog* net_log, | 58 net::NetLog* net_log, |
| 60 scoped_ptr<Backend>* backend, | 59 scoped_ptr<Backend>* backend, |
| 61 const net::CompletionCallback& callback); | 60 const net::CompletionCallback& callback); |
| 62 | 61 |
| 63 // The root interface for a disk cache instance. | 62 // The root interface for a disk cache instance. |
| 64 class NET_EXPORT Backend { | 63 class NET_EXPORT Backend { |
| 65 public: | 64 public: |
| 66 typedef net::CompletionCallback CompletionCallback; | 65 typedef net::CompletionCallback CompletionCallback; |
| 67 | 66 |
| 68 class Iterator { | |
| 69 public: | |
| 70 virtual ~Iterator() {} | |
| 71 | |
| 72 // OpenNextEntry returns |net::OK| and provides |next_entry| if there is an | |
| 73 // entry to enumerate. It returns |net::ERR_FAILED| at the end of | |
| 74 // enumeration. If the function returns |net::ERR_IO_PENDING|, then the | |
| 75 // final result will be passed to the provided |callback|, otherwise | |
| 76 // |callback| will not be called. If any entry in the cache is modified | |
| 77 // during iteration, the result of this function is thereafter undefined. | |
| 78 // | |
| 79 // Calling OpenNextEntry after the backend which created it is destroyed | |
| 80 // may fail with |net::ERR_FAILED|; however it should not crash. | |
| 81 // | |
| 82 // Some cache backends make stronger guarantees about mutation during | |
| 83 // iteration, see top comment in simple_backend_impl.h for details. | |
| 84 virtual int OpenNextEntry(Entry** next_entry, | |
| 85 const CompletionCallback& callback) = 0; | |
| 86 }; | |
| 87 | |
| 88 // If the backend is destroyed when there are operations in progress (any | 67 // If the backend is destroyed when there are operations in progress (any |
| 89 // callback that has not been invoked yet), this method cancels said | 68 // callback that has not been invoked yet), this method cancels said |
| 90 // operations so the callbacks are not invoked, possibly leaving the work | 69 // operations so the callbacks are not invoked, possibly leaving the work |
| 91 // half way (for instance, dooming just a few entries). Note that pending IO | 70 // half way (for instance, dooming just a few entries). Note that pending IO |
| 92 // for a given Entry (as opposed to the Backend) will still generate a | 71 // for a given Entry (as opposed to the Backend) will still generate a |
| 93 // callback from within this method. | 72 // callback from within this method. |
| 94 virtual ~Backend() {} | 73 virtual ~Backend() {} |
| 95 | 74 |
| 96 // Returns the type of this cache. | 75 // Returns the type of this cache. |
| 97 virtual net::CacheType GetCacheType() const = 0; | 76 virtual net::CacheType GetCacheType() const = 0; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 base::Time end_time, | 116 base::Time end_time, |
| 138 const CompletionCallback& callback) = 0; | 117 const CompletionCallback& callback) = 0; |
| 139 | 118 |
| 140 // Marks all entries accessed since |initial_time| for deletion. The return | 119 // Marks all entries accessed since |initial_time| for deletion. The return |
| 141 // value is a net error code. If this method returns ERR_IO_PENDING, the | 120 // value is a net error code. If this method returns ERR_IO_PENDING, the |
| 142 // |callback| will be invoked when the operation completes. | 121 // |callback| will be invoked when the operation completes. |
| 143 // Entries with |initial_time| <= access time are deleted. | 122 // Entries with |initial_time| <= access time are deleted. |
| 144 virtual int DoomEntriesSince(base::Time initial_time, | 123 virtual int DoomEntriesSince(base::Time initial_time, |
| 145 const CompletionCallback& callback) = 0; | 124 const CompletionCallback& callback) = 0; |
| 146 | 125 |
| 147 // Returns an iterator which will enumerate all entries of the cache in an | 126 // Enumerates the cache. Initialize |iter| to NULL before calling this method |
| 148 // undefined order. | 127 // the first time. That will cause the enumeration to start at the head of |
| 149 virtual scoped_ptr<Iterator> CreateIterator() = 0; | 128 // the cache. For subsequent calls, pass the same |iter| pointer again without |
| 129 // changing its value. This method returns ERR_FAILED when there are no more |
| 130 // entries to enumerate. When the entry pointer is no longer needed, its |
| 131 // Close method should be called. The return value is a net error code. If |
| 132 // this method returns ERR_IO_PENDING, the |callback| will be invoked when the |
| 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; |
| 145 |
| 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; |
| 150 | 151 |
| 151 // Return a list of cache statistics. | 152 // Return a list of cache statistics. |
| 152 virtual void GetStats( | 153 virtual void GetStats( |
| 153 std::vector<std::pair<std::string, std::string> >* stats) = 0; | 154 std::vector<std::pair<std::string, std::string> >* stats) = 0; |
| 154 | 155 |
| 155 // Called whenever an external cache in the system reuses the resource | 156 // Called whenever an external cache in the system reuses the resource |
| 156 // referred to by |key|. | 157 // referred to by |key|. |
| 157 virtual void OnExternalCacheHit(const std::string& key) = 0; | 158 virtual void OnExternalCacheHit(const std::string& key) = 0; |
| 158 }; | 159 }; |
| 159 | 160 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 entry->Close(); | 319 entry->Close(); |
| 319 } | 320 } |
| 320 }; | 321 }; |
| 321 | 322 |
| 322 // Automatically closes an entry when it goes out of scope. | 323 // Automatically closes an entry when it goes out of scope. |
| 323 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; | 324 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; |
| 324 | 325 |
| 325 } // namespace disk_cache | 326 } // namespace disk_cache |
| 326 | 327 |
| 327 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 328 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
| OLD | NEW |