Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: content/browser/cache_storage/cache_storage.cc

Issue 1132683003: CacheStorage: Merge CacheStorage::CacheStorageError and CacheStorageCache::ErrorType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 initializing_ = false; 553 initializing_ = false;
554 initialized_ = true; 554 initialized_ = true;
555 555
556 scheduler_->CompleteOperationAndRunNext(); 556 scheduler_->CompleteOperationAndRunNext();
557 } 557 }
558 558
559 void CacheStorage::OpenCacheImpl(const std::string& cache_name, 559 void CacheStorage::OpenCacheImpl(const std::string& cache_name,
560 const CacheAndErrorCallback& callback) { 560 const CacheAndErrorCallback& callback) {
561 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 561 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
562 if (cache.get()) { 562 if (cache.get()) {
563 callback.Run(cache, CACHE_STORAGE_ERROR_NO_ERROR); 563 callback.Run(cache, CACHE_STORAGE_OK);
564 return; 564 return;
565 } 565 }
566 566
567 cache_loader_->CreateCache( 567 cache_loader_->CreateCache(
568 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache, 568 cache_name, base::Bind(&CacheStorage::CreateCacheDidCreateCache,
569 weak_factory_.GetWeakPtr(), cache_name, callback)); 569 weak_factory_.GetWeakPtr(), cache_name, callback));
570 } 570 }
571 571
572 void CacheStorage::CreateCacheDidCreateCache( 572 void CacheStorage::CreateCacheDidCreateCache(
573 const std::string& cache_name, 573 const std::string& cache_name,
574 const CacheAndErrorCallback& callback, 574 const CacheAndErrorCallback& callback,
575 const scoped_refptr<CacheStorageCache>& cache) { 575 const scoped_refptr<CacheStorageCache>& cache) {
576 DCHECK_CURRENTLY_ON(BrowserThread::IO); 576 DCHECK_CURRENTLY_ON(BrowserThread::IO);
577 577
578 if (!cache.get()) { 578 if (!cache.get()) {
579 callback.Run(scoped_refptr<CacheStorageCache>(), 579 callback.Run(scoped_refptr<CacheStorageCache>(),
580 CACHE_STORAGE_ERROR_CLOSING); 580 CACHE_STORAGE_ERROR_STORAGE);
nhiroki 2015/05/08 07:33:03 Are we able to replace "CLOSING" with "STORAGE"? T
jkarlin 2015/05/08 12:38:19 Yes, I think that's fine. I see an error in the be
nhiroki 2015/05/08 14:14:49 I see, thanks!
581 return; 581 return;
582 } 582 }
583 583
584 UMA_HISTOGRAM_BOOLEAN("ServiceWorkerCache.CreateCacheStorageResult", 584 UMA_HISTOGRAM_BOOLEAN("ServiceWorkerCache.CreateCacheStorageResult",
585 cache != nullptr); 585 cache != nullptr);
586 586
587 cache_map_.insert(std::make_pair(cache_name, cache->AsWeakPtr())); 587 cache_map_.insert(std::make_pair(cache_name, cache->AsWeakPtr()));
588 ordered_cache_names_.push_back(cache_name); 588 ordered_cache_names_.push_back(cache_name);
589 589
590 cache_loader_->WriteIndex( 590 cache_loader_->WriteIndex(
591 ordered_cache_names_, 591 ordered_cache_names_,
592 base::Bind(&CacheStorage::CreateCacheDidWriteIndex, 592 base::Bind(&CacheStorage::CreateCacheDidWriteIndex,
593 weak_factory_.GetWeakPtr(), callback, cache)); 593 weak_factory_.GetWeakPtr(), callback, cache));
594 } 594 }
595 595
596 void CacheStorage::CreateCacheDidWriteIndex( 596 void CacheStorage::CreateCacheDidWriteIndex(
597 const CacheAndErrorCallback& callback, 597 const CacheAndErrorCallback& callback,
598 const scoped_refptr<CacheStorageCache>& cache, 598 const scoped_refptr<CacheStorageCache>& cache,
599 bool success) { 599 bool success) {
600 DCHECK_CURRENTLY_ON(BrowserThread::IO); 600 DCHECK_CURRENTLY_ON(BrowserThread::IO);
601 DCHECK(cache.get()); 601 DCHECK(cache.get());
602 602
603 // TODO(jkarlin): Handle !success. 603 // TODO(jkarlin): Handle !success.
604 604
605 callback.Run(cache, CACHE_STORAGE_ERROR_NO_ERROR); 605 callback.Run(cache, CACHE_STORAGE_OK);
606 } 606 }
607 607
608 void CacheStorage::HasCacheImpl(const std::string& cache_name, 608 void CacheStorage::HasCacheImpl(const std::string& cache_name,
609 const BoolAndErrorCallback& callback) { 609 const BoolAndErrorCallback& callback) {
610 bool has_cache = cache_map_.find(cache_name) != cache_map_.end(); 610 bool has_cache = cache_map_.find(cache_name) != cache_map_.end();
611 611
612 callback.Run(has_cache, CACHE_STORAGE_ERROR_NO_ERROR); 612 callback.Run(has_cache, CACHE_STORAGE_OK);
613 } 613 }
614 614
615 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, 615 void CacheStorage::DeleteCacheImpl(const std::string& cache_name,
616 const BoolAndErrorCallback& callback) { 616 const BoolAndErrorCallback& callback) {
617 CacheMap::iterator it = cache_map_.find(cache_name); 617 CacheMap::iterator it = cache_map_.find(cache_name);
618 if (it == cache_map_.end()) { 618 if (it == cache_map_.end()) {
619 callback.Run(false, CACHE_STORAGE_ERROR_NOT_FOUND); 619 callback.Run(false, CACHE_STORAGE_ERROR_NOT_FOUND);
620 return; 620 return;
621 } 621 }
622 622
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 661
662 cache_loader_->CleanUpDeletedCache( 662 cache_loader_->CleanUpDeletedCache(
663 cache_name, base::Bind(&CacheStorage::DeleteCacheDidCleanUp, 663 cache_name, base::Bind(&CacheStorage::DeleteCacheDidCleanUp,
664 weak_factory_.GetWeakPtr(), callback)); 664 weak_factory_.GetWeakPtr(), callback));
665 } 665 }
666 666
667 void CacheStorage::DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback, 667 void CacheStorage::DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback,
668 bool success) { 668 bool success) {
669 DCHECK_CURRENTLY_ON(BrowserThread::IO); 669 DCHECK_CURRENTLY_ON(BrowserThread::IO);
670 670
671 callback.Run(true, CACHE_STORAGE_ERROR_NO_ERROR); 671 callback.Run(true, CACHE_STORAGE_OK);
672 } 672 }
673 673
674 void CacheStorage::EnumerateCachesImpl( 674 void CacheStorage::EnumerateCachesImpl(
675 const StringsAndErrorCallback& callback) { 675 const StringsAndErrorCallback& callback) {
676 callback.Run(ordered_cache_names_, CACHE_STORAGE_ERROR_NO_ERROR); 676 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK);
677 } 677 }
678 678
679 void CacheStorage::MatchCacheImpl( 679 void CacheStorage::MatchCacheImpl(
680 const std::string& cache_name, 680 const std::string& cache_name,
681 scoped_ptr<ServiceWorkerFetchRequest> request, 681 scoped_ptr<ServiceWorkerFetchRequest> request,
682 const CacheStorageCache::ResponseCallback& callback) { 682 const CacheStorageCache::ResponseCallback& callback) {
683 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name); 683 scoped_refptr<CacheStorageCache> cache = GetLoadedCache(cache_name);
684 684
685 if (!cache.get()) { 685 if (!cache.get()) {
686 callback.Run(CacheStorageCache::ERROR_TYPE_NOT_FOUND, 686 callback.Run(CACHE_STORAGE_ERROR_NOT_FOUND,
687 scoped_ptr<ServiceWorkerResponse>(), 687 scoped_ptr<ServiceWorkerResponse>(),
688 scoped_ptr<storage::BlobDataHandle>()); 688 scoped_ptr<storage::BlobDataHandle>());
689 return; 689 return;
690 } 690 }
691 691
692 // Pass the cache along to the callback to keep the cache open until match is 692 // Pass the cache along to the callback to keep the cache open until match is
693 // done. 693 // done.
694 cache->Match(request.Pass(), 694 cache->Match(request.Pass(),
695 base::Bind(&CacheStorage::MatchCacheDidMatch, 695 base::Bind(&CacheStorage::MatchCacheDidMatch,
696 weak_factory_.GetWeakPtr(), cache, callback)); 696 weak_factory_.GetWeakPtr(), cache, callback));
697 } 697 }
698 698
699 void CacheStorage::MatchCacheDidMatch( 699 void CacheStorage::MatchCacheDidMatch(
700 const scoped_refptr<CacheStorageCache>& cache, 700 const scoped_refptr<CacheStorageCache>& cache,
701 const CacheStorageCache::ResponseCallback& callback, 701 const CacheStorageCache::ResponseCallback& callback,
702 CacheStorageCache::ErrorType error, 702 CacheStorageError error,
703 scoped_ptr<ServiceWorkerResponse> response, 703 scoped_ptr<ServiceWorkerResponse> response,
704 scoped_ptr<storage::BlobDataHandle> handle) { 704 scoped_ptr<storage::BlobDataHandle> handle) {
705 callback.Run(error, response.Pass(), handle.Pass()); 705 callback.Run(error, response.Pass(), handle.Pass());
706 } 706 }
707 707
708 void CacheStorage::MatchAllCachesImpl( 708 void CacheStorage::MatchAllCachesImpl(
709 scoped_ptr<ServiceWorkerFetchRequest> request, 709 scoped_ptr<ServiceWorkerFetchRequest> request,
710 const CacheStorageCache::ResponseCallback& callback) { 710 const CacheStorageCache::ResponseCallback& callback) {
711 scoped_ptr<CacheStorageCache::ResponseCallback> callback_copy( 711 scoped_ptr<CacheStorageCache::ResponseCallback> callback_copy(
712 new CacheStorageCache::ResponseCallback(callback)); 712 new CacheStorageCache::ResponseCallback(callback));
(...skipping 13 matching lines...) Expand all
726 base::Bind(&CacheStorage::MatchAllCachesDidMatch, 726 base::Bind(&CacheStorage::MatchAllCachesDidMatch,
727 weak_factory_.GetWeakPtr(), cache, barrier_closure, 727 weak_factory_.GetWeakPtr(), cache, barrier_closure,
728 callback_ptr)); 728 callback_ptr));
729 } 729 }
730 } 730 }
731 731
732 void CacheStorage::MatchAllCachesDidMatch( 732 void CacheStorage::MatchAllCachesDidMatch(
733 scoped_refptr<CacheStorageCache> cache, 733 scoped_refptr<CacheStorageCache> cache,
734 const base::Closure& barrier_closure, 734 const base::Closure& barrier_closure,
735 CacheStorageCache::ResponseCallback* callback, 735 CacheStorageCache::ResponseCallback* callback,
736 CacheStorageCache::ErrorType error, 736 CacheStorageError error,
737 scoped_ptr<ServiceWorkerResponse> response, 737 scoped_ptr<ServiceWorkerResponse> response,
738 scoped_ptr<storage::BlobDataHandle> handle) { 738 scoped_ptr<storage::BlobDataHandle> handle) {
739 if (callback->is_null() || error == CacheStorageCache::ERROR_TYPE_NOT_FOUND) { 739 if (callback->is_null() || error == CACHE_STORAGE_ERROR_NOT_FOUND) {
740 barrier_closure.Run(); 740 barrier_closure.Run();
741 return; 741 return;
742 } 742 }
743 callback->Run(error, response.Pass(), handle.Pass()); 743 callback->Run(error, response.Pass(), handle.Pass());
744 callback->Reset(); // Only call the callback once. 744 callback->Reset(); // Only call the callback once.
745 745
746 barrier_closure.Run(); 746 barrier_closure.Run();
747 } 747 }
748 748
749 void CacheStorage::MatchAllCachesDidMatchAll( 749 void CacheStorage::MatchAllCachesDidMatchAll(
750 scoped_ptr<CacheStorageCache::ResponseCallback> callback) { 750 scoped_ptr<CacheStorageCache::ResponseCallback> callback) {
751 if (!callback->is_null()) { 751 if (!callback->is_null()) {
752 callback->Run(CacheStorageCache::ERROR_TYPE_NOT_FOUND, 752 callback->Run(CACHE_STORAGE_ERROR_NOT_FOUND,
753 scoped_ptr<ServiceWorkerResponse>(), 753 scoped_ptr<ServiceWorkerResponse>(),
754 scoped_ptr<storage::BlobDataHandle>()); 754 scoped_ptr<storage::BlobDataHandle>());
755 } 755 }
756 } 756 }
757 757
758 scoped_refptr<CacheStorageCache> CacheStorage::GetLoadedCache( 758 scoped_refptr<CacheStorageCache> CacheStorage::GetLoadedCache(
759 const std::string& cache_name) { 759 const std::string& cache_name) {
760 DCHECK_CURRENTLY_ON(BrowserThread::IO); 760 DCHECK_CURRENTLY_ON(BrowserThread::IO);
761 DCHECK(initialized_); 761 DCHECK(initialized_);
762 762
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 CacheStorageError error) { 840 CacheStorageError error) {
841 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); 841 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr();
842 842
843 callback.Run(strings, error); 843 callback.Run(strings, error);
844 if (cache_storage) 844 if (cache_storage)
845 scheduler_->CompleteOperationAndRunNext(); 845 scheduler_->CompleteOperationAndRunNext();
846 } 846 }
847 847
848 void CacheStorage::PendingResponseCallback( 848 void CacheStorage::PendingResponseCallback(
849 const CacheStorageCache::ResponseCallback& callback, 849 const CacheStorageCache::ResponseCallback& callback,
850 CacheStorageCache::ErrorType error, 850 CacheStorageError error,
851 scoped_ptr<ServiceWorkerResponse> response, 851 scoped_ptr<ServiceWorkerResponse> response,
852 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { 852 scoped_ptr<storage::BlobDataHandle> blob_data_handle) {
853 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); 853 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr();
854 854
855 callback.Run(error, response.Pass(), blob_data_handle.Pass()); 855 callback.Run(error, response.Pass(), blob_data_handle.Pass());
856 if (cache_storage) 856 if (cache_storage)
857 scheduler_->CompleteOperationAndRunNext(); 857 scheduler_->CompleteOperationAndRunNext();
858 } 858 }
859 859
860 } // namespace content 860 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698