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