| 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 #include "content/renderer/cache_storage/cache_storage_dispatcher.h" | 5 #include "content/renderer/cache_storage/cache_storage_dispatcher.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 operation.response = ResponseFromWebResponse(web_operation.response); | 119 operation.response = ResponseFromWebResponse(web_operation.response); |
| 120 operation.match_params = | 120 operation.match_params = |
| 121 QueryParamsFromWebQueryParams(web_operation.matchParams); | 121 QueryParamsFromWebQueryParams(web_operation.matchParams); |
| 122 return operation; | 122 return operation; |
| 123 } | 123 } |
| 124 | 124 |
| 125 template <typename T> | 125 template <typename T> |
| 126 void ClearCallbacksMapWithErrors(T* callbacks_map) { | 126 void ClearCallbacksMapWithErrors(T* callbacks_map) { |
| 127 typename T::iterator iter(callbacks_map); | 127 typename T::iterator iter(callbacks_map); |
| 128 while (!iter.IsAtEnd()) { | 128 while (!iter.IsAtEnd()) { |
| 129 #ifdef CRBUG_494884 | |
| 130 iter.GetCurrentValue()->onError( | 129 iter.GetCurrentValue()->onError( |
| 131 new blink::WebServiceWorkerCacheError( | 130 new blink::WebServiceWorkerCacheError( |
| 132 blink::WebServiceWorkerCacheErrorNotFound)); | 131 blink::WebServiceWorkerCacheErrorNotFound)); |
| 133 #else | |
| 134 blink::WebServiceWorkerCacheError reason = | |
| 135 blink::WebServiceWorkerCacheErrorNotFound; | |
| 136 iter.GetCurrentValue()->onError(&reason); | |
| 137 #endif | |
| 138 callbacks_map->Remove(iter.GetCurrentKey()); | 132 callbacks_map->Remove(iter.GetCurrentKey()); |
| 139 iter.Advance(); | 133 iter.Advance(); |
| 140 } | 134 } |
| 141 } | 135 } |
| 142 | 136 |
| 143 } // namespace | 137 } // namespace |
| 144 | 138 |
| 145 // The WebCache object is the Chromium side implementation of the Blink | 139 // The WebCache object is the Chromium side implementation of the Blink |
| 146 // WebServiceWorkerCache API. Most of its methods delegate directly to the | 140 // WebServiceWorkerCache API. Most of its methods delegate directly to the |
| 147 // ServiceWorkerStorage object, which is able to assign unique IDs as well | 141 // ServiceWorkerStorage object, which is able to assign unique IDs as well |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 match_times_.erase(request_id); | 348 match_times_.erase(request_id); |
| 355 } | 349 } |
| 356 | 350 |
| 357 void CacheStorageDispatcher::OnCacheStorageHasError( | 351 void CacheStorageDispatcher::OnCacheStorageHasError( |
| 358 int thread_id, | 352 int thread_id, |
| 359 int request_id, | 353 int request_id, |
| 360 blink::WebServiceWorkerCacheError reason) { | 354 blink::WebServiceWorkerCacheError reason) { |
| 361 DCHECK_EQ(thread_id, CurrentWorkerId()); | 355 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 362 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = | 356 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = |
| 363 has_callbacks_.Lookup(request_id); | 357 has_callbacks_.Lookup(request_id); |
| 364 #ifdef CRBUG_494884 | |
| 365 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 358 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 366 #else | |
| 367 callbacks->onError(&reason); | |
| 368 #endif | |
| 369 has_callbacks_.Remove(request_id); | 359 has_callbacks_.Remove(request_id); |
| 370 has_times_.erase(request_id); | 360 has_times_.erase(request_id); |
| 371 } | 361 } |
| 372 | 362 |
| 373 void CacheStorageDispatcher::OnCacheStorageOpenError( | 363 void CacheStorageDispatcher::OnCacheStorageOpenError( |
| 374 int thread_id, | 364 int thread_id, |
| 375 int request_id, | 365 int request_id, |
| 376 blink::WebServiceWorkerCacheError reason) { | 366 blink::WebServiceWorkerCacheError reason) { |
| 377 DCHECK_EQ(thread_id, CurrentWorkerId()); | 367 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 378 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks = | 368 WebServiceWorkerCacheStorage::CacheStorageWithCacheCallbacks* callbacks = |
| 379 open_callbacks_.Lookup(request_id); | 369 open_callbacks_.Lookup(request_id); |
| 380 #ifdef CRBUG_494884 | |
| 381 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 370 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 382 #else | |
| 383 callbacks->onError(&reason); | |
| 384 #endif | |
| 385 open_callbacks_.Remove(request_id); | 371 open_callbacks_.Remove(request_id); |
| 386 open_times_.erase(request_id); | 372 open_times_.erase(request_id); |
| 387 } | 373 } |
| 388 | 374 |
| 389 void CacheStorageDispatcher::OnCacheStorageDeleteError( | 375 void CacheStorageDispatcher::OnCacheStorageDeleteError( |
| 390 int thread_id, | 376 int thread_id, |
| 391 int request_id, | 377 int request_id, |
| 392 blink::WebServiceWorkerCacheError reason) { | 378 blink::WebServiceWorkerCacheError reason) { |
| 393 DCHECK_EQ(thread_id, CurrentWorkerId()); | 379 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 394 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = | 380 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks = |
| 395 delete_callbacks_.Lookup(request_id); | 381 delete_callbacks_.Lookup(request_id); |
| 396 #ifdef CRBUG_494884 | |
| 397 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 382 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 398 #else | |
| 399 callbacks->onError(&reason); | |
| 400 #endif | |
| 401 delete_callbacks_.Remove(request_id); | 383 delete_callbacks_.Remove(request_id); |
| 402 delete_times_.erase(request_id); | 384 delete_times_.erase(request_id); |
| 403 } | 385 } |
| 404 | 386 |
| 405 void CacheStorageDispatcher::OnCacheStorageKeysError( | 387 void CacheStorageDispatcher::OnCacheStorageKeysError( |
| 406 int thread_id, | 388 int thread_id, |
| 407 int request_id, | 389 int request_id, |
| 408 blink::WebServiceWorkerCacheError reason) { | 390 blink::WebServiceWorkerCacheError reason) { |
| 409 DCHECK_EQ(thread_id, CurrentWorkerId()); | 391 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 410 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks = | 392 WebServiceWorkerCacheStorage::CacheStorageKeysCallbacks* callbacks = |
| 411 keys_callbacks_.Lookup(request_id); | 393 keys_callbacks_.Lookup(request_id); |
| 412 #ifdef CRBUG_494884 | |
| 413 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 394 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 414 #else | |
| 415 callbacks->onError(&reason); | |
| 416 #endif | |
| 417 keys_callbacks_.Remove(request_id); | 395 keys_callbacks_.Remove(request_id); |
| 418 keys_times_.erase(request_id); | 396 keys_times_.erase(request_id); |
| 419 } | 397 } |
| 420 | 398 |
| 421 void CacheStorageDispatcher::OnCacheStorageMatchError( | 399 void CacheStorageDispatcher::OnCacheStorageMatchError( |
| 422 int thread_id, | 400 int thread_id, |
| 423 int request_id, | 401 int request_id, |
| 424 blink::WebServiceWorkerCacheError reason) { | 402 blink::WebServiceWorkerCacheError reason) { |
| 425 DCHECK_EQ(thread_id, CurrentWorkerId()); | 403 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 426 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks = | 404 WebServiceWorkerCacheStorage::CacheStorageMatchCallbacks* callbacks = |
| 427 match_callbacks_.Lookup(request_id); | 405 match_callbacks_.Lookup(request_id); |
| 428 #ifdef CRBUG_494884 | |
| 429 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 406 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 430 #else | |
| 431 callbacks->onError(&reason); | |
| 432 #endif | |
| 433 match_callbacks_.Remove(request_id); | 407 match_callbacks_.Remove(request_id); |
| 434 match_times_.erase(request_id); | 408 match_times_.erase(request_id); |
| 435 } | 409 } |
| 436 | 410 |
| 437 void CacheStorageDispatcher::OnCacheMatchSuccess( | 411 void CacheStorageDispatcher::OnCacheMatchSuccess( |
| 438 int thread_id, | 412 int thread_id, |
| 439 int request_id, | 413 int request_id, |
| 440 const ServiceWorkerResponse& response) { | 414 const ServiceWorkerResponse& response) { |
| 441 DCHECK_EQ(thread_id, CurrentWorkerId()); | 415 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 442 blink::WebServiceWorkerResponse web_response; | 416 blink::WebServiceWorkerResponse web_response; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 cache_batch_times_.erase(request_id); | 473 cache_batch_times_.erase(request_id); |
| 500 } | 474 } |
| 501 | 475 |
| 502 void CacheStorageDispatcher::OnCacheMatchError( | 476 void CacheStorageDispatcher::OnCacheMatchError( |
| 503 int thread_id, | 477 int thread_id, |
| 504 int request_id, | 478 int request_id, |
| 505 blink::WebServiceWorkerCacheError reason) { | 479 blink::WebServiceWorkerCacheError reason) { |
| 506 DCHECK_EQ(thread_id, CurrentWorkerId()); | 480 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 507 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = | 481 blink::WebServiceWorkerCache::CacheMatchCallbacks* callbacks = |
| 508 cache_match_callbacks_.Lookup(request_id); | 482 cache_match_callbacks_.Lookup(request_id); |
| 509 #ifdef CRBUG_494884 | |
| 510 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 483 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 511 #else | |
| 512 callbacks->onError(&reason); | |
| 513 #endif | |
| 514 cache_match_callbacks_.Remove(request_id); | 484 cache_match_callbacks_.Remove(request_id); |
| 515 cache_match_times_.erase(request_id); | 485 cache_match_times_.erase(request_id); |
| 516 } | 486 } |
| 517 | 487 |
| 518 void CacheStorageDispatcher::OnCacheMatchAllError( | 488 void CacheStorageDispatcher::OnCacheMatchAllError( |
| 519 int thread_id, | 489 int thread_id, |
| 520 int request_id, | 490 int request_id, |
| 521 blink::WebServiceWorkerCacheError reason) { | 491 blink::WebServiceWorkerCacheError reason) { |
| 522 DCHECK_EQ(thread_id, CurrentWorkerId()); | 492 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 523 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = | 493 blink::WebServiceWorkerCache::CacheWithResponsesCallbacks* callbacks = |
| 524 cache_match_all_callbacks_.Lookup(request_id); | 494 cache_match_all_callbacks_.Lookup(request_id); |
| 525 #ifdef CRBUG_494884 | |
| 526 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 495 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 527 #else | |
| 528 callbacks->onError(&reason); | |
| 529 #endif | |
| 530 cache_match_all_callbacks_.Remove(request_id); | 496 cache_match_all_callbacks_.Remove(request_id); |
| 531 cache_match_all_times_.erase(request_id); | 497 cache_match_all_times_.erase(request_id); |
| 532 } | 498 } |
| 533 | 499 |
| 534 void CacheStorageDispatcher::OnCacheKeysError( | 500 void CacheStorageDispatcher::OnCacheKeysError( |
| 535 int thread_id, | 501 int thread_id, |
| 536 int request_id, | 502 int request_id, |
| 537 blink::WebServiceWorkerCacheError reason) { | 503 blink::WebServiceWorkerCacheError reason) { |
| 538 DCHECK_EQ(thread_id, CurrentWorkerId()); | 504 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 539 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = | 505 blink::WebServiceWorkerCache::CacheWithRequestsCallbacks* callbacks = |
| 540 cache_keys_callbacks_.Lookup(request_id); | 506 cache_keys_callbacks_.Lookup(request_id); |
| 541 #ifdef CRBUG_494884 | |
| 542 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 507 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 543 #else | |
| 544 callbacks->onError(&reason); | |
| 545 #endif | |
| 546 cache_keys_callbacks_.Remove(request_id); | 508 cache_keys_callbacks_.Remove(request_id); |
| 547 cache_keys_times_.erase(request_id); | 509 cache_keys_times_.erase(request_id); |
| 548 } | 510 } |
| 549 | 511 |
| 550 void CacheStorageDispatcher::OnCacheBatchError( | 512 void CacheStorageDispatcher::OnCacheBatchError( |
| 551 int thread_id, | 513 int thread_id, |
| 552 int request_id, | 514 int request_id, |
| 553 blink::WebServiceWorkerCacheError reason) { | 515 blink::WebServiceWorkerCacheError reason) { |
| 554 DCHECK_EQ(thread_id, CurrentWorkerId()); | 516 DCHECK_EQ(thread_id, CurrentWorkerId()); |
| 555 blink::WebServiceWorkerCache::CacheBatchCallbacks* callbacks = | 517 blink::WebServiceWorkerCache::CacheBatchCallbacks* callbacks = |
| 556 cache_batch_callbacks_.Lookup(request_id); | 518 cache_batch_callbacks_.Lookup(request_id); |
| 557 #ifdef CRBUG_494884 | |
| 558 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); | 519 callbacks->onError(new blink::WebServiceWorkerCacheError(reason)); |
| 559 #else | |
| 560 callbacks->onError(&reason); | |
| 561 #endif | |
| 562 cache_batch_callbacks_.Remove(request_id); | 520 cache_batch_callbacks_.Remove(request_id); |
| 563 cache_batch_times_.erase(request_id); | 521 cache_batch_times_.erase(request_id); |
| 564 } | 522 } |
| 565 | 523 |
| 566 void CacheStorageDispatcher::dispatchHas( | 524 void CacheStorageDispatcher::dispatchHas( |
| 567 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, | 525 WebServiceWorkerCacheStorage::CacheStorageCallbacks* callbacks, |
| 568 const GURL& origin, | 526 const GURL& origin, |
| 569 const blink::WebString& cacheName) { | 527 const blink::WebString& cacheName) { |
| 570 int request_id = has_callbacks_.Add(callbacks); | 528 int request_id = has_callbacks_.Add(callbacks); |
| 571 has_times_[request_id] = base::TimeTicks::Now(); | 529 has_times_[request_id] = base::TimeTicks::Now(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 CacheStorageDispatcher::WebResponsesFromResponses( | 665 CacheStorageDispatcher::WebResponsesFromResponses( |
| 708 const std::vector<ServiceWorkerResponse>& responses) { | 666 const std::vector<ServiceWorkerResponse>& responses) { |
| 709 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( | 667 blink::WebVector<blink::WebServiceWorkerResponse> web_responses( |
| 710 responses.size()); | 668 responses.size()); |
| 711 for (size_t i = 0; i < responses.size(); ++i) | 669 for (size_t i = 0; i < responses.size(); ++i) |
| 712 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); | 670 PopulateWebResponseFromResponse(responses[i], &(web_responses[i])); |
| 713 return web_responses; | 671 return web_responses; |
| 714 } | 672 } |
| 715 | 673 |
| 716 } // namespace content | 674 } // namespace content |
| OLD | NEW |