OLD | NEW |
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 Loading... |
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 Loading... |
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 std::vector<ServiceWorkerResponse> responses; |
| 386 ScopedVector<storage::BlobDataHandle> blob_data_handles; |
| 387 if (error == CACHE_STORAGE_OK) { |
| 388 DCHECK(response); |
| 389 responses.push_back(*response); |
| 390 blob_data_handles.push_back(blob_data_handle.release()); |
| 391 } |
| 392 OnCacheMatchAllCallback(thread_id, request_id, cache, error, responses, |
| 393 blob_data_handles.Pass()); |
| 394 } |
| 395 |
| 396 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( |
| 397 int thread_id, |
| 398 int request_id, |
| 399 const scoped_refptr<CacheStorageCache>& cache, |
| 400 CacheStorageError error, |
| 401 const std::vector<ServiceWorkerResponse>& responses, |
| 402 ScopedVector<storage::BlobDataHandle> blob_data_handles) { |
| 403 if (error != CACHE_STORAGE_OK || error != CACHE_STORAGE_ERROR_NOT_FOUND) { |
| 404 Send(new CacheStorageMsg_CacheMatchAllError( |
| 405 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 406 return; |
| 407 } |
| 408 |
| 409 for (storage::BlobDataHandle* handle : blob_data_handles) { |
| 410 if (handle) |
| 411 StoreBlobDataHandle(make_scoped_ptr(handle)); |
| 412 } |
| 413 blob_data_handles.weak_clear(); |
| 414 |
| 415 Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id, |
| 416 responses)); |
| 417 } |
| 418 |
358 void CacheStorageDispatcherHost::OnCacheKeysCallback( | 419 void CacheStorageDispatcherHost::OnCacheKeysCallback( |
359 int thread_id, | 420 int thread_id, |
360 int request_id, | 421 int request_id, |
361 const scoped_refptr<CacheStorageCache>& cache, | 422 const scoped_refptr<CacheStorageCache>& cache, |
362 CacheStorageError error, | 423 CacheStorageError error, |
363 scoped_ptr<CacheStorageCache::Requests> requests) { | 424 scoped_ptr<CacheStorageCache::Requests> requests) { |
364 if (error != CACHE_STORAGE_OK) { | 425 if (error != CACHE_STORAGE_OK) { |
365 Send(new CacheStorageMsg_CacheKeysError( | 426 Send(new CacheStorageMsg_CacheKeysError( |
366 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 427 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
367 return; | 428 return; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 468 |
408 void CacheStorageDispatcherHost::StoreBlobDataHandle( | 469 void CacheStorageDispatcherHost::StoreBlobDataHandle( |
409 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 470 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
410 DCHECK(blob_data_handle); | 471 DCHECK(blob_data_handle); |
411 std::pair<UUIDToBlobDataHandleList::iterator, bool> rv = | 472 std::pair<UUIDToBlobDataHandleList::iterator, bool> rv = |
412 blob_handle_store_.insert(std::make_pair( | 473 blob_handle_store_.insert(std::make_pair( |
413 blob_data_handle->uuid(), std::list<storage::BlobDataHandle>())); | 474 blob_data_handle->uuid(), std::list<storage::BlobDataHandle>())); |
414 rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle)); | 475 rv.first->second.push_front(storage::BlobDataHandle(*blob_data_handle)); |
415 } | 476 } |
416 | 477 |
417 void CacheStorageDispatcherHost::DropBlobDataHandle(std::string uuid) { | 478 void CacheStorageDispatcherHost::DropBlobDataHandle(const std::string& uuid) { |
418 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 479 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
419 if (it == blob_handle_store_.end()) | 480 if (it == blob_handle_store_.end()) |
420 return; | 481 return; |
421 DCHECK(!it->second.empty()); | 482 DCHECK(!it->second.empty()); |
422 it->second.pop_front(); | 483 it->second.pop_front(); |
423 if (it->second.empty()) | 484 if (it->second.empty()) |
424 blob_handle_store_.erase(it); | 485 blob_handle_store_.erase(it); |
425 } | 486 } |
426 | 487 |
427 } // namespace content | 488 } // namespace content |
OLD | NEW |