OLD | NEW |
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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 using BlobDataHandles = std::vector<storage::BlobDataHandle>; | 54 using BlobDataHandles = std::vector<storage::BlobDataHandle>; |
55 using ResponsesCallback = | 55 using ResponsesCallback = |
56 base::Callback<void(CacheStorageError, | 56 base::Callback<void(CacheStorageError, |
57 std::unique_ptr<Responses>, | 57 std::unique_ptr<Responses>, |
58 std::unique_ptr<BlobDataHandles>)>; | 58 std::unique_ptr<BlobDataHandles>)>; |
59 using Requests = std::vector<ServiceWorkerFetchRequest>; | 59 using Requests = std::vector<ServiceWorkerFetchRequest>; |
60 using RequestsCallback = | 60 using RequestsCallback = |
61 base::Callback<void(CacheStorageError, std::unique_ptr<Requests>)>; | 61 base::Callback<void(CacheStorageError, std::unique_ptr<Requests>)>; |
62 using SizeCallback = base::Callback<void(int64_t)>; | 62 using SizeCallback = base::Callback<void(int64_t)>; |
63 | 63 |
| 64 struct QueryCacheResults; |
| 65 using QueryCacheResultsCallback = |
| 66 base::Callback<void(CacheStorageError, |
| 67 std::unique_ptr<QueryCacheResults>)>; |
| 68 |
64 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; | 69 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA }; |
65 | 70 |
66 static std::unique_ptr<CacheStorageCache> CreateMemoryCache( | 71 static std::unique_ptr<CacheStorageCache> CreateMemoryCache( |
67 const GURL& origin, | 72 const GURL& origin, |
68 const std::string& cache_name, | 73 const std::string& cache_name, |
69 CacheStorage* cache_storage, | 74 CacheStorage* cache_storage, |
70 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 75 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
71 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 76 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
72 base::WeakPtr<storage::BlobStorageContext> blob_context); | 77 base::WeakPtr<storage::BlobStorageContext> blob_context); |
73 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( | 78 static std::unique_ptr<CacheStorageCache> CreatePersistentCache( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 155 |
151 std::string cache_name() const { return cache_name_; } | 156 std::string cache_name() const { return cache_name_; } |
152 | 157 |
153 base::WeakPtr<CacheStorageCache> AsWeakPtr(); | 158 base::WeakPtr<CacheStorageCache> AsWeakPtr(); |
154 | 159 |
155 private: | 160 private: |
156 friend class base::RefCounted<CacheStorageCache>; | 161 friend class base::RefCounted<CacheStorageCache>; |
157 friend class TestCacheStorageCache; | 162 friend class TestCacheStorageCache; |
158 | 163 |
159 struct OpenAllEntriesContext; | 164 struct OpenAllEntriesContext; |
160 struct MatchAllContext; | |
161 struct KeysContext; | |
162 struct PutContext; | 165 struct PutContext; |
163 | 166 |
164 // The backend progresses from uninitialized, to open, to closed, and cannot | 167 // The backend progresses from uninitialized, to open, to closed, and cannot |
165 // reverse direction. The open step may be skipped. | 168 // reverse direction. The open step may be skipped. |
166 enum BackendState { | 169 enum BackendState { |
167 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. | 170 BACKEND_UNINITIALIZED, // No backend, create backend on first operation. |
168 BACKEND_OPEN, // Backend can be used. | 171 BACKEND_OPEN, // Backend can be used. |
169 BACKEND_CLOSED // Backend cannot be used. All ops should fail. | 172 BACKEND_CLOSED // Backend cannot be used. All ops should fail. |
170 }; | 173 }; |
171 | 174 |
(...skipping 13 matching lines...) Expand all Loading... |
185 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 188 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
186 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 189 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
187 base::WeakPtr<storage::BlobStorageContext> blob_context); | 190 base::WeakPtr<storage::BlobStorageContext> blob_context); |
188 | 191 |
189 // Returns all entries in this cache. | 192 // Returns all entries in this cache. |
190 void OpenAllEntries(const OpenAllEntriesCallback& callback); | 193 void OpenAllEntries(const OpenAllEntriesCallback& callback); |
191 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, | 194 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, |
192 const OpenAllEntriesCallback& callback, | 195 const OpenAllEntriesCallback& callback, |
193 int rv); | 196 int rv); |
194 | 197 |
| 198 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 199 const CacheStorageCacheQueryParams& options, |
| 200 const QueryCacheResultsCallback& callback); |
| 201 void QueryCacheDidOpenAllEntries( |
| 202 std::unique_ptr<QueryCacheResults> query_cache_results, |
| 203 std::unique_ptr<OpenAllEntriesContext> entries_context, |
| 204 CacheStorageError error); |
| 205 void QueryCacheProcessNextEntry( |
| 206 std::unique_ptr<QueryCacheResults> query_cache_results, |
| 207 const Entries::iterator& iter); |
| 208 void QueryCacheDidReadMetadata( |
| 209 std::unique_ptr<QueryCacheResults> query_cache_results, |
| 210 const Entries::iterator& iter, |
| 211 std::unique_ptr<CacheMetadata> metadata); |
| 212 |
195 // Match callbacks | 213 // Match callbacks |
196 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 214 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
197 const ResponseCallback& callback); | 215 const ResponseCallback& callback); |
198 void MatchDidOpenEntry(std::unique_ptr<ServiceWorkerFetchRequest> request, | 216 void MatchDidOpenEntry(std::unique_ptr<ServiceWorkerFetchRequest> request, |
199 const ResponseCallback& callback, | 217 const ResponseCallback& callback, |
200 std::unique_ptr<disk_cache::Entry*> entry_ptr, | 218 std::unique_ptr<disk_cache::Entry*> entry_ptr, |
201 int rv); | 219 int rv); |
202 void MatchDidReadMetadata(std::unique_ptr<ServiceWorkerFetchRequest> request, | 220 void MatchDidReadMetadata(std::unique_ptr<ServiceWorkerFetchRequest> request, |
203 const ResponseCallback& callback, | 221 const ResponseCallback& callback, |
204 disk_cache::ScopedEntryPtr entry, | 222 disk_cache::ScopedEntryPtr entry, |
205 std::unique_ptr<CacheMetadata> headers); | 223 std::unique_ptr<CacheMetadata> headers); |
206 | 224 |
207 // MatchAll callbacks | 225 // MatchAll callbacks |
208 void MatchAllImpl(std::unique_ptr<MatchAllContext> context); | 226 void MatchAllImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
209 void MatchAllDidOpenAllEntries( | 227 const CacheStorageCacheQueryParams& options, |
210 std::unique_ptr<MatchAllContext> context, | 228 const ResponsesCallback& callback); |
211 std::unique_ptr<OpenAllEntriesContext> entries_context, | 229 void MatchAllDidQueryCache( |
212 CacheStorageError error); | 230 const ResponsesCallback& callback, |
213 void MatchAllProcessNextEntry(std::unique_ptr<MatchAllContext> context, | 231 CacheStorageError error, |
214 const Entries::iterator& iter); | 232 std::unique_ptr<QueryCacheResults> query_cache_results); |
215 void MatchAllDidReadMetadata(std::unique_ptr<MatchAllContext> context, | |
216 const Entries::iterator& iter, | |
217 std::unique_ptr<CacheMetadata> metadata); | |
218 | 233 |
219 // WriteSideData callbacks | 234 // WriteSideData callbacks |
220 void WriteSideDataDidGetQuota(const ErrorCallback& callback, | 235 void WriteSideDataDidGetQuota(const ErrorCallback& callback, |
221 const GURL& url, | 236 const GURL& url, |
222 base::Time expected_response_time, | 237 base::Time expected_response_time, |
223 scoped_refptr<net::IOBuffer> buffer, | 238 scoped_refptr<net::IOBuffer> buffer, |
224 int buf_len, | 239 int buf_len, |
225 storage::QuotaStatusCode status_code, | 240 storage::QuotaStatusCode status_code, |
226 int64_t usage, | 241 int64_t usage, |
227 int64_t quota); | 242 int64_t quota); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 std::unique_ptr<OpenAllEntriesContext> entries_context, | 313 std::unique_ptr<OpenAllEntriesContext> entries_context, |
299 CacheStorageError error); | 314 CacheStorageError error); |
300 void DeleteDidOpenEntry(const GURL& origin, | 315 void DeleteDidOpenEntry(const GURL& origin, |
301 std::unique_ptr<ServiceWorkerFetchRequest> request, | 316 std::unique_ptr<ServiceWorkerFetchRequest> request, |
302 const CacheStorageCache::ErrorCallback& callback, | 317 const CacheStorageCache::ErrorCallback& callback, |
303 std::unique_ptr<disk_cache::Entry*> entryptr, | 318 std::unique_ptr<disk_cache::Entry*> entryptr, |
304 int rv); | 319 int rv); |
305 | 320 |
306 // Keys callbacks. | 321 // Keys callbacks. |
307 void KeysImpl(const RequestsCallback& callback); | 322 void KeysImpl(const RequestsCallback& callback); |
308 void KeysDidOpenAllEntries( | 323 void KeysDidQueryCache( |
309 const RequestsCallback& callback, | 324 const RequestsCallback& callback, |
310 std::unique_ptr<OpenAllEntriesContext> entries_context, | 325 CacheStorageError error, |
311 CacheStorageError error); | 326 std::unique_ptr<QueryCacheResults> query_cache_results); |
312 void KeysProcessNextEntry(std::unique_ptr<KeysContext> keys_context, | |
313 const Entries::iterator& iter); | |
314 void KeysDidReadMetadata(std::unique_ptr<KeysContext> keys_context, | |
315 const Entries::iterator& iter, | |
316 std::unique_ptr<CacheMetadata> metadata); | |
317 | 327 |
318 void CloseImpl(const base::Closure& callback); | 328 void CloseImpl(const base::Closure& callback); |
319 | 329 |
320 void SizeImpl(const SizeCallback& callback); | 330 void SizeImpl(const SizeCallback& callback); |
321 | 331 |
322 void GetSizeThenCloseDidGetSize(const SizeCallback& callback, | 332 void GetSizeThenCloseDidGetSize(const SizeCallback& callback, |
323 int64_t cache_size); | 333 int64_t cache_size); |
324 | 334 |
325 // Loads the backend and calls the callback with the result (true for | 335 // Loads the backend and calls the callback with the result (true for |
326 // success). The callback will always be called. Virtual for tests. | 336 // success). The callback will always be called. Virtual for tests. |
327 virtual void CreateBackend(const ErrorCallback& callback); | 337 virtual void CreateBackend(const ErrorCallback& callback); |
328 void CreateBackendDidCreate(const CacheStorageCache::ErrorCallback& callback, | 338 void CreateBackendDidCreate(const CacheStorageCache::ErrorCallback& callback, |
329 std::unique_ptr<ScopedBackendPtr> backend_ptr, | 339 std::unique_ptr<ScopedBackendPtr> backend_ptr, |
330 int rv); | 340 int rv); |
331 | 341 |
332 void InitBackend(); | 342 void InitBackend(); |
333 void InitDidCreateBackend(const base::Closure& callback, | 343 void InitDidCreateBackend(const base::Closure& callback, |
334 CacheStorageError cache_create_error); | 344 CacheStorageError cache_create_error); |
335 void InitGotCacheSize(const base::Closure& callback, | 345 void InitGotCacheSize(const base::Closure& callback, |
336 CacheStorageError cache_create_error, | 346 CacheStorageError cache_create_error, |
337 int cache_size); | 347 int cache_size); |
338 | 348 |
| 349 void PopulateRequestFromMetadata(const CacheMetadata& metadata, |
| 350 const GURL& request_url, |
| 351 ServiceWorkerFetchRequest* request); |
339 void PopulateResponseMetadata(const CacheMetadata& metadata, | 352 void PopulateResponseMetadata(const CacheMetadata& metadata, |
340 ServiceWorkerResponse* response); | 353 ServiceWorkerResponse* response); |
341 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( | 354 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( |
342 disk_cache::ScopedEntryPtr entry, | 355 disk_cache::ScopedEntryPtr entry, |
343 ServiceWorkerResponse* response); | 356 ServiceWorkerResponse* response); |
344 | 357 |
345 // Virtual for testing. | 358 // Virtual for testing. |
346 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); | 359 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); |
347 | 360 |
348 // Be sure to check |backend_state_| before use. | 361 // Be sure to check |backend_state_| before use. |
(...skipping 21 matching lines...) Expand all Loading... |
370 bool memory_only_; | 383 bool memory_only_; |
371 | 384 |
372 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 385 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
373 | 386 |
374 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 387 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
375 }; | 388 }; |
376 | 389 |
377 } // namespace content | 390 } // namespace content |
378 | 391 |
379 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 392 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
OLD | NEW |