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

Side by Side Diff: content/browser/cache_storage/cache_storage_cache.h

Issue 1248003004: CacheStorage: Implement Cache.matchAll() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix wrong conditional branch Created 5 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_
6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/id_map.h" 12 #include "base/id_map.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "content/common/cache_storage/cache_storage_types.h" 16 #include "content/common/cache_storage/cache_storage_types.h"
16 #include "content/common/service_worker/service_worker_types.h" 17 #include "content/common/service_worker/service_worker_types.h"
17 #include "net/disk_cache/disk_cache.h" 18 #include "net/disk_cache/disk_cache.h"
18 19
19 namespace net { 20 namespace net {
20 class URLRequestContextGetter; 21 class URLRequestContextGetter;
21 class IOBufferWithSize; 22 class IOBufferWithSize;
22 } 23 }
23 24
(...skipping 15 matching lines...) Expand all
39 // The asynchronous methods are executed serially. Callbacks to the 40 // The asynchronous methods are executed serially. Callbacks to the
40 // public functions will be called so long as the cache object lives. 41 // public functions will be called so long as the cache object lives.
41 class CONTENT_EXPORT CacheStorageCache 42 class CONTENT_EXPORT CacheStorageCache
42 : public base::RefCounted<CacheStorageCache> { 43 : public base::RefCounted<CacheStorageCache> {
43 public: 44 public:
44 using ErrorCallback = base::Callback<void(CacheStorageError)>; 45 using ErrorCallback = base::Callback<void(CacheStorageError)>;
45 using ResponseCallback = 46 using ResponseCallback =
46 base::Callback<void(CacheStorageError, 47 base::Callback<void(CacheStorageError,
47 scoped_ptr<ServiceWorkerResponse>, 48 scoped_ptr<ServiceWorkerResponse>,
48 scoped_ptr<storage::BlobDataHandle>)>; 49 scoped_ptr<storage::BlobDataHandle>)>;
50 using ResponsesCallback =
51 base::Callback<void(CacheStorageError,
52 const std::vector<ServiceWorkerResponse>&,
jkarlin 2015/08/05 12:09:05 Let's make this a scoped_ptr<std::vector<ServiceWo
nhiroki 2015/08/06 03:36:53 Done.
53 ScopedVector<storage::BlobDataHandle>)>;
49 using Requests = std::vector<ServiceWorkerFetchRequest>; 54 using Requests = std::vector<ServiceWorkerFetchRequest>;
50 using RequestsCallback = 55 using RequestsCallback =
51 base::Callback<void(CacheStorageError, scoped_ptr<Requests>)>; 56 base::Callback<void(CacheStorageError, scoped_ptr<Requests>)>;
52 57
53 static scoped_refptr<CacheStorageCache> CreateMemoryCache( 58 static scoped_refptr<CacheStorageCache> CreateMemoryCache(
54 const GURL& origin, 59 const GURL& origin,
55 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 60 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
56 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 61 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
57 base::WeakPtr<storage::BlobStorageContext> blob_context); 62 base::WeakPtr<storage::BlobStorageContext> blob_context);
58 static scoped_refptr<CacheStorageCache> CreatePersistentCache( 63 static scoped_refptr<CacheStorageCache> CreatePersistentCache(
59 const GURL& origin, 64 const GURL& origin,
60 const base::FilePath& path, 65 const base::FilePath& path,
61 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 66 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
62 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 67 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
63 base::WeakPtr<storage::BlobStorageContext> blob_context); 68 base::WeakPtr<storage::BlobStorageContext> blob_context);
64 69
65 // Returns ERROR_TYPE_NOT_FOUND if not found. 70 // Returns ERROR_TYPE_NOT_FOUND if not found.
66 void Match(scoped_ptr<ServiceWorkerFetchRequest> request, 71 void Match(scoped_ptr<ServiceWorkerFetchRequest> request,
67 const ResponseCallback& callback); 72 const ResponseCallback& callback);
68 73
74 // Returns CACHE_STORAGE_OK and all responses in this cache. If there is no
jkarlin 2015/08/05 12:09:05 s/there is no response/there are no responses/
nhiroki 2015/08/06 03:36:53 Done.
75 // response, returns CACHE_STORAGE_OK and an empty vector.
76 void MatchAll(const ResponsesCallback& callback);
77
69 // Runs given batch operations. This corresponds to the Batch Cache Operations 78 // Runs given batch operations. This corresponds to the Batch Cache Operations
70 // algorithm in the spec. 79 // algorithm in the spec.
71 // 80 //
72 // |operations| cannot mix PUT and DELETE operations and cannot contain 81 // |operations| cannot mix PUT and DELETE operations and cannot contain
73 // multiple DELETE operations. 82 // multiple DELETE operations.
74 // 83 //
75 // In the case of the PUT operation, puts request and response objects in the 84 // In the case of the PUT operation, puts request and response objects in the
76 // cache and returns OK when all operations are successfully completed. 85 // cache and returns OK when all operations are successfully completed.
77 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified 86 // In the case of the DELETE operation, returns ERROR_NOT_FOUND if a specified
78 // entry is not found. Otherwise deletes it and returns OK. 87 // entry is not found. Otherwise deletes it and returns OK.
(...skipping 18 matching lines...) Expand all
97 // The size of the cache contents in memory. Returns 0 if the cache backend is 106 // The size of the cache contents in memory. Returns 0 if the cache backend is
98 // not a memory cache backend. 107 // not a memory cache backend.
99 int64 MemoryBackedSize() const; 108 int64 MemoryBackedSize() const;
100 109
101 base::WeakPtr<CacheStorageCache> AsWeakPtr(); 110 base::WeakPtr<CacheStorageCache> AsWeakPtr();
102 111
103 private: 112 private:
104 friend class base::RefCounted<CacheStorageCache>; 113 friend class base::RefCounted<CacheStorageCache>;
105 friend class TestCacheStorageCache; 114 friend class TestCacheStorageCache;
106 115
116 struct OpenAllEntriesContext;
117 struct MatchAllContext;
107 struct KeysContext; 118 struct KeysContext;
108 struct PutContext; 119 struct PutContext;
109 120
110 // The backend progresses from uninitialized, to open, to closed, and cannot 121 // The backend progresses from uninitialized, to open, to closed, and cannot
111 // reverse direction. The open step may be skipped. 122 // reverse direction. The open step may be skipped.
112 enum BackendState { 123 enum BackendState {
113 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. 124 BACKEND_UNINITIALIZED, // No backend, create backend on first operation.
114 BACKEND_OPEN, // Backend can be used. 125 BACKEND_OPEN, // Backend can be used.
115 BACKEND_CLOSED // Backend cannot be used. All ops should fail. 126 BACKEND_CLOSED // Backend cannot be used. All ops should fail.
116 }; 127 };
117 128
118 using Entries = std::vector<disk_cache::Entry*>; 129 using Entries = std::vector<disk_cache::Entry*>;
119 using ScopedBackendPtr = scoped_ptr<disk_cache::Backend>; 130 using ScopedBackendPtr = scoped_ptr<disk_cache::Backend>;
120 using BlobToDiskCacheIDMap = 131 using BlobToDiskCacheIDMap =
121 IDMap<CacheStorageBlobToDiskCache, IDMapOwnPointer>; 132 IDMap<CacheStorageBlobToDiskCache, IDMapOwnPointer>;
133 using OpenAllEntriesCallback =
134 base::Callback<void(scoped_ptr<OpenAllEntriesContext>,
135 CacheStorageError)>;
122 136
123 CacheStorageCache( 137 CacheStorageCache(
124 const GURL& origin, 138 const GURL& origin,
125 const base::FilePath& path, 139 const base::FilePath& path,
126 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 140 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
127 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 141 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
128 base::WeakPtr<storage::BlobStorageContext> blob_context); 142 base::WeakPtr<storage::BlobStorageContext> blob_context);
129 143
130 // Async operations in progress will cancel and not run their callbacks. 144 // Async operations in progress will cancel and not run their callbacks.
131 virtual ~CacheStorageCache(); 145 virtual ~CacheStorageCache();
132 146
133 // Returns true if the backend is ready to operate. 147 // Returns true if the backend is ready to operate.
134 bool LazyInitialize(); 148 bool LazyInitialize();
135 149
150 // Returns all entries in this cache.
151 void OpenAllEntries(const OpenAllEntriesCallback& callback);
152 void DidOpenNextEntry(scoped_ptr<OpenAllEntriesContext> entries_context,
153 const OpenAllEntriesCallback& callback,
154 int rv);
155
136 // Match callbacks 156 // Match callbacks
137 void MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request, 157 void MatchImpl(scoped_ptr<ServiceWorkerFetchRequest> request,
138 const ResponseCallback& callback); 158 const ResponseCallback& callback);
139 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, 159 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request,
140 const ResponseCallback& callback, 160 const ResponseCallback& callback,
141 scoped_ptr<disk_cache::Entry*> entry_ptr, 161 scoped_ptr<disk_cache::Entry*> entry_ptr,
142 int rv); 162 int rv);
143 void MatchDidReadMetadata(scoped_ptr<ServiceWorkerFetchRequest> request, 163 void MatchDidReadMetadata(scoped_ptr<ServiceWorkerFetchRequest> request,
144 const ResponseCallback& callback, 164 const ResponseCallback& callback,
145 disk_cache::ScopedEntryPtr entry, 165 disk_cache::ScopedEntryPtr entry,
146 scoped_ptr<CacheMetadata> headers); 166 scoped_ptr<CacheMetadata> headers);
147 167
168 // MatchAll callbacks
169 void MatchAllImpl(const ResponsesCallback& callback);
170 void MatchAllDidOpenAllEntries(
171 const ResponsesCallback& callback,
172 scoped_ptr<OpenAllEntriesContext> entries_context,
173 CacheStorageError error);
174 void MatchAllProcessNextEntry(scoped_ptr<MatchAllContext> context,
175 const Entries::iterator& iter);
176 void MatchAllDidReadMetadata(scoped_ptr<MatchAllContext> context,
177 const Entries::iterator& iter,
178 scoped_ptr<CacheMetadata> metadata);
179
148 // Puts the request and response object in the cache. The response body (if 180 // Puts the request and response object in the cache. The response body (if
149 // present) is stored in the cache, but not the request body. Returns OK on 181 // present) is stored in the cache, but not the request body. Returns OK on
150 // success. 182 // success.
151 void Put(const CacheStorageBatchOperation& operation, 183 void Put(const CacheStorageBatchOperation& operation,
152 const ErrorCallback& callback); 184 const ErrorCallback& callback);
153 void PutImpl(scoped_ptr<PutContext> put_context); 185 void PutImpl(scoped_ptr<PutContext> put_context);
154 void PutDidDelete(scoped_ptr<PutContext> put_context, 186 void PutDidDelete(scoped_ptr<PutContext> put_context,
155 CacheStorageError delete_error); 187 CacheStorageError delete_error);
156 void PutDidCreateEntry(scoped_ptr<disk_cache::Entry*> entry_ptr, 188 void PutDidCreateEntry(scoped_ptr<disk_cache::Entry*> entry_ptr,
157 scoped_ptr<PutContext> put_context, 189 scoped_ptr<PutContext> put_context,
(...skipping 14 matching lines...) Expand all
172 void DeleteDidOpenEntry( 204 void DeleteDidOpenEntry(
173 const GURL& origin, 205 const GURL& origin,
174 scoped_ptr<ServiceWorkerFetchRequest> request, 206 scoped_ptr<ServiceWorkerFetchRequest> request,
175 const CacheStorageCache::ErrorCallback& callback, 207 const CacheStorageCache::ErrorCallback& callback,
176 scoped_ptr<disk_cache::Entry*> entryptr, 208 scoped_ptr<disk_cache::Entry*> entryptr,
177 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 209 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
178 int rv); 210 int rv);
179 211
180 // Keys callbacks. 212 // Keys callbacks.
181 void KeysImpl(const RequestsCallback& callback); 213 void KeysImpl(const RequestsCallback& callback);
182 void KeysDidOpenNextEntry(scoped_ptr<KeysContext> keys_context, int rv); 214 void KeysDidOpenAllEntries(const RequestsCallback& callback,
215 scoped_ptr<OpenAllEntriesContext> entries_context,
216 CacheStorageError error);
183 void KeysProcessNextEntry(scoped_ptr<KeysContext> keys_context, 217 void KeysProcessNextEntry(scoped_ptr<KeysContext> keys_context,
184 const Entries::iterator& iter); 218 const Entries::iterator& iter);
185 void KeysDidReadMetadata(scoped_ptr<KeysContext> keys_context, 219 void KeysDidReadMetadata(scoped_ptr<KeysContext> keys_context,
186 const Entries::iterator& iter, 220 const Entries::iterator& iter,
187 scoped_ptr<CacheMetadata> metadata); 221 scoped_ptr<CacheMetadata> metadata);
188 222
189 void CloseImpl(const base::Closure& callback); 223 void CloseImpl(const base::Closure& callback);
190 224
191 // Loads the backend and calls the callback with the result (true for 225 // Loads the backend and calls the callback with the result (true for
192 // success). The callback will always be called. Virtual for tests. 226 // success). The callback will always be called. Virtual for tests.
193 virtual void CreateBackend(const ErrorCallback& callback); 227 virtual void CreateBackend(const ErrorCallback& callback);
194 void CreateBackendDidCreate(const CacheStorageCache::ErrorCallback& callback, 228 void CreateBackendDidCreate(const CacheStorageCache::ErrorCallback& callback,
195 scoped_ptr<ScopedBackendPtr> backend_ptr, 229 scoped_ptr<ScopedBackendPtr> backend_ptr,
196 int rv); 230 int rv);
197 231
198 void InitBackend(); 232 void InitBackend();
199 void InitDone(CacheStorageError error); 233 void InitDone(CacheStorageError error);
200 234
201 void PendingClosure(const base::Closure& callback); 235 void PendingClosure(const base::Closure& callback);
202 void PendingErrorCallback(const ErrorCallback& callback, 236 void PendingErrorCallback(const ErrorCallback& callback,
203 CacheStorageError error); 237 CacheStorageError error);
204 void PendingResponseCallback( 238 void PendingResponseCallback(
205 const ResponseCallback& callback, 239 const ResponseCallback& callback,
206 CacheStorageError error, 240 CacheStorageError error,
207 scoped_ptr<ServiceWorkerResponse> response, 241 scoped_ptr<ServiceWorkerResponse> response,
208 scoped_ptr<storage::BlobDataHandle> blob_data_handle); 242 scoped_ptr<storage::BlobDataHandle> blob_data_handle);
243 void PendingResponsesCallback(
244 const ResponsesCallback& callback,
245 CacheStorageError error,
246 const std::vector<ServiceWorkerResponse>& responses,
247 ScopedVector<storage::BlobDataHandle> blob_data_handles);
209 void PendingRequestsCallback(const RequestsCallback& callback, 248 void PendingRequestsCallback(const RequestsCallback& callback,
210 CacheStorageError error, 249 CacheStorageError error,
211 scoped_ptr<Requests> requests); 250 scoped_ptr<Requests> requests);
212 251
213 // Be sure to check |backend_state_| before use. 252 // Be sure to check |backend_state_| before use.
214 scoped_ptr<disk_cache::Backend> backend_; 253 scoped_ptr<disk_cache::Backend> backend_;
215 254
216 GURL origin_; 255 GURL origin_;
217 base::FilePath path_; 256 base::FilePath path_;
218 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 257 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
(...skipping 10 matching lines...) Expand all
229 bool memory_only_; 268 bool memory_only_;
230 269
231 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; 270 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_;
232 271
233 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); 272 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache);
234 }; 273 };
235 274
236 } // namespace content 275 } // namespace content
237 276
238 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ 277 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698