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/browser/cache_storage/cache_storage.h" | 5 #include "content/browser/cache_storage/cache_storage.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 const CacheAndErrorCallback& callback) { | 514 const CacheAndErrorCallback& callback) { |
515 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 515 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
516 | 516 |
517 if (!initialized_) | 517 if (!initialized_) |
518 LazyInit(); | 518 LazyInit(); |
519 | 519 |
520 quota_manager_proxy_->NotifyStorageAccessed( | 520 quota_manager_proxy_->NotifyStorageAccessed( |
521 storage::QuotaClient::kServiceWorkerCache, origin_, | 521 storage::QuotaClient::kServiceWorkerCache, origin_, |
522 storage::kStorageTypeTemporary); | 522 storage::kStorageTypeTemporary); |
523 | 523 |
524 CacheAndErrorCallback pending_callback = | 524 scheduler_->ScheduleOperation( |
525 base::Bind(&CacheStorage::PendingCacheAndErrorCallback, | 525 base::Bind(&CacheStorage::OpenCacheImpl, weak_factory_.GetWeakPtr(), |
526 weak_factory_.GetWeakPtr(), callback); | 526 cache_name, scheduler_->WrapCallbackToRunNext(callback))); |
527 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::OpenCacheImpl, | |
528 weak_factory_.GetWeakPtr(), | |
529 cache_name, pending_callback)); | |
530 } | 527 } |
531 | 528 |
532 void CacheStorage::HasCache(const std::string& cache_name, | 529 void CacheStorage::HasCache(const std::string& cache_name, |
533 const BoolAndErrorCallback& callback) { | 530 const BoolAndErrorCallback& callback) { |
534 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 531 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
535 | 532 |
536 if (!initialized_) | 533 if (!initialized_) |
537 LazyInit(); | 534 LazyInit(); |
538 | 535 |
539 quota_manager_proxy_->NotifyStorageAccessed( | 536 quota_manager_proxy_->NotifyStorageAccessed( |
540 storage::QuotaClient::kServiceWorkerCache, origin_, | 537 storage::QuotaClient::kServiceWorkerCache, origin_, |
541 storage::kStorageTypeTemporary); | 538 storage::kStorageTypeTemporary); |
542 | 539 |
543 BoolAndErrorCallback pending_callback = | 540 scheduler_->ScheduleOperation( |
544 base::Bind(&CacheStorage::PendingBoolAndErrorCallback, | 541 base::Bind(&CacheStorage::HasCacheImpl, weak_factory_.GetWeakPtr(), |
545 weak_factory_.GetWeakPtr(), callback); | 542 cache_name, scheduler_->WrapCallbackToRunNext(callback))); |
546 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::HasCacheImpl, | |
547 weak_factory_.GetWeakPtr(), | |
548 cache_name, pending_callback)); | |
549 } | 543 } |
550 | 544 |
551 void CacheStorage::DeleteCache(const std::string& cache_name, | 545 void CacheStorage::DeleteCache(const std::string& cache_name, |
552 const BoolAndErrorCallback& callback) { | 546 const BoolAndErrorCallback& callback) { |
553 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 547 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
554 | 548 |
555 if (!initialized_) | 549 if (!initialized_) |
556 LazyInit(); | 550 LazyInit(); |
557 | 551 |
558 quota_manager_proxy_->NotifyStorageAccessed( | 552 quota_manager_proxy_->NotifyStorageAccessed( |
559 storage::QuotaClient::kServiceWorkerCache, origin_, | 553 storage::QuotaClient::kServiceWorkerCache, origin_, |
560 storage::kStorageTypeTemporary); | 554 storage::kStorageTypeTemporary); |
561 | 555 |
562 BoolAndErrorCallback pending_callback = | 556 scheduler_->ScheduleOperation( |
563 base::Bind(&CacheStorage::PendingBoolAndErrorCallback, | 557 base::Bind(&CacheStorage::DeleteCacheImpl, weak_factory_.GetWeakPtr(), |
564 weak_factory_.GetWeakPtr(), callback); | 558 cache_name, scheduler_->WrapCallbackToRunNext(callback))); |
565 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::DeleteCacheImpl, | |
566 weak_factory_.GetWeakPtr(), | |
567 cache_name, pending_callback)); | |
568 } | 559 } |
569 | 560 |
570 void CacheStorage::EnumerateCaches(const StringsAndErrorCallback& callback) { | 561 void CacheStorage::EnumerateCaches(const StringsAndErrorCallback& callback) { |
571 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 562 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
572 | 563 |
573 if (!initialized_) | 564 if (!initialized_) |
574 LazyInit(); | 565 LazyInit(); |
575 | 566 |
576 quota_manager_proxy_->NotifyStorageAccessed( | 567 quota_manager_proxy_->NotifyStorageAccessed( |
577 storage::QuotaClient::kServiceWorkerCache, origin_, | 568 storage::QuotaClient::kServiceWorkerCache, origin_, |
578 storage::kStorageTypeTemporary); | 569 storage::kStorageTypeTemporary); |
579 | 570 |
580 StringsAndErrorCallback pending_callback = | 571 scheduler_->ScheduleOperation( |
581 base::Bind(&CacheStorage::PendingStringsAndErrorCallback, | 572 base::Bind(&CacheStorage::EnumerateCachesImpl, weak_factory_.GetWeakPtr(), |
582 weak_factory_.GetWeakPtr(), callback); | 573 scheduler_->WrapCallbackToRunNext(callback))); |
583 scheduler_->ScheduleOperation(base::Bind(&CacheStorage::EnumerateCachesImpl, | |
584 weak_factory_.GetWeakPtr(), | |
585 pending_callback)); | |
586 } | 574 } |
587 | 575 |
588 void CacheStorage::MatchCache( | 576 void CacheStorage::MatchCache( |
589 const std::string& cache_name, | 577 const std::string& cache_name, |
590 std::unique_ptr<ServiceWorkerFetchRequest> request, | 578 std::unique_ptr<ServiceWorkerFetchRequest> request, |
591 const CacheStorageCache::ResponseCallback& callback) { | 579 const CacheStorageCache::ResponseCallback& callback) { |
592 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 580 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
593 | 581 |
594 if (!initialized_) | 582 if (!initialized_) |
595 LazyInit(); | 583 LazyInit(); |
596 | 584 |
597 quota_manager_proxy_->NotifyStorageAccessed( | 585 quota_manager_proxy_->NotifyStorageAccessed( |
598 storage::QuotaClient::kServiceWorkerCache, origin_, | 586 storage::QuotaClient::kServiceWorkerCache, origin_, |
599 storage::kStorageTypeTemporary); | 587 storage::kStorageTypeTemporary); |
600 | 588 |
601 CacheStorageCache::ResponseCallback pending_callback = | 589 scheduler_->ScheduleOperation( |
602 base::Bind(&CacheStorage::PendingResponseCallback, | 590 base::Bind(&CacheStorage::MatchCacheImpl, weak_factory_.GetWeakPtr(), |
603 weak_factory_.GetWeakPtr(), callback); | 591 cache_name, base::Passed(std::move(request)), |
604 scheduler_->ScheduleOperation(base::Bind( | 592 scheduler_->WrapCallbackToRunNext(callback))); |
605 &CacheStorage::MatchCacheImpl, weak_factory_.GetWeakPtr(), cache_name, | |
606 base::Passed(std::move(request)), pending_callback)); | |
607 } | 593 } |
608 | 594 |
609 void CacheStorage::MatchAllCaches( | 595 void CacheStorage::MatchAllCaches( |
610 std::unique_ptr<ServiceWorkerFetchRequest> request, | 596 std::unique_ptr<ServiceWorkerFetchRequest> request, |
611 const CacheStorageCache::ResponseCallback& callback) { | 597 const CacheStorageCache::ResponseCallback& callback) { |
612 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 598 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
613 | 599 |
614 if (!initialized_) | 600 if (!initialized_) |
615 LazyInit(); | 601 LazyInit(); |
616 | 602 |
617 quota_manager_proxy_->NotifyStorageAccessed( | 603 quota_manager_proxy_->NotifyStorageAccessed( |
618 storage::QuotaClient::kServiceWorkerCache, origin_, | 604 storage::QuotaClient::kServiceWorkerCache, origin_, |
619 storage::kStorageTypeTemporary); | 605 storage::kStorageTypeTemporary); |
620 | 606 |
621 CacheStorageCache::ResponseCallback pending_callback = | |
622 base::Bind(&CacheStorage::PendingResponseCallback, | |
623 weak_factory_.GetWeakPtr(), callback); | |
624 scheduler_->ScheduleOperation( | 607 scheduler_->ScheduleOperation( |
625 base::Bind(&CacheStorage::MatchAllCachesImpl, weak_factory_.GetWeakPtr(), | 608 base::Bind(&CacheStorage::MatchAllCachesImpl, weak_factory_.GetWeakPtr(), |
626 base::Passed(std::move(request)), pending_callback)); | 609 base::Passed(std::move(request)), |
| 610 scheduler_->WrapCallbackToRunNext(callback))); |
627 } | 611 } |
628 | 612 |
629 void CacheStorage::GetSizeThenCloseAllCaches(const SizeCallback& callback) { | 613 void CacheStorage::GetSizeThenCloseAllCaches(const SizeCallback& callback) { |
630 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 614 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
631 | 615 |
632 if (!initialized_) | 616 if (!initialized_) |
633 LazyInit(); | 617 LazyInit(); |
634 | 618 |
635 CacheStorageCache::SizeCallback pending_callback = base::Bind( | 619 scheduler_->ScheduleOperation(base::Bind( |
636 &CacheStorage::PendingSizeCallback, weak_factory_.GetWeakPtr(), callback); | 620 &CacheStorage::GetSizeThenCloseAllCachesImpl, weak_factory_.GetWeakPtr(), |
637 | 621 scheduler_->WrapCallbackToRunNext(callback))); |
638 scheduler_->ScheduleOperation( | |
639 base::Bind(&CacheStorage::GetSizeThenCloseAllCachesImpl, | |
640 weak_factory_.GetWeakPtr(), pending_callback)); | |
641 } | 622 } |
642 | 623 |
643 void CacheStorage::Size(const CacheStorage::SizeCallback& callback) { | 624 void CacheStorage::Size(const CacheStorage::SizeCallback& callback) { |
644 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 625 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
645 | 626 |
646 if (!initialized_) | 627 if (!initialized_) |
647 LazyInit(); | 628 LazyInit(); |
648 | 629 |
649 CacheStorageCache::SizeCallback pending_callback = base::Bind( | 630 scheduler_->ScheduleOperation( |
650 &CacheStorage::PendingSizeCallback, weak_factory_.GetWeakPtr(), callback); | 631 base::Bind(&CacheStorage::SizeImpl, weak_factory_.GetWeakPtr(), |
651 | 632 scheduler_->WrapCallbackToRunNext(callback))); |
652 scheduler_->ScheduleOperation(base::Bind( | |
653 &CacheStorage::SizeImpl, weak_factory_.GetWeakPtr(), pending_callback)); | |
654 } | 633 } |
655 | 634 |
656 void CacheStorage::StartAsyncOperationForTesting() { | 635 void CacheStorage::StartAsyncOperationForTesting() { |
657 scheduler_->ScheduleOperation(base::Bind(&base::DoNothing)); | 636 scheduler_->ScheduleOperation(base::Bind(&base::DoNothing)); |
658 } | 637 } |
659 | 638 |
660 void CacheStorage::CompleteAsyncOperationForTesting() { | 639 void CacheStorage::CompleteAsyncOperationForTesting() { |
661 scheduler_->CompleteOperationAndRunNext(); | 640 scheduler_->CompleteOperationAndRunNext(); |
662 } | 641 } |
663 | 642 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 for (const std::string& cache_name : ordered_cache_names_) { | 1015 for (const std::string& cache_name : ordered_cache_names_) { |
1037 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 1016 std::unique_ptr<CacheStorageCacheHandle> cache_handle = |
1038 GetLoadedCache(cache_name); | 1017 GetLoadedCache(cache_name); |
1039 CacheStorageCache* cache = cache_handle->value(); | 1018 CacheStorageCache* cache = cache_handle->value(); |
1040 cache->Size(base::Bind(&SizeRetrievedFromCache, | 1019 cache->Size(base::Bind(&SizeRetrievedFromCache, |
1041 base::Passed(std::move(cache_handle)), | 1020 base::Passed(std::move(cache_handle)), |
1042 barrier_closure, accumulator_ptr)); | 1021 barrier_closure, accumulator_ptr)); |
1043 } | 1022 } |
1044 } | 1023 } |
1045 | 1024 |
1046 void CacheStorage::PendingClosure(const base::Closure& callback) { | |
1047 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | |
1048 | |
1049 callback.Run(); | |
1050 if (cache_storage) | |
1051 scheduler_->CompleteOperationAndRunNext(); | |
1052 } | |
1053 | |
1054 void CacheStorage::PendingBoolAndErrorCallback( | |
1055 const BoolAndErrorCallback& callback, | |
1056 bool found, | |
1057 CacheStorageError error) { | |
1058 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | |
1059 | |
1060 callback.Run(found, error); | |
1061 if (cache_storage) | |
1062 scheduler_->CompleteOperationAndRunNext(); | |
1063 } | |
1064 | |
1065 void CacheStorage::PendingCacheAndErrorCallback( | |
1066 const CacheAndErrorCallback& callback, | |
1067 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | |
1068 CacheStorageError error) { | |
1069 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | |
1070 | |
1071 callback.Run(std::move(cache_handle), error); | |
1072 if (cache_storage) | |
1073 scheduler_->CompleteOperationAndRunNext(); | |
1074 } | |
1075 | |
1076 void CacheStorage::PendingStringsAndErrorCallback( | |
1077 const StringsAndErrorCallback& callback, | |
1078 const StringVector& strings, | |
1079 CacheStorageError error) { | |
1080 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | |
1081 | |
1082 callback.Run(strings, error); | |
1083 if (cache_storage) | |
1084 scheduler_->CompleteOperationAndRunNext(); | |
1085 } | |
1086 | |
1087 void CacheStorage::PendingResponseCallback( | |
1088 const CacheStorageCache::ResponseCallback& callback, | |
1089 CacheStorageError error, | |
1090 std::unique_ptr<ServiceWorkerResponse> response, | |
1091 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { | |
1092 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | |
1093 | |
1094 callback.Run(error, std::move(response), std::move(blob_data_handle)); | |
1095 if (cache_storage) | |
1096 scheduler_->CompleteOperationAndRunNext(); | |
1097 } | |
1098 | |
1099 void CacheStorage::PendingSizeCallback(const SizeCallback& callback, | |
1100 int64_t size) { | |
1101 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | |
1102 | |
1103 callback.Run(size); | |
1104 if (cache_storage) | |
1105 scheduler_->CompleteOperationAndRunNext(); | |
1106 } | |
1107 | |
1108 } // namespace content | 1025 } // namespace content |
OLD | NEW |