| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // load the backend, that happens lazily when the cache is used. | 106 // load the backend, that happens lazily when the cache is used. |
| 107 virtual std::unique_ptr<CacheStorageCache> CreateCache( | 107 virtual std::unique_ptr<CacheStorageCache> CreateCache( |
| 108 const std::string& cache_name) = 0; | 108 const std::string& cache_name) = 0; |
| 109 | 109 |
| 110 // Deletes any pre-existing cache of the same name and then loads it. | 110 // Deletes any pre-existing cache of the same name and then loads it. |
| 111 virtual void PrepareNewCacheDestination(const std::string& cache_name, | 111 virtual void PrepareNewCacheDestination(const std::string& cache_name, |
| 112 const CacheCallback& callback) = 0; | 112 const CacheCallback& callback) = 0; |
| 113 | 113 |
| 114 // After the backend has been deleted, do any extra house keeping such as | 114 // After the backend has been deleted, do any extra house keeping such as |
| 115 // removing the cache's directory. | 115 // removing the cache's directory. |
| 116 virtual void CleanUpDeletedCache(const std::string& key, | 116 virtual void CleanUpDeletedCache(const std::string& key) = 0; |
| 117 const BoolCallback& callback) = 0; | |
| 118 | 117 |
| 119 // Writes the cache names (and sizes) to disk if applicable. | 118 // Writes the cache names (and sizes) to disk if applicable. |
| 120 virtual void WriteIndex(const StringVector& cache_names, | 119 virtual void WriteIndex(const StringVector& cache_names, |
| 121 const BoolCallback& callback) = 0; | 120 const BoolCallback& callback) = 0; |
| 122 | 121 |
| 123 // Loads the cache names from disk if applicable. | 122 // Loads the cache names from disk if applicable. |
| 124 virtual void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names, | 123 virtual void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names, |
| 125 const StringVectorCallback& callback) = 0; | 124 const StringVectorCallback& callback) = 0; |
| 126 | 125 |
| 126 // Called when CacheStorage has created a cache. Used to hold onto a handle to |
| 127 // the cache if necessary. |
| 128 virtual void NotifyCacheCreated( |
| 129 const std::string& cache_name, |
| 130 std::unique_ptr<CacheStorageCacheHandle> cache_handle){}; |
| 131 |
| 132 // Notification that a cache has been doomed and will be deleted once the last |
| 133 // cache handle has been dropped. If the loader is holding a handle to the |
| 134 // cache, it should drop it now. |
| 135 virtual void NotifyCacheDoomed(const std::string& cache_name){}; |
| 136 |
| 127 protected: | 137 protected: |
| 128 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; | 138 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; |
| 129 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 139 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 130 | 140 |
| 131 // Owned by CacheStorage which owns this. | 141 // Owned by CacheStorage which owns this. |
| 132 storage::QuotaManagerProxy* quota_manager_proxy_; | 142 storage::QuotaManagerProxy* quota_manager_proxy_; |
| 133 | 143 |
| 134 base::WeakPtr<storage::BlobStorageContext> blob_context_; | 144 base::WeakPtr<storage::BlobStorageContext> blob_context_; |
| 135 | 145 |
| 136 // Raw pointer is safe because this object is owned by cache_storage_. | 146 // Raw pointer is safe because this object is owned by cache_storage_. |
| 137 CacheStorage* cache_storage_; | 147 CacheStorage* cache_storage_; |
| 138 | 148 |
| 139 GURL origin_; | 149 GURL origin_; |
| 140 }; | 150 }; |
| 141 | 151 |
| 142 // Creates memory-only ServiceWorkerCaches. Because these caches have no | 152 // Creates memory-only ServiceWorkerCaches. Because these caches have no |
| 143 // persistent storage it is not safe to free them from memory if they might be | 153 // persistent storage it is not safe to free them from memory if they might be |
| 144 // used again. Therefore this class holds a reference to each cache until the | 154 // used again. Therefore this class holds a reference to each cache until the |
| 145 // cache is deleted. | 155 // cache is doomed. |
| 146 class CacheStorage::MemoryLoader : public CacheStorage::CacheLoader { | 156 class CacheStorage::MemoryLoader : public CacheStorage::CacheLoader { |
| 147 public: | 157 public: |
| 148 MemoryLoader(base::SequencedTaskRunner* cache_task_runner, | 158 MemoryLoader(base::SequencedTaskRunner* cache_task_runner, |
| 149 scoped_refptr<net::URLRequestContextGetter> request_context, | 159 scoped_refptr<net::URLRequestContextGetter> request_context, |
| 150 storage::QuotaManagerProxy* quota_manager_proxy, | 160 storage::QuotaManagerProxy* quota_manager_proxy, |
| 151 base::WeakPtr<storage::BlobStorageContext> blob_context, | 161 base::WeakPtr<storage::BlobStorageContext> blob_context, |
| 152 CacheStorage* cache_storage, | 162 CacheStorage* cache_storage, |
| 153 const GURL& origin) | 163 const GURL& origin) |
| 154 : CacheLoader(cache_task_runner, | 164 : CacheLoader(cache_task_runner, |
| 155 request_context, | 165 request_context, |
| 156 quota_manager_proxy, | 166 quota_manager_proxy, |
| 157 blob_context, | 167 blob_context, |
| 158 cache_storage, | 168 cache_storage, |
| 159 origin) {} | 169 origin) {} |
| 160 | 170 |
| 161 std::unique_ptr<CacheStorageCache> CreateCache( | 171 std::unique_ptr<CacheStorageCache> CreateCache( |
| 162 const std::string& cache_name) override { | 172 const std::string& cache_name) override { |
| 163 return CacheStorageCache::CreateMemoryCache( | 173 return CacheStorageCache::CreateMemoryCache( |
| 164 origin_, cache_name, cache_storage_, request_context_getter_, | 174 origin_, cache_name, cache_storage_, request_context_getter_, |
| 165 quota_manager_proxy_, blob_context_); | 175 quota_manager_proxy_, blob_context_); |
| 166 } | 176 } |
| 167 | 177 |
| 168 void PrepareNewCacheDestination(const std::string& cache_name, | 178 void PrepareNewCacheDestination(const std::string& cache_name, |
| 169 const CacheCallback& callback) override { | 179 const CacheCallback& callback) override { |
| 170 std::unique_ptr<CacheStorageCache> cache = CreateCache(cache_name); | 180 std::unique_ptr<CacheStorageCache> cache = CreateCache(cache_name); |
| 171 callback.Run(std::move(cache)); | 181 callback.Run(std::move(cache)); |
| 172 } | 182 } |
| 173 | 183 |
| 174 void CleanUpDeletedCache(const std::string& cache_name, | 184 void CleanUpDeletedCache(const std::string& cache_name) override { |
| 175 const BoolCallback& callback) override { | 185 DCHECK(!ContainsKey(cache_handles_, cache_name)); |
| 176 CacheHandles::iterator it = cache_handles_.find(cache_name); | |
| 177 DCHECK(it != cache_handles_.end()); | |
| 178 cache_handles_.erase(it); | |
| 179 callback.Run(true); | |
| 180 } | 186 } |
| 181 | 187 |
| 182 void WriteIndex(const StringVector& cache_names, | 188 void WriteIndex(const StringVector& cache_names, |
| 183 const BoolCallback& callback) override { | 189 const BoolCallback& callback) override { |
| 184 callback.Run(false); | 190 callback.Run(true); |
| 185 } | 191 } |
| 186 | 192 |
| 187 void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names, | 193 void LoadIndex(std::unique_ptr<std::vector<std::string>> cache_names, |
| 188 const StringVectorCallback& callback) override { | 194 const StringVectorCallback& callback) override { |
| 189 callback.Run(std::move(cache_names)); | 195 callback.Run(std::move(cache_names)); |
| 190 } | 196 } |
| 191 | 197 |
| 192 void StoreCacheHandle(const std::string& cache_name, | 198 void NotifyCacheCreated( |
| 193 std::unique_ptr<CacheStorageCacheHandle> cache_handle) { | 199 const std::string& cache_name, |
| 200 std::unique_ptr<CacheStorageCacheHandle> cache_handle) override { |
| 194 DCHECK(!ContainsKey(cache_handles_, cache_name)); | 201 DCHECK(!ContainsKey(cache_handles_, cache_name)); |
| 195 cache_handles_.insert(std::make_pair(cache_name, std::move(cache_handle))); | 202 cache_handles_.insert(std::make_pair(cache_name, std::move(cache_handle))); |
| 196 } | 203 }; |
| 204 |
| 205 void NotifyCacheDoomed(const std::string& cache_name) override { |
| 206 DCHECK(ContainsKey(cache_handles_, cache_name)); |
| 207 cache_handles_.erase(cache_name); |
| 208 }; |
| 197 | 209 |
| 198 private: | 210 private: |
| 199 typedef std::map<std::string, std::unique_ptr<CacheStorageCacheHandle>> | 211 typedef std::map<std::string, std::unique_ptr<CacheStorageCacheHandle>> |
| 200 CacheHandles; | 212 CacheHandles; |
| 201 ~MemoryLoader() override {} | 213 ~MemoryLoader() override {} |
| 202 | 214 |
| 203 // Keep a reference to each cache to ensure that it's not freed before the | 215 // Keep a reference to each cache to ensure that it's not freed before the |
| 204 // client calls CacheStorage::Delete or the CacheStorage is | 216 // client calls CacheStorage::Delete or the CacheStorage is |
| 205 // freed. | 217 // freed. |
| 206 CacheHandles cache_handles_; | 218 CacheHandles cache_handles_; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 const std::string& cache_dir) { | 278 const std::string& cache_dir) { |
| 267 if (cache_dir.empty()) { | 279 if (cache_dir.empty()) { |
| 268 callback.Run(std::unique_ptr<CacheStorageCache>()); | 280 callback.Run(std::unique_ptr<CacheStorageCache>()); |
| 269 return; | 281 return; |
| 270 } | 282 } |
| 271 | 283 |
| 272 cache_name_to_cache_dir_[cache_name] = cache_dir; | 284 cache_name_to_cache_dir_[cache_name] = cache_dir; |
| 273 callback.Run(CreateCache(cache_name)); | 285 callback.Run(CreateCache(cache_name)); |
| 274 } | 286 } |
| 275 | 287 |
| 276 void CleanUpDeletedCache(const std::string& cache_name, | 288 void CleanUpDeletedCache(const std::string& cache_name) override { |
| 277 const BoolCallback& callback) override { | |
| 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 289 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 279 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name)); | 290 DCHECK(ContainsKey(cache_name_to_cache_dir_, cache_name)); |
| 280 | 291 |
| 281 base::FilePath cache_path = | 292 base::FilePath cache_path = |
| 282 origin_path_.AppendASCII(cache_name_to_cache_dir_[cache_name]); | 293 origin_path_.AppendASCII(cache_name_to_cache_dir_[cache_name]); |
| 283 cache_name_to_cache_dir_.erase(cache_name); | 294 cache_name_to_cache_dir_.erase(cache_name); |
| 284 | 295 |
| 285 cache_task_runner_->PostTask( | 296 cache_task_runner_->PostTask( |
| 286 FROM_HERE, | 297 FROM_HERE, base::Bind(&SimpleCacheLoader::CleanUpDeleteCacheDirInPool, |
| 287 base::Bind(&SimpleCacheLoader::CleanUpDeleteCacheDirInPool, cache_path, | 298 cache_path)); |
| 288 callback, base::ThreadTaskRunnerHandle::Get())); | |
| 289 } | 299 } |
| 290 | 300 |
| 291 static void CleanUpDeleteCacheDirInPool( | 301 static void CleanUpDeleteCacheDirInPool(const base::FilePath& cache_path) { |
| 292 const base::FilePath& cache_path, | 302 base::DeleteFile(cache_path, true /* recursive */); |
| 293 const BoolCallback& callback, | |
| 294 scoped_refptr<base::SingleThreadTaskRunner> original_task_runner) { | |
| 295 bool rv = base::DeleteFile(cache_path, true); | |
| 296 original_task_runner->PostTask(FROM_HERE, base::Bind(callback, rv)); | |
| 297 } | 303 } |
| 298 | 304 |
| 299 void WriteIndex(const StringVector& cache_names, | 305 void WriteIndex(const StringVector& cache_names, |
| 300 const BoolCallback& callback) override { | 306 const BoolCallback& callback) override { |
| 301 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 307 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 302 | 308 |
| 303 // 1. Create the index file as a string. (WriteIndex) | 309 // 1. Create the index file as a string. (WriteIndex) |
| 304 // 2. Write the file to disk. (WriteIndexWriteToFileInPool) | 310 // 2. Write the file to disk. (WriteIndexWriteToFileInPool) |
| 305 | 311 |
| 306 CacheStorageIndex index; | 312 CacheStorageIndex index; |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 callback.Run(std::unique_ptr<CacheStorageCacheHandle>(), | 737 callback.Run(std::unique_ptr<CacheStorageCacheHandle>(), |
| 732 CACHE_STORAGE_ERROR_STORAGE); | 738 CACHE_STORAGE_ERROR_STORAGE); |
| 733 return; | 739 return; |
| 734 } | 740 } |
| 735 | 741 |
| 736 CacheStorageCache* cache_ptr = cache.get(); | 742 CacheStorageCache* cache_ptr = cache.get(); |
| 737 | 743 |
| 738 cache_map_.insert(std::make_pair(cache_name, std::move(cache))); | 744 cache_map_.insert(std::make_pair(cache_name, std::move(cache))); |
| 739 ordered_cache_names_.push_back(cache_name); | 745 ordered_cache_names_.push_back(cache_name); |
| 740 | 746 |
| 741 if (memory_only_) { | |
| 742 static_cast<MemoryLoader*>(cache_loader_.get()) | |
| 743 ->StoreCacheHandle(cache_name, CreateCacheHandle(cache_ptr)); | |
| 744 } | |
| 745 | |
| 746 cache_loader_->WriteIndex( | 747 cache_loader_->WriteIndex( |
| 747 ordered_cache_names_, | 748 ordered_cache_names_, |
| 748 base::Bind(&CacheStorage::CreateCacheDidWriteIndex, | 749 base::Bind(&CacheStorage::CreateCacheDidWriteIndex, |
| 749 weak_factory_.GetWeakPtr(), callback, | 750 weak_factory_.GetWeakPtr(), callback, |
| 750 base::Passed(CreateCacheHandle(cache_ptr)))); | 751 base::Passed(CreateCacheHandle(cache_ptr)))); |
| 752 |
| 753 cache_loader_->NotifyCacheCreated(cache_name, CreateCacheHandle(cache_ptr)); |
| 751 } | 754 } |
| 752 | 755 |
| 753 void CacheStorage::CreateCacheDidWriteIndex( | 756 void CacheStorage::CreateCacheDidWriteIndex( |
| 754 const CacheAndErrorCallback& callback, | 757 const CacheAndErrorCallback& callback, |
| 755 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | 758 std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
| 756 bool success) { | 759 bool success) { |
| 757 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 760 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 758 DCHECK(cache_handle); | 761 DCHECK(cache_handle); |
| 759 | 762 |
| 760 // TODO(jkarlin): Handle !success. | 763 // TODO(jkarlin): Handle !success. |
| 761 | 764 |
| 762 callback.Run(std::move(cache_handle), CACHE_STORAGE_OK); | 765 callback.Run(std::move(cache_handle), CACHE_STORAGE_OK); |
| 763 } | 766 } |
| 764 | 767 |
| 765 void CacheStorage::HasCacheImpl(const std::string& cache_name, | 768 void CacheStorage::HasCacheImpl(const std::string& cache_name, |
| 766 const BoolAndErrorCallback& callback) { | 769 const BoolAndErrorCallback& callback) { |
| 767 bool has_cache = ContainsKey(cache_map_, cache_name); | 770 bool has_cache = ContainsKey(cache_map_, cache_name); |
| 768 callback.Run(has_cache, CACHE_STORAGE_OK); | 771 callback.Run(has_cache, CACHE_STORAGE_OK); |
| 769 } | 772 } |
| 770 | 773 |
| 771 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, | 774 void CacheStorage::DeleteCacheImpl(const std::string& cache_name, |
| 772 const BoolAndErrorCallback& callback) { | 775 const BoolAndErrorCallback& callback) { |
| 773 std::unique_ptr<CacheStorageCacheHandle> cache_handle = | 776 if (!GetLoadedCache(cache_name)) { |
| 774 GetLoadedCache(cache_name); | |
| 775 if (!cache_handle) { | |
| 776 base::ThreadTaskRunnerHandle::Get()->PostTask( | 777 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 777 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND)); | 778 FROM_HERE, base::Bind(callback, false, CACHE_STORAGE_ERROR_NOT_FOUND)); |
| 778 return; | 779 return; |
| 779 } | 780 } |
| 780 | 781 |
| 781 CacheMap::iterator map_iter = cache_map_.find(cache_name); | |
| 782 deleted_caches_.insert( | |
| 783 std::make_pair(cache_handle->value(), std::move(map_iter->second))); | |
| 784 cache_map_.erase(map_iter); | |
| 785 | |
| 786 // Delete the name from ordered_cache_names_. | 782 // Delete the name from ordered_cache_names_. |
| 783 StringVector original_ordered_cache_names = ordered_cache_names_; |
| 787 StringVector::iterator iter = std::find( | 784 StringVector::iterator iter = std::find( |
| 788 ordered_cache_names_.begin(), ordered_cache_names_.end(), cache_name); | 785 ordered_cache_names_.begin(), ordered_cache_names_.end(), cache_name); |
| 789 DCHECK(iter != ordered_cache_names_.end()); | 786 DCHECK(iter != ordered_cache_names_.end()); |
| 790 ordered_cache_names_.erase(iter); | 787 ordered_cache_names_.erase(iter); |
| 791 | 788 |
| 792 CacheStorageCache* cache_ptr = cache_handle->value(); | 789 cache_loader_->WriteIndex(ordered_cache_names_, |
| 793 cache_ptr->GetSizeThenClose( | 790 base::Bind(&CacheStorage::DeleteCacheDidWriteIndex, |
| 794 base::Bind(&CacheStorage::DeleteCacheDidClose, weak_factory_.GetWeakPtr(), | 791 weak_factory_.GetWeakPtr(), cache_name, |
| 795 cache_name, callback, ordered_cache_names_, | 792 original_ordered_cache_names, callback)); |
| 796 base::Passed(std::move(cache_handle)))); | |
| 797 } | |
| 798 | |
| 799 void CacheStorage::DeleteCacheDidClose( | |
| 800 const std::string& cache_name, | |
| 801 const BoolAndErrorCallback& callback, | |
| 802 const StringVector& ordered_cache_names, | |
| 803 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | |
| 804 int64_t cache_size) { | |
| 805 cache_loader_->WriteIndex( | |
| 806 ordered_cache_names, | |
| 807 base::Bind(&CacheStorage::DeleteCacheDidWriteIndex, | |
| 808 weak_factory_.GetWeakPtr(), cache_name, callback, cache_size)); | |
| 809 } | 793 } |
| 810 | 794 |
| 811 void CacheStorage::DeleteCacheDidWriteIndex( | 795 void CacheStorage::DeleteCacheDidWriteIndex( |
| 812 const std::string& cache_name, | 796 const std::string& cache_name, |
| 797 const StringVector& original_ordered_cache_names, |
| 813 const BoolAndErrorCallback& callback, | 798 const BoolAndErrorCallback& callback, |
| 814 int cache_size, | |
| 815 bool success) { | 799 bool success) { |
| 816 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 800 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 817 | 801 |
| 802 if (!success) { |
| 803 // Undo any changes if the change couldn't be written to disk. |
| 804 ordered_cache_names_ = original_ordered_cache_names; |
| 805 callback.Run(false, CACHE_STORAGE_ERROR_STORAGE); |
| 806 return; |
| 807 } |
| 808 |
| 809 CacheMap::iterator map_iter = cache_map_.find(cache_name); |
| 810 doomed_caches_.insert( |
| 811 std::make_pair(map_iter->second.get(), std::move(map_iter->second))); |
| 812 cache_map_.erase(map_iter); |
| 813 |
| 814 cache_loader_->NotifyCacheDoomed(cache_name); |
| 815 |
| 816 callback.Run(true, CACHE_STORAGE_OK); |
| 817 } |
| 818 |
| 819 // Call this once the last handle to a doomed cache is gone. It's okay if this |
| 820 // doesn't get to complete before shutdown, the cache will be removed from disk |
| 821 // on next startup in that case. |
| 822 void CacheStorage::DeleteCacheFinalize( |
| 823 std::unique_ptr<CacheStorageCache> doomed_cache) { |
| 824 CacheStorageCache* cache = doomed_cache.get(); |
| 825 cache->Size(base::Bind(&CacheStorage::DeleteCacheDidGetSize, |
| 826 weak_factory_.GetWeakPtr(), |
| 827 base::Passed(std::move(doomed_cache)))); |
| 828 } |
| 829 |
| 830 void CacheStorage::DeleteCacheDidGetSize( |
| 831 std::unique_ptr<CacheStorageCache> cache, |
| 832 int64_t cache_size) { |
| 818 quota_manager_proxy_->NotifyStorageModified( | 833 quota_manager_proxy_->NotifyStorageModified( |
| 819 storage::QuotaClient::kServiceWorkerCache, origin_, | 834 storage::QuotaClient::kServiceWorkerCache, origin_, |
| 820 storage::kStorageTypeTemporary, -1 * cache_size); | 835 storage::kStorageTypeTemporary, -1 * cache_size); |
| 821 | 836 |
| 822 cache_loader_->CleanUpDeletedCache( | 837 cache_loader_->CleanUpDeletedCache(cache->cache_name()); |
| 823 cache_name, base::Bind(&CacheStorage::DeleteCacheDidCleanUp, | |
| 824 weak_factory_.GetWeakPtr(), callback)); | |
| 825 } | |
| 826 | |
| 827 void CacheStorage::DeleteCacheDidCleanUp(const BoolAndErrorCallback& callback, | |
| 828 bool success) { | |
| 829 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 830 | |
| 831 callback.Run(true, CACHE_STORAGE_OK); | |
| 832 } | 838 } |
| 833 | 839 |
| 834 void CacheStorage::EnumerateCachesImpl( | 840 void CacheStorage::EnumerateCachesImpl( |
| 835 const StringsAndErrorCallback& callback) { | 841 const StringsAndErrorCallback& callback) { |
| 836 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); | 842 callback.Run(ordered_cache_names_, CACHE_STORAGE_OK); |
| 837 } | 843 } |
| 838 | 844 |
| 839 void CacheStorage::MatchCacheImpl( | 845 void CacheStorage::MatchCacheImpl( |
| 840 const std::string& cache_name, | 846 const std::string& cache_name, |
| 841 std::unique_ptr<ServiceWorkerFetchRequest> request, | 847 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 void CacheStorage::DropCacheHandleRef(CacheStorageCache* cache) { | 944 void CacheStorage::DropCacheHandleRef(CacheStorageCache* cache) { |
| 939 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 945 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 940 auto iter = cache_handle_counts_.find(cache); | 946 auto iter = cache_handle_counts_.find(cache); |
| 941 DCHECK(iter != cache_handle_counts_.end()); | 947 DCHECK(iter != cache_handle_counts_.end()); |
| 942 DCHECK(iter->second >= 1); | 948 DCHECK(iter->second >= 1); |
| 943 | 949 |
| 944 iter->second -= 1; | 950 iter->second -= 1; |
| 945 if (iter->second == 0) { | 951 if (iter->second == 0) { |
| 946 // Delete the CacheStorageCache object. It's either in the main cache map or | 952 // Delete the CacheStorageCache object. It's either in the main cache map or |
| 947 // the CacheStorage::Delete operation has run on the cache, in which case | 953 // the CacheStorage::Delete operation has run on the cache, in which case |
| 948 // it's in the deleted caches map. | 954 // it's in the doomed caches map. |
| 949 auto cache_map_iter = cache_map_.find(cache->cache_name()); | 955 auto cache_map_iter = cache_map_.find(cache->cache_name()); |
| 950 | 956 |
| 951 if (cache_map_iter == cache_map_.end()) { | 957 if (cache_map_iter == cache_map_.end()) { |
| 952 auto deleted_caches_iter = deleted_caches_.find(cache); | 958 auto doomed_caches_iter = doomed_caches_.find(cache); |
| 953 DCHECK(deleted_caches_iter != deleted_caches_.end()); | 959 DCHECK(doomed_caches_iter != doomed_caches_.end()); |
| 954 deleted_caches_.erase(deleted_caches_iter); | 960 |
| 961 // The last reference to a doomed cache is gone, perform clean up. |
| 962 DeleteCacheFinalize(std::move(doomed_caches_iter->second)); |
| 963 doomed_caches_.erase(doomed_caches_iter); |
| 955 return; | 964 return; |
| 956 } | 965 } |
| 957 | 966 |
| 958 cache_map_iter->second.reset(); | 967 cache_map_iter->second.reset(); |
| 959 cache_handle_counts_.erase(iter); | 968 cache_handle_counts_.erase(iter); |
| 960 } | 969 } |
| 961 } | 970 } |
| 962 | 971 |
| 963 std::unique_ptr<CacheStorageCacheHandle> CacheStorage::CreateCacheHandle( | 972 std::unique_ptr<CacheStorageCacheHandle> CacheStorage::CreateCacheHandle( |
| 964 CacheStorageCache* cache) { | 973 CacheStorageCache* cache) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 void CacheStorage::PendingSizeCallback(const SizeCallback& callback, | 1099 void CacheStorage::PendingSizeCallback(const SizeCallback& callback, |
| 1091 int64_t size) { | 1100 int64_t size) { |
| 1092 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); | 1101 base::WeakPtr<CacheStorage> cache_storage = weak_factory_.GetWeakPtr(); |
| 1093 | 1102 |
| 1094 callback.Run(size); | 1103 callback.Run(size); |
| 1095 if (cache_storage) | 1104 if (cache_storage) |
| 1096 scheduler_->CompleteOperationAndRunNext(); | 1105 scheduler_->CompleteOperationAndRunNext(); |
| 1097 } | 1106 } |
| 1098 | 1107 |
| 1099 } // namespace content | 1108 } // namespace content |
| OLD | NEW |