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 16 matching lines...) Expand all Loading... | |
188 | 191 |
189 // Returns true if the backend is ready to operate. | 192 // Returns true if the backend is ready to operate. |
190 bool LazyInitialize(); | 193 bool LazyInitialize(); |
191 | 194 |
192 // Returns all entries in this cache. | 195 // Returns all entries in this cache. |
193 void OpenAllEntries(const OpenAllEntriesCallback& callback); | 196 void OpenAllEntries(const OpenAllEntriesCallback& callback); |
194 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, | 197 void DidOpenNextEntry(std::unique_ptr<OpenAllEntriesContext> entries_context, |
195 const OpenAllEntriesCallback& callback, | 198 const OpenAllEntriesCallback& callback, |
196 int rv); | 199 int rv); |
197 | 200 |
201 void QueryCache(std::unique_ptr<ServiceWorkerFetchRequest> request, | |
202 const CacheStorageCacheQueryParams& options, | |
203 const QueryCacheResultsCallback& callback); | |
204 void QueryCacheDidOpenAllEntries( | |
205 std::unique_ptr<QueryCacheResults> query_cache_results, | |
206 std::unique_ptr<OpenAllEntriesContext> entries_context, | |
207 CacheStorageError error); | |
208 void QueryCacheProcessNextEntry( | |
209 std::unique_ptr<QueryCacheResults> query_cache_results, | |
210 const Entries::iterator& iter); | |
211 void QueryCacheDidReadMetadata( | |
212 std::unique_ptr<QueryCacheResults> query_cache_results, | |
213 const Entries::iterator& iter, | |
214 std::unique_ptr<CacheMetadata> metadata); | |
215 | |
198 // Match callbacks | 216 // Match callbacks |
199 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, | 217 void MatchImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
200 const ResponseCallback& callback); | 218 const ResponseCallback& callback); |
201 void MatchDidOpenEntry(std::unique_ptr<ServiceWorkerFetchRequest> request, | 219 void MatchDidOpenEntry(std::unique_ptr<ServiceWorkerFetchRequest> request, |
202 const ResponseCallback& callback, | 220 const ResponseCallback& callback, |
203 std::unique_ptr<disk_cache::Entry*> entry_ptr, | 221 std::unique_ptr<disk_cache::Entry*> entry_ptr, |
204 int rv); | 222 int rv); |
205 void MatchDidReadMetadata(std::unique_ptr<ServiceWorkerFetchRequest> request, | 223 void MatchDidReadMetadata(std::unique_ptr<ServiceWorkerFetchRequest> request, |
206 const ResponseCallback& callback, | 224 const ResponseCallback& callback, |
207 disk_cache::ScopedEntryPtr entry, | 225 disk_cache::ScopedEntryPtr entry, |
208 std::unique_ptr<CacheMetadata> headers); | 226 std::unique_ptr<CacheMetadata> headers); |
209 | 227 |
210 // MatchAll callbacks | 228 // MatchAll callbacks |
211 void MatchAllImpl(std::unique_ptr<MatchAllContext> context); | 229 void MatchAllImpl(std::unique_ptr<ServiceWorkerFetchRequest> request, |
212 void MatchAllDidOpenAllEntries( | 230 const CacheStorageCacheQueryParams& options, |
213 std::unique_ptr<MatchAllContext> context, | 231 const ResponsesCallback& callback); |
214 std::unique_ptr<OpenAllEntriesContext> entries_context, | 232 void MatchAllDidQueryCache( |
215 CacheStorageError error); | 233 const ResponsesCallback& callback, |
216 void MatchAllProcessNextEntry(std::unique_ptr<MatchAllContext> context, | 234 CacheStorageError error, |
217 const Entries::iterator& iter); | 235 std::unique_ptr<QueryCacheResults> query_cache_results); |
218 void MatchAllDidReadMetadata(std::unique_ptr<MatchAllContext> context, | |
219 const Entries::iterator& iter, | |
220 std::unique_ptr<CacheMetadata> metadata); | |
221 | 236 |
222 // WriteSideData callbacks | 237 // WriteSideData callbacks |
223 void WriteSideDataDidGetQuota(const ErrorCallback& callback, | 238 void WriteSideDataDidGetQuota(const ErrorCallback& callback, |
224 const GURL& url, | 239 const GURL& url, |
225 base::Time expected_response_time, | 240 base::Time expected_response_time, |
226 scoped_refptr<net::IOBuffer> buffer, | 241 scoped_refptr<net::IOBuffer> buffer, |
227 int buf_len, | 242 int buf_len, |
228 storage::QuotaStatusCode status_code, | 243 storage::QuotaStatusCode status_code, |
229 int64_t usage, | 244 int64_t usage, |
230 int64_t quota); | 245 int64_t quota); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 std::unique_ptr<OpenAllEntriesContext> entries_context, | 316 std::unique_ptr<OpenAllEntriesContext> entries_context, |
302 CacheStorageError error); | 317 CacheStorageError error); |
303 void DeleteDidOpenEntry(const GURL& origin, | 318 void DeleteDidOpenEntry(const GURL& origin, |
304 std::unique_ptr<ServiceWorkerFetchRequest> request, | 319 std::unique_ptr<ServiceWorkerFetchRequest> request, |
305 const CacheStorageCache::ErrorCallback& callback, | 320 const CacheStorageCache::ErrorCallback& callback, |
306 std::unique_ptr<disk_cache::Entry*> entryptr, | 321 std::unique_ptr<disk_cache::Entry*> entryptr, |
307 int rv); | 322 int rv); |
308 | 323 |
309 // Keys callbacks. | 324 // Keys callbacks. |
310 void KeysImpl(const RequestsCallback& callback); | 325 void KeysImpl(const RequestsCallback& callback); |
311 void KeysDidOpenAllEntries( | 326 void KeysDidQueryCache( |
312 const RequestsCallback& callback, | 327 const RequestsCallback& callback, |
313 std::unique_ptr<OpenAllEntriesContext> entries_context, | 328 CacheStorageError error, |
314 CacheStorageError error); | 329 std::unique_ptr<QueryCacheResults> query_cache_results); |
315 void KeysProcessNextEntry(std::unique_ptr<KeysContext> keys_context, | |
316 const Entries::iterator& iter); | |
317 void KeysDidReadMetadata(std::unique_ptr<KeysContext> keys_context, | |
318 const Entries::iterator& iter, | |
319 std::unique_ptr<CacheMetadata> metadata); | |
320 | 330 |
321 void CloseImpl(const base::Closure& callback); | 331 void CloseImpl(const base::Closure& callback); |
322 | 332 |
323 void SizeImpl(const SizeCallback& callback); | 333 void SizeImpl(const SizeCallback& callback); |
324 | 334 |
325 void GetSizeThenCloseDidGetSize(const SizeCallback& callback, | 335 void GetSizeThenCloseDidGetSize(const SizeCallback& callback, |
326 int64_t cache_size); | 336 int64_t cache_size); |
327 | 337 |
328 // Loads the backend and calls the callback with the result (true for | 338 // Loads the backend and calls the callback with the result (true for |
329 // success). The callback will always be called. Virtual for tests. | 339 // success). The callback will always be called. Virtual for tests. |
(...skipping 16 matching lines...) Expand all Loading... | |
346 std::unique_ptr<storage::BlobDataHandle> blob_data_handle); | 356 std::unique_ptr<storage::BlobDataHandle> blob_data_handle); |
347 void PendingResponsesCallback( | 357 void PendingResponsesCallback( |
348 const ResponsesCallback& callback, | 358 const ResponsesCallback& callback, |
349 CacheStorageError error, | 359 CacheStorageError error, |
350 std::unique_ptr<Responses> responses, | 360 std::unique_ptr<Responses> responses, |
351 std::unique_ptr<BlobDataHandles> blob_data_handles); | 361 std::unique_ptr<BlobDataHandles> blob_data_handles); |
352 void PendingRequestsCallback(const RequestsCallback& callback, | 362 void PendingRequestsCallback(const RequestsCallback& callback, |
353 CacheStorageError error, | 363 CacheStorageError error, |
354 std::unique_ptr<Requests> requests); | 364 std::unique_ptr<Requests> requests); |
355 void PendingSizeCallback(const SizeCallback& callback, int64_t size); | 365 void PendingSizeCallback(const SizeCallback& callback, int64_t size); |
366 // TODO(zino): Do we really need this? | |
367 void PendingQueryCacheResultsCallback( | |
nhiroki
2016/07/20 15:44:17
You may be able to avoid this pattern after jkarli
zino
2016/07/24 10:14:04
Done.
| |
368 const QueryCacheResultsCallback& callback, | |
369 CacheStorageError error, | |
370 std::unique_ptr<QueryCacheResults> results); | |
356 | 371 |
372 void PopulateRequestFromMetadata(const CacheMetadata& metadata, | |
373 ServiceWorkerFetchRequest* request); | |
357 void PopulateResponseMetadata(const CacheMetadata& metadata, | 374 void PopulateResponseMetadata(const CacheMetadata& metadata, |
358 ServiceWorkerResponse* response); | 375 ServiceWorkerResponse* response); |
359 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( | 376 std::unique_ptr<storage::BlobDataHandle> PopulateResponseBody( |
360 disk_cache::ScopedEntryPtr entry, | 377 disk_cache::ScopedEntryPtr entry, |
361 ServiceWorkerResponse* response); | 378 ServiceWorkerResponse* response); |
362 | 379 |
363 // Virtual for testing. | 380 // Virtual for testing. |
364 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); | 381 virtual std::unique_ptr<CacheStorageCacheHandle> CreateCacheHandle(); |
365 | 382 |
366 // Be sure to check |backend_state_| before use. | 383 // Be sure to check |backend_state_| before use. |
(...skipping 21 matching lines...) Expand all Loading... | |
388 bool memory_only_; | 405 bool memory_only_; |
389 | 406 |
390 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; | 407 base::WeakPtrFactory<CacheStorageCache> weak_ptr_factory_; |
391 | 408 |
392 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); | 409 DISALLOW_COPY_AND_ASSIGN(CacheStorageCache); |
393 }; | 410 }; |
394 | 411 |
395 } // namespace content | 412 } // namespace content |
396 | 413 |
397 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ | 414 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_CACHE_H_ |
OLD | NEW |