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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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: |
65 typedef net::CompletionCallback CompletionCallback; | 66 typedef net::CompletionCallback CompletionCallback; |
66 | 67 |
68 class Iterator { | |
69 public: | |
70 virtual ~Iterator(); | |
71 | |
72 // OpenNextEntry returns |net::OK| and provides |next_entry| if there is an | |
pasko
2014/09/12 08:10:26
Please briefly mention net::ERR_IO_PENDING behavio
gavinp
2014/09/12 14:15:32
Done.
| |
73 // entry to enumerate. It returns |net::ERR_FAILED| at the end of | |
74 // enumeration. If any entry in the cache is modified during iteration, the | |
75 // result of this function is thereafter undefined. | |
76 // | |
77 // Some cache backends make stronger guarantees about mutation during | |
78 // iteration, see top comment in simple_backend_impl.h for details. | |
79 virtual int OpenNextEntry(Entry** next_entry, | |
80 const CompletionCallback& callback) = 0; | |
81 }; | |
82 | |
67 // If the backend is destroyed when there are operations in progress (any | 83 // If the backend is destroyed when there are operations in progress (any |
68 // callback that has not been invoked yet), this method cancels said | 84 // callback that has not been invoked yet), this method cancels said |
69 // operations so the callbacks are not invoked, possibly leaving the work | 85 // 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 | 86 // 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 | 87 // for a given Entry (as opposed to the Backend) will still generate a |
72 // callback from within this method. | 88 // callback from within this method. |
73 virtual ~Backend() {} | 89 virtual ~Backend(); |
74 | 90 |
75 // Returns the type of this cache. | 91 // Returns the type of this cache. |
76 virtual net::CacheType GetCacheType() const = 0; | 92 virtual net::CacheType GetCacheType() const = 0; |
77 | 93 |
78 // Returns the number of entries in the cache. | 94 // Returns the number of entries in the cache. |
79 virtual int32 GetEntryCount() const = 0; | 95 virtual int32 GetEntryCount() const = 0; |
80 | 96 |
81 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry | 97 // 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 | 98 // 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 | 99 // 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, | 132 base::Time end_time, |
117 const CompletionCallback& callback) = 0; | 133 const CompletionCallback& callback) = 0; |
118 | 134 |
119 // Marks all entries accessed since |initial_time| for deletion. The return | 135 // 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 | 136 // value is a net error code. If this method returns ERR_IO_PENDING, the |
121 // |callback| will be invoked when the operation completes. | 137 // |callback| will be invoked when the operation completes. |
122 // Entries with |initial_time| <= access time are deleted. | 138 // Entries with |initial_time| <= access time are deleted. |
123 virtual int DoomEntriesSince(base::Time initial_time, | 139 virtual int DoomEntriesSince(base::Time initial_time, |
124 const CompletionCallback& callback) = 0; | 140 const CompletionCallback& callback) = 0; |
125 | 141 |
126 // Enumerates the cache. Initialize |iter| to NULL before calling this method | 142 // Returns an iterator which will enumerate all entries of the cache in an |
127 // the first time. That will cause the enumeration to start at the head of | 143 // undefined order. |
128 // the cache. For subsequent calls, pass the same |iter| pointer again without | 144 virtual scoped_ptr<Iterator> CreateIterator() = 0; |
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 | |
pasko
2014/09/12 08:10:26
this comment clarifies some undesired behavior of
gavinp
2014/09/12 14:15:32
Done. The revised comment in disk_cache.h summariz
| |
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; | |
151 | 145 |
152 // Return a list of cache statistics. | 146 // Return a list of cache statistics. |
153 virtual void GetStats( | 147 virtual void GetStats( |
154 std::vector<std::pair<std::string, std::string> >* stats) = 0; | 148 std::vector<std::pair<std::string, std::string> >* stats) = 0; |
155 | 149 |
156 // Called whenever an external cache in the system reuses the resource | 150 // Called whenever an external cache in the system reuses the resource |
157 // referred to by |key|. | 151 // referred to by |key|. |
158 virtual void OnExternalCacheHit(const std::string& key) = 0; | 152 virtual void OnExternalCacheHit(const std::string& key) = 0; |
159 }; | 153 }; |
160 | 154 |
(...skipping 142 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 | 297 // 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 | 298 // case the caller should just wait for the regular callback to be invoked |
305 // instead of using this method to provide another callback. | 299 // instead of using this method to provide another callback. |
306 // | 300 // |
307 // Note that CancelSparseIO may have been called on another instance of this | 301 // Note that CancelSparseIO may have been called on another instance of this |
308 // object that refers to the same physical disk entry. | 302 // object that refers to the same physical disk entry. |
309 // Note: This method is deprecated. | 303 // Note: This method is deprecated. |
310 virtual int ReadyForSparseIO(const CompletionCallback& callback) = 0; | 304 virtual int ReadyForSparseIO(const CompletionCallback& callback) = 0; |
311 | 305 |
312 protected: | 306 protected: |
313 virtual ~Entry() {} | 307 virtual ~Entry(); |
314 }; | 308 }; |
315 | 309 |
316 struct EntryDeleter { | 310 struct EntryDeleter { |
317 void operator()(Entry* entry) { | 311 void operator()(Entry* entry) { |
318 // Note that |entry| is ref-counted. | 312 // Note that |entry| is ref-counted. |
319 entry->Close(); | 313 entry->Close(); |
320 } | 314 } |
321 }; | 315 }; |
322 | 316 |
323 // Automatically closes an entry when it goes out of scope. | 317 // Automatically closes an entry when it goes out of scope. |
324 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; | 318 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; |
325 | 319 |
326 } // namespace disk_cache | 320 } // namespace disk_cache |
327 | 321 |
328 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 322 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
OLD | NEW |