| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 Send(new CacheStorageMsg_CacheMatchError( | 220 Send(new CacheStorageMsg_CacheMatchError( |
| 221 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 221 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 scoped_refptr<CacheStorageCache> cache = it->second; | 225 scoped_refptr<CacheStorageCache> cache = it->second; |
| 226 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( | 226 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 227 new ServiceWorkerFetchRequest(request.url, request.method, | 227 new ServiceWorkerFetchRequest(request.url, request.method, |
| 228 request.headers, request.referrer, | 228 request.headers, request.referrer, |
| 229 request.is_reload)); | 229 request.is_reload)); |
| 230 | 230 cache->Match(std::move(scoped_request), |
| 231 cache->Match( | 231 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, |
| 232 std::move(scoped_request), | 232 this, thread_id, request_id, cache)); |
| 233 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchCallback, this, | |
| 234 thread_id, request_id, StoreCacheReference(cache))); | |
| 235 } | 233 } |
| 236 | 234 |
| 237 void CacheStorageDispatcherHost::OnCacheMatchAll( | 235 void CacheStorageDispatcherHost::OnCacheMatchAll( |
| 238 int thread_id, | 236 int thread_id, |
| 239 int request_id, | 237 int request_id, |
| 240 int cache_id, | 238 int cache_id, |
| 241 const ServiceWorkerFetchRequest& request, | 239 const ServiceWorkerFetchRequest& request, |
| 242 const CacheStorageCacheQueryParams& match_params) { | 240 const CacheStorageCacheQueryParams& match_params) { |
| 243 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 241 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
| 244 if (it == id_to_cache_map_.end()) { | 242 if (it == id_to_cache_map_.end()) { |
| 245 Send(new CacheStorageMsg_CacheMatchError( | 243 Send(new CacheStorageMsg_CacheMatchError( |
| 246 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 244 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 247 return; | 245 return; |
| 248 } | 246 } |
| 249 | 247 |
| 250 scoped_refptr<CacheStorageCache> cache = it->second; | 248 scoped_refptr<CacheStorageCache> cache = it->second; |
| 251 if (request.url.is_empty()) { | 249 if (request.url.is_empty()) { |
| 252 cache->MatchAll( | 250 cache->MatchAll( |
| 253 std::unique_ptr<ServiceWorkerFetchRequest>(), match_params, | 251 std::unique_ptr<ServiceWorkerFetchRequest>(), match_params, |
| 254 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, | 252 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, |
| 255 thread_id, request_id, StoreCacheReference(cache))); | 253 thread_id, request_id, cache)); |
| 256 return; | 254 return; |
| 257 } | 255 } |
| 258 | 256 |
| 259 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( | 257 std::unique_ptr<ServiceWorkerFetchRequest> scoped_request( |
| 260 new ServiceWorkerFetchRequest(request.url, request.method, | 258 new ServiceWorkerFetchRequest(request.url, request.method, |
| 261 request.headers, request.referrer, | 259 request.headers, request.referrer, |
| 262 request.is_reload)); | 260 request.is_reload)); |
| 263 if (match_params.ignore_search) { | 261 if (match_params.ignore_search) { |
| 264 cache->MatchAll( | 262 cache->MatchAll( |
| 265 std::move(scoped_request), match_params, | 263 std::move(scoped_request), match_params, |
| 266 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, | 264 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallback, this, |
| 267 thread_id, request_id, StoreCacheReference(cache))); | 265 thread_id, request_id, cache)); |
| 268 return; | 266 return; |
| 269 } | 267 } |
| 270 cache->Match( | 268 cache->Match( |
| 271 std::move(scoped_request), | 269 std::move(scoped_request), |
| 272 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter, | 270 base::Bind(&CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter, |
| 273 this, thread_id, request_id, StoreCacheReference(cache))); | 271 this, thread_id, request_id, cache)); |
| 274 } | 272 } |
| 275 | 273 |
| 276 void CacheStorageDispatcherHost::OnCacheKeys( | 274 void CacheStorageDispatcherHost::OnCacheKeys( |
| 277 int thread_id, | 275 int thread_id, |
| 278 int request_id, | 276 int request_id, |
| 279 int cache_id, | 277 int cache_id, |
| 280 const ServiceWorkerFetchRequest& request, | 278 const ServiceWorkerFetchRequest& request, |
| 281 const CacheStorageCacheQueryParams& match_params) { | 279 const CacheStorageCacheQueryParams& match_params) { |
| 282 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 280 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
| 283 if (it == id_to_cache_map_.end()) { | 281 if (it == id_to_cache_map_.end()) { |
| 284 Send(new CacheStorageMsg_CacheKeysError( | 282 Send(new CacheStorageMsg_CacheKeysError( |
| 285 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 283 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 286 return; | 284 return; |
| 287 } | 285 } |
| 288 | 286 |
| 289 scoped_refptr<CacheStorageCache> cache = it->second; | 287 scoped_refptr<CacheStorageCache> cache = it->second; |
| 290 | 288 |
| 291 cache->Keys(base::Bind(&CacheStorageDispatcherHost::OnCacheKeysCallback, this, | 289 cache->Keys(base::Bind(&CacheStorageDispatcherHost::OnCacheKeysCallback, this, |
| 292 thread_id, request_id, StoreCacheReference(cache))); | 290 thread_id, request_id, cache)); |
| 293 } | 291 } |
| 294 | 292 |
| 295 void CacheStorageDispatcherHost::OnCacheBatch( | 293 void CacheStorageDispatcherHost::OnCacheBatch( |
| 296 int thread_id, | 294 int thread_id, |
| 297 int request_id, | 295 int request_id, |
| 298 int cache_id, | 296 int cache_id, |
| 299 const std::vector<CacheStorageBatchOperation>& operations) { | 297 const std::vector<CacheStorageBatchOperation>& operations) { |
| 300 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); | 298 IDToCacheMap::iterator it = id_to_cache_map_.find(cache_id); |
| 301 if (it == id_to_cache_map_.end()) { | 299 if (it == id_to_cache_map_.end()) { |
| 302 Send(new CacheStorageMsg_CacheBatchError( | 300 Send(new CacheStorageMsg_CacheBatchError( |
| 303 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); | 301 thread_id, request_id, blink::WebServiceWorkerCacheErrorNotFound)); |
| 304 return; | 302 return; |
| 305 } | 303 } |
| 306 scoped_refptr<CacheStorageCache> cache = it->second; | 304 scoped_refptr<CacheStorageCache> cache = it->second; |
| 307 cache->BatchOperation( | 305 cache->BatchOperation( |
| 308 operations, | 306 operations, base::Bind(&CacheStorageDispatcherHost::OnCacheBatchCallback, |
| 309 base::Bind(&CacheStorageDispatcherHost::OnCacheBatchCallback, this, | 307 this, thread_id, request_id, cache)); |
| 310 thread_id, request_id, StoreCacheReference(cache))); | |
| 311 } | 308 } |
| 312 | 309 |
| 313 void CacheStorageDispatcherHost::OnCacheClosed(int cache_id) { | 310 void CacheStorageDispatcherHost::OnCacheClosed(int cache_id) { |
| 314 DropCacheReference(cache_id); | 311 DropCacheReference(cache_id); |
| 315 } | 312 } |
| 316 | 313 |
| 317 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) { | 314 void CacheStorageDispatcherHost::OnBlobDataHandled(const std::string& uuid) { |
| 318 DropBlobDataHandle(uuid); | 315 DropBlobDataHandle(uuid); |
| 319 } | 316 } |
| 320 | 317 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 if (blob_data_handle) | 395 if (blob_data_handle) |
| 399 StoreBlobDataHandle(*blob_data_handle); | 396 StoreBlobDataHandle(*blob_data_handle); |
| 400 | 397 |
| 401 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, | 398 Send(new CacheStorageMsg_CacheStorageMatchSuccess(thread_id, request_id, |
| 402 *response)); | 399 *response)); |
| 403 } | 400 } |
| 404 | 401 |
| 405 void CacheStorageDispatcherHost::OnCacheMatchCallback( | 402 void CacheStorageDispatcherHost::OnCacheMatchCallback( |
| 406 int thread_id, | 403 int thread_id, |
| 407 int request_id, | 404 int request_id, |
| 408 CacheID cache_id, | 405 scoped_refptr<CacheStorageCache> cache, |
| 409 CacheStorageError error, | 406 CacheStorageError error, |
| 410 std::unique_ptr<ServiceWorkerResponse> response, | 407 std::unique_ptr<ServiceWorkerResponse> response, |
| 411 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { | 408 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 412 DropCacheReference(cache_id); | |
| 413 if (error != CACHE_STORAGE_OK) { | 409 if (error != CACHE_STORAGE_OK) { |
| 414 Send(new CacheStorageMsg_CacheMatchError( | 410 Send(new CacheStorageMsg_CacheMatchError( |
| 415 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 411 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 416 return; | 412 return; |
| 417 } | 413 } |
| 418 | 414 |
| 419 if (blob_data_handle) | 415 if (blob_data_handle) |
| 420 StoreBlobDataHandle(*blob_data_handle); | 416 StoreBlobDataHandle(*blob_data_handle); |
| 421 | 417 |
| 422 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); | 418 Send(new CacheStorageMsg_CacheMatchSuccess(thread_id, request_id, *response)); |
| 423 } | 419 } |
| 424 | 420 |
| 425 void CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter( | 421 void CacheStorageDispatcherHost::OnCacheMatchAllCallbackAdapter( |
| 426 int thread_id, | 422 int thread_id, |
| 427 int request_id, | 423 int request_id, |
| 428 CacheID cache_id, | 424 scoped_refptr<CacheStorageCache> cache, |
| 429 CacheStorageError error, | 425 CacheStorageError error, |
| 430 std::unique_ptr<ServiceWorkerResponse> response, | 426 std::unique_ptr<ServiceWorkerResponse> response, |
| 431 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { | 427 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 432 std::unique_ptr<CacheStorageCache::Responses> responses( | 428 std::unique_ptr<CacheStorageCache::Responses> responses( |
| 433 new CacheStorageCache::Responses); | 429 new CacheStorageCache::Responses); |
| 434 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles( | 430 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles( |
| 435 new CacheStorageCache::BlobDataHandles); | 431 new CacheStorageCache::BlobDataHandles); |
| 436 if (error == CACHE_STORAGE_OK) { | 432 if (error == CACHE_STORAGE_OK) { |
| 437 DCHECK(response); | 433 DCHECK(response); |
| 438 responses->push_back(*response); | 434 responses->push_back(*response); |
| 439 if (blob_data_handle) | 435 if (blob_data_handle) |
| 440 blob_data_handles->push_back(*blob_data_handle); | 436 blob_data_handles->push_back(*blob_data_handle); |
| 441 } | 437 } |
| 442 OnCacheMatchAllCallback(thread_id, request_id, cache_id, error, | 438 OnCacheMatchAllCallback(thread_id, request_id, std::move(cache), error, |
| 443 std::move(responses), std::move(blob_data_handles)); | 439 std::move(responses), std::move(blob_data_handles)); |
| 444 } | 440 } |
| 445 | 441 |
| 446 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( | 442 void CacheStorageDispatcherHost::OnCacheMatchAllCallback( |
| 447 int thread_id, | 443 int thread_id, |
| 448 int request_id, | 444 int request_id, |
| 449 CacheID cache_id, | 445 scoped_refptr<CacheStorageCache> cache, |
| 450 CacheStorageError error, | 446 CacheStorageError error, |
| 451 std::unique_ptr<CacheStorageCache::Responses> responses, | 447 std::unique_ptr<CacheStorageCache::Responses> responses, |
| 452 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) { | 448 std::unique_ptr<CacheStorageCache::BlobDataHandles> blob_data_handles) { |
| 453 DropCacheReference(cache_id); | |
| 454 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) { | 449 if (error != CACHE_STORAGE_OK && error != CACHE_STORAGE_ERROR_NOT_FOUND) { |
| 455 Send(new CacheStorageMsg_CacheMatchAllError( | 450 Send(new CacheStorageMsg_CacheMatchAllError( |
| 456 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 451 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 457 return; | 452 return; |
| 458 } | 453 } |
| 459 | 454 |
| 460 for (const storage::BlobDataHandle& handle : *blob_data_handles) | 455 for (const storage::BlobDataHandle& handle : *blob_data_handles) |
| 461 StoreBlobDataHandle(handle); | 456 StoreBlobDataHandle(handle); |
| 462 | 457 |
| 463 Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id, | 458 Send(new CacheStorageMsg_CacheMatchAllSuccess(thread_id, request_id, |
| 464 *responses)); | 459 *responses)); |
| 465 } | 460 } |
| 466 | 461 |
| 467 void CacheStorageDispatcherHost::OnCacheKeysCallback( | 462 void CacheStorageDispatcherHost::OnCacheKeysCallback( |
| 468 int thread_id, | 463 int thread_id, |
| 469 int request_id, | 464 int request_id, |
| 470 CacheID cache_id, | 465 scoped_refptr<CacheStorageCache> cache, |
| 471 CacheStorageError error, | 466 CacheStorageError error, |
| 472 std::unique_ptr<CacheStorageCache::Requests> requests) { | 467 std::unique_ptr<CacheStorageCache::Requests> requests) { |
| 473 DropCacheReference(cache_id); | |
| 474 if (error != CACHE_STORAGE_OK) { | 468 if (error != CACHE_STORAGE_OK) { |
| 475 Send(new CacheStorageMsg_CacheKeysError( | 469 Send(new CacheStorageMsg_CacheKeysError( |
| 476 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 470 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 477 return; | 471 return; |
| 478 } | 472 } |
| 479 | 473 |
| 480 CacheStorageCache::Requests out; | 474 CacheStorageCache::Requests out; |
| 481 | 475 |
| 482 for (CacheStorageCache::Requests::const_iterator it = requests->begin(); | 476 for (CacheStorageCache::Requests::const_iterator it = requests->begin(); |
| 483 it != requests->end(); ++it) { | 477 it != requests->end(); ++it) { |
| 484 ServiceWorkerFetchRequest request(it->url, it->method, it->headers, | 478 ServiceWorkerFetchRequest request(it->url, it->method, it->headers, |
| 485 it->referrer, it->is_reload); | 479 it->referrer, it->is_reload); |
| 486 out.push_back(request); | 480 out.push_back(request); |
| 487 } | 481 } |
| 488 | 482 |
| 489 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out)); | 483 Send(new CacheStorageMsg_CacheKeysSuccess(thread_id, request_id, out)); |
| 490 } | 484 } |
| 491 | 485 |
| 492 void CacheStorageDispatcherHost::OnCacheBatchCallback(int thread_id, | 486 void CacheStorageDispatcherHost::OnCacheBatchCallback( |
| 493 int request_id, | 487 int thread_id, |
| 494 CacheID cache_id, | 488 int request_id, |
| 495 CacheStorageError error) { | 489 scoped_refptr<CacheStorageCache> cache, |
| 496 DropCacheReference(cache_id); | 490 CacheStorageError error) { |
| 497 if (error != CACHE_STORAGE_OK) { | 491 if (error != CACHE_STORAGE_OK) { |
| 498 Send(new CacheStorageMsg_CacheBatchError( | 492 Send(new CacheStorageMsg_CacheBatchError( |
| 499 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 493 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 500 return; | 494 return; |
| 501 } | 495 } |
| 502 | 496 |
| 503 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id)); | 497 Send(new CacheStorageMsg_CacheBatchSuccess(thread_id, request_id)); |
| 504 } | 498 } |
| 505 | 499 |
| 506 CacheStorageDispatcherHost::CacheID | 500 CacheStorageDispatcherHost::CacheID |
| (...skipping 20 matching lines...) Expand all Loading... |
| 527 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 521 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
| 528 if (it == blob_handle_store_.end()) | 522 if (it == blob_handle_store_.end()) |
| 529 return; | 523 return; |
| 530 DCHECK(!it->second.empty()); | 524 DCHECK(!it->second.empty()); |
| 531 it->second.pop_front(); | 525 it->second.pop_front(); |
| 532 if (it->second.empty()) | 526 if (it->second.empty()) |
| 533 blob_handle_store_.erase(it); | 527 blob_handle_store_.erase(it); |
| 534 } | 528 } |
| 535 | 529 |
| 536 } // namespace content | 530 } // namespace content |
| OLD | NEW |