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/service_worker/service_worker_cache_storage.h" | 5 #include "content/browser/service_worker/service_worker_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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 weak_factory_.GetWeakPtr(), cache_name, | 509 weak_factory_.GetWeakPtr(), cache_name, |
510 base::Passed(request.Pass()), callback)); | 510 base::Passed(request.Pass()), callback)); |
511 return; | 511 return; |
512 } | 512 } |
513 | 513 |
514 scoped_refptr<ServiceWorkerCache> cache = GetLoadedCache(cache_name); | 514 scoped_refptr<ServiceWorkerCache> cache = GetLoadedCache(cache_name); |
515 | 515 |
516 if (!cache.get()) { | 516 if (!cache.get()) { |
517 callback.Run(ServiceWorkerCache::ErrorTypeNotFound, | 517 callback.Run(ServiceWorkerCache::ErrorTypeNotFound, |
518 scoped_ptr<ServiceWorkerResponse>(), | 518 scoped_ptr<ServiceWorkerResponse>(), |
519 scoped_ptr<storage::BlobDataHandle>()); | 519 scoped_ptr<storage::BlobDataSnapshotHandle>()); |
520 return; | 520 return; |
521 } | 521 } |
522 | 522 |
523 // Pass the cache along to the callback to keep the cache open until match is | 523 // Pass the cache along to the callback to keep the cache open until match is |
524 // done. | 524 // done. |
525 cache->Match(request.Pass(), | 525 cache->Match(request.Pass(), |
526 base::Bind(&ServiceWorkerCacheStorage::MatchCacheDidMatch, | 526 base::Bind(&ServiceWorkerCacheStorage::MatchCacheDidMatch, |
527 weak_factory_.GetWeakPtr(), cache, callback)); | 527 weak_factory_.GetWeakPtr(), cache, callback)); |
528 } | 528 } |
529 | 529 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 719 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
720 | 720 |
721 callback.Run(true, CACHE_STORAGE_ERROR_NO_ERROR); | 721 callback.Run(true, CACHE_STORAGE_ERROR_NO_ERROR); |
722 } | 722 } |
723 | 723 |
724 void ServiceWorkerCacheStorage::MatchCacheDidMatch( | 724 void ServiceWorkerCacheStorage::MatchCacheDidMatch( |
725 const scoped_refptr<ServiceWorkerCache>& cache, | 725 const scoped_refptr<ServiceWorkerCache>& cache, |
726 const ServiceWorkerCache::ResponseCallback& callback, | 726 const ServiceWorkerCache::ResponseCallback& callback, |
727 ServiceWorkerCache::ErrorType error, | 727 ServiceWorkerCache::ErrorType error, |
728 scoped_ptr<ServiceWorkerResponse> response, | 728 scoped_ptr<ServiceWorkerResponse> response, |
729 scoped_ptr<storage::BlobDataHandle> handle) { | 729 scoped_ptr<storage::BlobDataSnapshotHandle> handle) { |
730 callback.Run(error, response.Pass(), handle.Pass()); | 730 callback.Run(error, response.Pass(), handle.Pass()); |
731 } | 731 } |
732 | 732 |
733 void ServiceWorkerCacheStorage::MatchAllCachesDidMatch( | 733 void ServiceWorkerCacheStorage::MatchAllCachesDidMatch( |
734 scoped_refptr<ServiceWorkerCache> cache, | 734 scoped_refptr<ServiceWorkerCache> cache, |
735 const base::Closure& barrier_closure, | 735 const base::Closure& barrier_closure, |
736 ServiceWorkerCache::ResponseCallback* callback, | 736 ServiceWorkerCache::ResponseCallback* callback, |
737 ServiceWorkerCache::ErrorType error, | 737 ServiceWorkerCache::ErrorType error, |
738 scoped_ptr<ServiceWorkerResponse> response, | 738 scoped_ptr<ServiceWorkerResponse> response, |
739 scoped_ptr<storage::BlobDataHandle> handle) { | 739 scoped_ptr<storage::BlobDataSnapshotHandle> handle) { |
740 if (callback->is_null() || error == ServiceWorkerCache::ErrorTypeNotFound) { | 740 if (callback->is_null() || error == ServiceWorkerCache::ErrorTypeNotFound) { |
741 barrier_closure.Run(); | 741 barrier_closure.Run(); |
742 return; | 742 return; |
743 } | 743 } |
744 callback->Run(error, response.Pass(), handle.Pass()); | 744 callback->Run(error, response.Pass(), handle.Pass()); |
745 callback->Reset(); // Only call the callback once. | 745 callback->Reset(); // Only call the callback once. |
746 | 746 |
747 barrier_closure.Run(); | 747 barrier_closure.Run(); |
748 } | 748 } |
749 | 749 |
750 void ServiceWorkerCacheStorage::MatchAllCachesDidMatchAll( | 750 void ServiceWorkerCacheStorage::MatchAllCachesDidMatchAll( |
751 scoped_ptr<ServiceWorkerCache::ResponseCallback> callback) { | 751 scoped_ptr<ServiceWorkerCache::ResponseCallback> callback) { |
752 if (!callback->is_null()) { | 752 if (!callback->is_null()) { |
753 callback->Run(ServiceWorkerCache::ErrorTypeNotFound, | 753 callback->Run(ServiceWorkerCache::ErrorTypeNotFound, |
754 scoped_ptr<ServiceWorkerResponse>(), | 754 scoped_ptr<ServiceWorkerResponse>(), |
755 scoped_ptr<storage::BlobDataHandle>()); | 755 scoped_ptr<storage::BlobDataSnapshotHandle>()); |
756 } | 756 } |
757 } | 757 } |
758 | 758 |
759 scoped_refptr<ServiceWorkerCache> ServiceWorkerCacheStorage::GetLoadedCache( | 759 scoped_refptr<ServiceWorkerCache> ServiceWorkerCacheStorage::GetLoadedCache( |
760 const std::string& cache_name) { | 760 const std::string& cache_name) { |
761 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 761 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
762 DCHECK(initialized_); | 762 DCHECK(initialized_); |
763 | 763 |
764 CacheMap::iterator map_iter = cache_map_.find(cache_name); | 764 CacheMap::iterator map_iter = cache_map_.find(cache_name); |
765 if (map_iter == cache_map_.end()) | 765 if (map_iter == cache_map_.end()) |
766 return scoped_refptr<ServiceWorkerCache>(); | 766 return scoped_refptr<ServiceWorkerCache>(); |
767 | 767 |
768 base::WeakPtr<ServiceWorkerCache> cache = map_iter->second; | 768 base::WeakPtr<ServiceWorkerCache> cache = map_iter->second; |
769 | 769 |
770 if (!cache) { | 770 if (!cache) { |
771 scoped_refptr<ServiceWorkerCache> new_cache = | 771 scoped_refptr<ServiceWorkerCache> new_cache = |
772 cache_loader_->CreateServiceWorkerCache(cache_name); | 772 cache_loader_->CreateServiceWorkerCache(cache_name); |
773 map_iter->second = new_cache->AsWeakPtr(); | 773 map_iter->second = new_cache->AsWeakPtr(); |
774 return new_cache; | 774 return new_cache; |
775 } | 775 } |
776 | 776 |
777 return make_scoped_refptr(cache.get()); | 777 return make_scoped_refptr(cache.get()); |
778 } | 778 } |
779 | 779 |
780 } // namespace content | 780 } // namespace content |
OLD | NEW |