Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: net/disk_cache/disk_cache.h

Issue 542733002: Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: narrower Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
67 // If the backend is destroyed when there are operations in progress (any 88 // If the backend is destroyed when there are operations in progress (any
68 // callback that has not been invoked yet), this method cancels said 89 // callback that has not been invoked yet), this method cancels said
69 // operations so the callbacks are not invoked, possibly leaving the work 90 // 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 91 // 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 92 // for a given Entry (as opposed to the Backend) will still generate a
72 // callback from within this method. 93 // callback from within this method.
73 virtual ~Backend() {} 94 virtual ~Backend();
rvargas (doing something else) 2014/09/18 02:32:12 I still think we should not have a cc file for thi
gavinp 2014/09/18 18:13:04 You're right, I reviewed the rules in http://www.c
74 95
75 // Returns the type of this cache. 96 // Returns the type of this cache.
76 virtual net::CacheType GetCacheType() const = 0; 97 virtual net::CacheType GetCacheType() const = 0;
77 98
78 // Returns the number of entries in the cache. 99 // Returns the number of entries in the cache.
79 virtual int32 GetEntryCount() const = 0; 100 virtual int32 GetEntryCount() const = 0;
80 101
81 // Opens an existing entry. Upon success, |entry| holds a pointer to an Entry 102 // 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 103 // 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 104 // 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
116 base::Time end_time, 137 base::Time end_time,
117 const CompletionCallback& callback) = 0; 138 const CompletionCallback& callback) = 0;
118 139
119 // Marks all entries accessed since |initial_time| for deletion. The return 140 // 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 141 // value is a net error code. If this method returns ERR_IO_PENDING, the
121 // |callback| will be invoked when the operation completes. 142 // |callback| will be invoked when the operation completes.
122 // Entries with |initial_time| <= access time are deleted. 143 // Entries with |initial_time| <= access time are deleted.
123 virtual int DoomEntriesSince(base::Time initial_time, 144 virtual int DoomEntriesSince(base::Time initial_time,
124 const CompletionCallback& callback) = 0; 145 const CompletionCallback& callback) = 0;
125 146
126 // Enumerates the cache. Initialize |iter| to NULL before calling this method 147 // 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 148 // undefined order.
128 // the cache. For subsequent calls, pass the same |iter| pointer again without 149 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
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 150
152 // Return a list of cache statistics. 151 // Return a list of cache statistics.
153 virtual void GetStats( 152 virtual void GetStats(
154 std::vector<std::pair<std::string, std::string> >* stats) = 0; 153 std::vector<std::pair<std::string, std::string> >* stats) = 0;
155 154
156 // Called whenever an external cache in the system reuses the resource 155 // Called whenever an external cache in the system reuses the resource
157 // referred to by |key|. 156 // referred to by |key|.
158 virtual void OnExternalCacheHit(const std::string& key) = 0; 157 virtual void OnExternalCacheHit(const std::string& key) = 0;
159 }; 158 };
160 159
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // OK although another IO operation cannot be issued at this time; in this 302 // 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 303 // case the caller should just wait for the regular callback to be invoked
305 // instead of using this method to provide another callback. 304 // instead of using this method to provide another callback.
306 // 305 //
307 // Note that CancelSparseIO may have been called on another instance of this 306 // Note that CancelSparseIO may have been called on another instance of this
308 // object that refers to the same physical disk entry. 307 // object that refers to the same physical disk entry.
309 // Note: This method is deprecated. 308 // Note: This method is deprecated.
310 virtual int ReadyForSparseIO(const CompletionCallback& callback) = 0; 309 virtual int ReadyForSparseIO(const CompletionCallback& callback) = 0;
311 310
312 protected: 311 protected:
313 virtual ~Entry() {} 312 virtual ~Entry();
314 }; 313 };
315 314
316 struct EntryDeleter { 315 struct EntryDeleter {
317 void operator()(Entry* entry) { 316 void operator()(Entry* entry) {
318 // Note that |entry| is ref-counted. 317 // Note that |entry| is ref-counted.
319 entry->Close(); 318 entry->Close();
320 } 319 }
321 }; 320 };
322 321
323 // Automatically closes an entry when it goes out of scope. 322 // Automatically closes an entry when it goes out of scope.
324 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; 323 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr;
325 324
326 } // namespace disk_cache 325 } // namespace disk_cache
327 326
328 #endif // NET_DISK_CACHE_DISK_CACHE_H_ 327 #endif // NET_DISK_CACHE_DISK_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698