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

Unified Diff: content/browser/cache_storage/cache_storage_dispatcher_host.cc

Issue 1248003004: CacheStorage: Implement Cache.matchAll() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replace ScopedVector<BlobDataHandle> with scoped_ptr<std::vector<BlobDataHandle>> 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/cache_storage/cache_storage_dispatcher_host.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/cache_storage/cache_storage_dispatcher_host.cc
diff --git a/content/browser/cache_storage/cache_storage_dispatcher_host.cc b/content/browser/cache_storage/cache_storage_dispatcher_host.cc
index 79d3f5a884033aab3533b9edcdef23d565608aa0..c0b4b76fa45e5d0827b0df54b00aa4d732cc29a3 100644
--- a/content/browser/cache_storage/cache_storage_dispatcher_host.cc
+++ b/content/browser/cache_storage/cache_storage_dispatcher_host.cc
@@ -203,9 +203,29 @@ void CacheStorageDispatcherHost::OnCacheMatchAll(
int cache_id,
const ServiceWorkerFetchRequest& request,
const CacheStorageCacheQueryParams& match_params) {
- // TODO(gavinp,jkarlin): Implement this method.
- Send(new CacheStorageMsg_CacheMatchAllError(
- thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented));
+ IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
+ if (it == id_to_cache_map_.end()) {
+ Send(new CacheStorageMsg_CacheMatchError(
+ thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
+ return;
+ }
+
+ scoped_refptr<CacheStorageCache> cache = it->second;
+ if (request.url.is_empty()) {
+ cache->MatchAll(
+ base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this,
+ thread_id, request_id, cache));
+ return;
+ }
+
+ scoped_ptr<ServiceWorkerFetchRequest> scoped_request(
+ new ServiceWorkerFetchRequest(request.url, request.method,
+ request.headers, request.referrer,
+ request.is_reload));
+ cache->Match(
+ scoped_request.Pass(),
+ base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter,
+ this, thread_id, request_id, cache));
}
void CacheStorageDispatcherHost::OnCacheKeys(
@@ -330,7 +350,7 @@ void CacheStorageDispatcherHost::OnCacheStorageMatchCallback(
}
if (blob_data_handle)
- StoreBlobDataHandle(blob_data_handle.Pass());
+ StoreBlobDataHandle(*blob_data_handle);
Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id,
*response));
@@ -350,11 +370,52 @@ void CacheStorageDispatcherHost::OnCacheMatchCallback(
}
if (blob_data_handle)
- StoreBlobDataHandle(blob_data_handle.Pass());
+ StoreBlobDataHandle(*blob_data_handle);
Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response));
}
+void CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter(
+ int thread_id,
+ int request_id,
+ const scoped_refptr<CacheStorageCache>& cache,
+ CacheStorageError error,
+ scoped_ptr<ServiceWorkerResponse> response,
+ scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
+ scoped_ptr<CacheStorageCache::Responses> responses(
+ new CacheStorageCache::Responses);
+ scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles(
+ new CacheStorageCache::BlobDataHandles);
+ if (error == CACHE_STORAGE_OK) {
+ DCHECK(response);
+ responses->push_back(*response);
+ if (blob_data_handle)
+ blob_data_handles->push_back(*blob_data_handle);
+ }
+ OnCacheMatchAllCallback(thread_id, request_id, cache, error, responses.Pass(),
+ blob_data_handles.Pass());
+}
+
+void CacheStorageDispatcherHost::OnCacheMatchAllCallback(
+ int thread_id,
+ int request_id,
+ const scoped_refptr<CacheStorageCache>& cache,
+ CacheStorageError error,
+ scoped_ptr<CacheStorageCache::Responses> responses,
+ scoped_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) {
+ if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) {
+ Send(new CacheStorageMsg_CacheMatchAllError(
+ thread_id, request_id, ToWebServiceWorkerCacheError(error)));
+ return;
+ }
+
+ for (const storage::BlobDataHandle& handle : *blob_data_handles)
+ StoreBlobDataHandle(handle);
+
+ Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id,
+ *responses));
+}
+
void CacheStorageDispatcherHost::OnCacheKeysCallback(
int thread_id,
int request_id,
@@ -406,15 +467,14 @@ void CacheStorageDispatcherHost::DropCacheReference(CacheID cache_id) {
}
void CacheStorageDispatcherHost::StoreBlobDataHandle(
- scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
- DCHECK(blob_data_handle);
+ const storage::BlobDataHandle& blob_data_handle) {
std::pair<UUIDToBlobDataHandleList::iterator, bool> rv =
blob_handle_store_.insert(std::make_pair(
- blob_data_handle->uuid(), std::list<storage::BlobDataHandle>()));
- rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle));
+ blob_data_handle.uuid(), std::list<storage::BlobDataHandle>()));
+ rv.first->second.push_front(storage::BlobDataHandle(blob_data_handle));
}
-void CacheStorageDispatcherHost::DropBlobDataHandle(std::string uuid) {
+void CacheStorageDispatcherHost::DropBlobDataHandle(const std::string& uuid) {
UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid);
if (it == blob_handle_store_.end())
return;
« no previous file with comments | « content/browser/cache_storage/cache_storage_dispatcher_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698