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

Side by Side 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: incorporate review comments 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "content/browser/cache_storage/cache_storage_dispatcher_host.h" 5 #include "content/browser/cache_storage/cache_storage_dispatcher_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, 196 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback,
197 this, thread_id, request_id, cache)); 197 this, thread_id, request_id, cache));
198 } 198 }
199 199
200 void CacheStorageDispatcherHost::OnCacheMatchAll( 200 void CacheStorageDispatcherHost::OnCacheMatchAll(
201 int thread_id, 201 int thread_id,
202 int request_id, 202 int request_id,
203 int cache_id, 203 int cache_id,
204 const ServiceWorkerFetchRequest& request, 204 const ServiceWorkerFetchRequest& request,
205 const CacheStorageCacheQueryParams& match_params) { 205 const CacheStorageCacheQueryParams& match_params) {
206 // TODO(gavinp,jkarlin): Implement this method. 206 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
207 Send(new CacheStorageMsg_CacheMatchAllError( 207 if (it == id_to_cache_map_.end()) {
208 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotImplemented)); 208 Send(new CacheStorageMsg_CacheMatchError(
209 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound));
210 return;
211 }
212
213 scoped_refptr<CacheStorageCache> cache = it->second;
214 if (request.url.is_empty()) {
215 cache->MatchAll(
216 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this,
217 thread_id, request_id, cache));
218 return;
219 }
220
221 scoped_ptr<ServiceWorkerFetchRequest> scoped_request(
222 new ServiceWorkerFetchRequest(request.url, request.method,
223 request.headers, request.referrer,
224 request.is_reload));
225 cache->Match(
226 scoped_request.Pass(),
227 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter,
228 this, thread_id, request_id, cache));
209 } 229 }
210 230
211 void CacheStorageDispatcherHost::OnCacheKeys( 231 void CacheStorageDispatcherHost::OnCacheKeys(
212 int thread_id, 232 int thread_id,
213 int request_id, 233 int request_id,
214 int cache_id, 234 int cache_id,
215 const ServiceWorkerFetchRequest& request, 235 const ServiceWorkerFetchRequest& request,
216 const CacheStorageCacheQueryParams& match_params) { 236 const CacheStorageCacheQueryParams& match_params) {
217 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); 237 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id);
218 if (it == id_to_cache_map_.end()) { 238 if (it == id_to_cache_map_.end()) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 368 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
349 return; 369 return;
350 } 370 }
351 371
352 if (blob_data_handle) 372 if (blob_data_handle)
353 StoreBlobDataHandle(blob_data_handle.Pass()); 373 StoreBlobDataHandle(blob_data_handle.Pass());
354 374
355 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); 375 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response));
356 } 376 }
357 377
378 void CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter(
379 int thread_id,
380 int request_id,
381 const scoped_refptr<CacheStorageCache>& cache,
382 CacheStorageError error,
383 scoped_ptr<ServiceWorkerResponse> response,
384 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
385 scoped_ptr<std::vector<ServiceWorkerResponse>> responses(
386 new std::vector<ServiceWorkerResponse>);
387 ScopedVector<storage::BlobDataHandle> blob_data_handles;
388 if (error == CACHE_STORAGE_OK) {
389 DCHECK(response);
390 responses->push_back(*response);
391 blob_data_handles.push_back(blob_data_handle.release());
392 }
393 OnCacheMatchAllCallback(thread_id, request_id, cache, error, responses.Pass(),
394 blob_data_handles.Pass());
395 }
396
397 void CacheStorageDispatcherHost::OnCacheMatchAllCallback(
398 int thread_id,
399 int request_id,
400 const scoped_refptr<CacheStorageCache>& cache,
401 CacheStorageError error,
402 scoped_ptr<std::vector<ServiceWorkerResponse>> responses,
403 ScopedVector<storage::BlobDataHandle> blob_data_handles) {
404 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) {
405 Send(new CacheStorageMsg_CacheMatchAllError(
406 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
407 return;
408 }
409
410 for (storage::BlobDataHandle* handle : blob_data_handles) {
411 if (handle)
412 StoreBlobDataHandle(make_scoped_ptr(handle));
413 }
414 blob_data_handles.weak_clear();
415
416 Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id,
417 *responses));
418 }
419
358 void CacheStorageDispatcherHost::OnCacheKeysCallback( 420 void CacheStorageDispatcherHost::OnCacheKeysCallback(
359 int thread_id, 421 int thread_id,
360 int request_id, 422 int request_id,
361 const scoped_refptr<CacheStorageCache>& cache, 423 const scoped_refptr<CacheStorageCache>& cache,
362 CacheStorageError error, 424 CacheStorageError error,
363 scoped_ptr<CacheStorageCache::Requests> requests) { 425 scoped_ptr<CacheStorageCache::Requests> requests) {
364 if (error != CACHE_STORAGE_OK) { 426 if (error != CACHE_STORAGE_OK) {
365 Send(new CacheStorageMsg_CacheKeysError( 427 Send(new CacheStorageMsg_CacheKeysError(
366 thread_id, request_id, ToWebServiceWorkerCacheError(error))); 428 thread_id, request_id, ToWebServiceWorkerCacheError(error)));
367 return; 429 return;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 469
408 void CacheStorageDispatcherHost::StoreBlobDataHandle( 470 void CacheStorageDispatcherHost::StoreBlobDataHandle(
409 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 471 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
410 DCHECK(blob_data_handle); 472 DCHECK(blob_data_handle);
411 std::pair<UUIDToBlobDataHandleList::iterator, bool> rv = 473 std::pair<UUIDToBlobDataHandleList::iterator, bool> rv =
412 blob_handle_store_.insert(std::make_pair( 474 blob_handle_store_.insert(std::make_pair(
413 blob_data_handle->uuid(), std::list<storage::BlobDataHandle>())); 475 blob_data_handle->uuid(), std::list<storage::BlobDataHandle>()));
414 rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle)); 476 rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle));
415 } 477 }
416 478
417 void CacheStorageDispatcherHost::DropBlobDataHandle(std::string uuid) { 479 void CacheStorageDispatcherHost::DropBlobDataHandle(const std::string& uuid) {
418 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); 480 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid);
419 if (it == blob_handle_store_.end()) 481 if (it == blob_handle_store_.end())
420 return; 482 return;
421 DCHECK(!it->second.empty()); 483 DCHECK(!it->second.empty());
422 it->second.pop_front(); 484 it->second.pop_front();
423 if (it->second.empty()) 485 if (it->second.empty())
424 blob_handle_store_.erase(it); 486 blob_handle_store_.erase(it);
425 } 487 }
426 488
427 } // namespace content 489 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698