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

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: 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"
(...skipping 28 matching lines...) Expand all
39 // The asynchronous methods are executed serially. Callbacks to the 39 // The asynchronous methods are executed serially. Callbacks to the
40 // public functions will be called so long as the cache object lives. 40 // public functions will be called so long as the cache object lives.
41 class CONTENT_EXPORT CacheStorageCache 41 class CONTENT_EXPORT CacheStorageCache
42 : public base::RefCounted<CacheStorageCache> { 42 : public base::RefCounted<CacheStorageCache> {
43 public: 43 public:
44 using ErrorCallback = base::Callback<void(CacheStorageError)>; 44 using ErrorCallback = base::Callback<void(CacheStorageError)>;
45 using ResponseCallback = 45 using ResponseCallback =
46 base::Callback<void(CacheStorageError, 46 base::Callback<void(CacheStorageError,
47 scoped_ptr<ServiceWorkerResponse>, 47 scoped_ptr<ServiceWorkerResponse>,
48 scoped_ptr<storage::BlobDataHandle>)>; 48 scoped_ptr<storage::BlobDataHandle>)>;
49 using ResponsesCallback =
50 base::Callback<void(CacheStorageError,
51 const std::vector<ServiceWorkerResponse>&,
52 ScopedVector<storage::BlobDataHandle>)>;
49 using Requests = std::vector<ServiceWorkerFetchRequest>; 53 using Requests = std::vector<ServiceWorkerFetchRequest>;
50 using RequestsCallback = 54 using RequestsCallback =
51 base::Callback<void(CacheStorageError, scoped_ptr<Requests>)>; 55 base::Callback<void(CacheStorageError, scoped_ptr<Requests>)>;
52 56
53 static scoped_refptr<CacheStorageCache> CreateMemoryCache( 57 static scoped_refptr<CacheStorageCache> CreateMemoryCache(
54 const GURL& origin, 58 const GURL& origin,
55 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 59 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
56 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 60 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
57 base::WeakPtr<storage::BlobStorageContext> blob_context); 61 base::WeakPtr<storage::BlobStorageContext> blob_context);
58 static scoped_refptr<CacheStorageCache> CreatePersistentCache( 62 static scoped_refptr<CacheStorageCache> CreatePersistentCache(
59 const GURL& origin, 63 const GURL& origin,
60 const base::FilePath& path, 64 const base::FilePath& path,
61 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 65 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
62 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 66 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
63 base::WeakPtr<storage::BlobStorageContext> blob_context); 67 base::WeakPtr<storage::BlobStorageContext> blob_context);
64 68
65 // Returns ERROR_TYPE_NOT_FOUND if not found. 69 // Returns ERROR_TYPE_NOT_FOUND if not found.
66 void Match(scoped_ptr<ServiceWorkerFetchRequest> request, 70 void Match(scoped_ptr<ServiceWorkerFetchRequest> request,
67 const ResponseCallback& callback); 71 const ResponseCallback& callback);
68 72
73 // Returns CACHE_STORAGE_OK and all responses in this cache. If there is no
74 // response, returns CACHE_STORAGE_OK and an empty vector.
75 void MatchAll(const ResponsesCallback& callback);
76
69 // Runs given batch operations. This corresponds to the Batch Cache Operations 77 // Runs given batch operations. This corresponds to the Batch Cache Operations
70 // algorithm in the spec. 78 // algorithm in the spec.
71 // 79 //
72 // |operations| cannot mix PUT and DELETE operations and cannot contain 80 // |operations| cannot mix PUT and DELETE operations and cannot contain
73 // multiple DELETE operations. 81 // multiple DELETE operations.
74 // 82 //
75 // In the case of the PUT operation, puts request and response objects in the 83 // 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. 84 // 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 85 // 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. 86 // 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 105 // The size of the cache contents in memory. Returns 0 if the cache backend is
98 // not a memory cache backend. 106 // not a memory cache backend.
99 int64 MemoryBackedSize() const; 107 int64 MemoryBackedSize() const;
100 108
101 base::WeakPtr<CacheStorageCache> AsWeakPtr(); 109 base::WeakPtr<CacheStorageCache> AsWeakPtr();
102 110
103 private: 111 private:
104 friend class base::RefCounted<CacheStorageCache>; 112 friend class base::RefCounted<CacheStorageCache>;
105 friend class TestCacheStorageCache; 113 friend class TestCacheStorageCache;
106 114
115 struct MatchAllContext;
107 struct KeysContext; 116 struct KeysContext;
108 struct PutContext; 117 struct PutContext;
109 118
110 // The backend progresses from uninitialized, to open, to closed, and cannot 119 // The backend progresses from uninitialized, to open, to closed, and cannot
111 // reverse direction. The open step may be skipped. 120 // reverse direction. The open step may be skipped.
112 enum BackendState { 121 enum BackendState {
113 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. 122 BACKEND_UNINITIALIZED, // No backend, create backend on first operation.
114 BACKEND_OPEN, // Backend can be used. 123 BACKEND_OPEN, // Backend can be used.
115 BACKEND_CLOSED // Backend cannot be used. All ops should fail. 124 BACKEND_CLOSED // Backend cannot be used. All ops should fail.
116 }; 125 };
(...skipping 21 matching lines...) Expand all
138 const ResponseCallback& callback); 147 const ResponseCallback& callback);
139 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request, 148 void MatchDidOpenEntry(scoped_ptr<ServiceWorkerFetchRequest> request,
140 const ResponseCallback& callback, 149 const ResponseCallback& callback,
141 scoped_ptr<disk_cache::Entry*> entry_ptr, 150 scoped_ptr<disk_cache::Entry*> entry_ptr,
142 int rv); 151 int rv);
143 void MatchDidReadMetadata(scoped_ptr<ServiceWorkerFetchRequest> request, 152 void MatchDidReadMetadata(scoped_ptr<ServiceWorkerFetchRequest> request,
144 const ResponseCallback& callback, 153 const ResponseCallback& callback,
145 disk_cache::ScopedEntryPtr entry, 154 disk_cache::ScopedEntryPtr entry,
146 scoped_ptr<CacheMetadata> headers); 155 scoped_ptr<CacheMetadata> headers);
147 156
157 // MatchAll callbacks
158 void MatchAllImpl(const ResponsesCallback& callback);
159 void MatchAllDidOpenNextEntry(scoped_ptr<MatchAllContext> context, int rv);
160 void MatchAllProcessNextEntry(scoped_ptr<MatchAllContext> context);
161 void MatchAllDidReadMetadata(scoped_ptr<MatchAllContext> context,
162 disk_cache::ScopedEntryPtr entry,
163 scoped_ptr<CacheMetadata> metadata);
164
148 // Puts the request and response object in the cache. The response body (if 165 // 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 166 // present) is stored in the cache, but not the request body. Returns OK on
150 // success. 167 // success.
151 void Put(const CacheStorageBatchOperation& operation, 168 void Put(const CacheStorageBatchOperation& operation,
152 const ErrorCallback& callback); 169 const ErrorCallback& callback);
153 void PutImpl(scoped_ptr<PutContext> put_context); 170 void PutImpl(scoped_ptr<PutContext> put_context);
154 void PutDidDelete(scoped_ptr<PutContext> put_context, 171 void PutDidDelete(scoped_ptr<PutContext> put_context,
155 CacheStorageError delete_error); 172 CacheStorageError delete_error);
156 void PutDidCreateEntry(scoped_ptr<disk_cache::Entry*> entry_ptr, 173 void PutDidCreateEntry(scoped_ptr<disk_cache::Entry*> entry_ptr,
157 scoped_ptr<PutContext> put_context, 174 scoped_ptr<PutContext> put_context,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void InitDone(CacheStorageError error); 216 void InitDone(CacheStorageError error);
200 217
201 void PendingClosure(const base::Closure& callback); 218 void PendingClosure(const base::Closure& callback);
202 void PendingErrorCallback(const ErrorCallback& callback, 219 void PendingErrorCallback(const ErrorCallback& callback,
203 CacheStorageError error); 220 CacheStorageError error);
204 void PendingResponseCallback( 221 void PendingResponseCallback(
205 const ResponseCallback& callback, 222 const ResponseCallback& callback,
206 CacheStorageError error, 223 CacheStorageError error,
207 scoped_ptr<ServiceWorkerResponse> response, 224 scoped_ptr<ServiceWorkerResponse> response,
208 scoped_ptr<storage::BlobDataHandle> blob_data_handle); 225 scoped_ptr<storage::BlobDataHandle> blob_data_handle);
226 void PendingResponsesCallback(
227 const ResponsesCallback& callback,
228 CacheStorageError error,
229 const std::vector<ServiceWorkerResponse>& responses,
230 ScopedVector<storage::BlobDataHandle> blob_data_handles);
209 void PendingRequestsCallback(const RequestsCallback& callback, 231 void PendingRequestsCallback(const RequestsCallback& callback,
210 CacheStorageError error, 232 CacheStorageError error,
211 scoped_ptr<Requests> requests); 233 scoped_ptr<Requests> requests);
212 234
213 // Be sure to check |backend_state_| before use. 235 // Be sure to check |backend_state_| before use.
214 scoped_ptr<disk_cache::Backend> backend_; 236 scoped_ptr<disk_cache::Backend> backend_;
215 237
216 GURL origin_; 238 GURL origin_;
217 base::FilePath path_; 239 base::FilePath path_;
218 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 240 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
(...skipping 10 matching lines...) Expand all
229 bool memory_only_; 251 bool memory_only_;
230 252
231 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; 253 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_;
232 254
233 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); 255 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache);
234 }; 256 };
235 257
236 } // namespace content 258 } // namespace content
237 259
238 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ 260 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698