| 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_MANAGER_H_ | 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "content/browser/service_worker/service_worker_cache_storage.h" | 14 #include "content/browser/cache_storage/cache_storage.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "storage/browser/quota/quota_client.h" | 16 #include "storage/browser/quota/quota_client.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 class URLRequestContext; | 24 class URLRequestContext; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace storage { | 27 namespace storage { |
| 28 class BlobStorageContext; | 28 class BlobStorageContext; |
| 29 class QuotaManagerProxy; | 29 class QuotaManagerProxy; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 class ServiceWorkerCacheQuotaClient; | 34 class CacheStorageQuotaClient; |
| 35 | 35 |
| 36 // Keeps track of a ServiceWorkerCacheStorage per origin. There is one | 36 // Keeps track of a CacheStorage per origin. There is one |
| 37 // ServiceWorkerCacheStorageManager per ServiceWorkerContextCore. | 37 // CacheStorageManager per ServiceWorkerContextCore. |
| 38 // TODO(jkarlin): Remove ServiceWorkerCacheStorage from memory once they're no | 38 // TODO(jkarlin): Remove CacheStorage from memory once they're no |
| 39 // longer in active use. | 39 // longer in active use. |
| 40 class CONTENT_EXPORT ServiceWorkerCacheStorageManager { | 40 class CONTENT_EXPORT CacheStorageManager { |
| 41 public: | 41 public: |
| 42 static scoped_ptr<ServiceWorkerCacheStorageManager> Create( | 42 static scoped_ptr<CacheStorageManager> Create( |
| 43 const base::FilePath& path, | 43 const base::FilePath& path, |
| 44 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner, | 44 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner, |
| 45 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy); | 45 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy); |
| 46 | 46 |
| 47 static scoped_ptr<ServiceWorkerCacheStorageManager> Create( | 47 static scoped_ptr<CacheStorageManager> Create( |
| 48 ServiceWorkerCacheStorageManager* old_manager); | 48 CacheStorageManager* old_manager); |
| 49 | 49 |
| 50 virtual ~ServiceWorkerCacheStorageManager(); | 50 virtual ~CacheStorageManager(); |
| 51 | 51 |
| 52 // Methods to support the CacheStorage spec. These methods call the | 52 // Methods to support the CacheStorage spec. These methods call the |
| 53 // corresponding ServiceWorkerCacheStorage method on the appropriate thread. | 53 // corresponding CacheStorage method on the appropriate thread. |
| 54 void OpenCache( | 54 void OpenCache(const GURL& origin, |
| 55 const GURL& origin, | 55 const std::string& cache_name, |
| 56 const std::string& cache_name, | 56 const CacheStorage::CacheAndErrorCallback& callback); |
| 57 const ServiceWorkerCacheStorage::CacheAndErrorCallback& callback); | 57 void HasCache(const GURL& origin, |
| 58 void HasCache( | 58 const std::string& cache_name, |
| 59 const GURL& origin, | 59 const CacheStorage::BoolAndErrorCallback& callback); |
| 60 const std::string& cache_name, | 60 void DeleteCache(const GURL& origin, |
| 61 const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback); | 61 const std::string& cache_name, |
| 62 void DeleteCache( | 62 const CacheStorage::BoolAndErrorCallback& callback); |
| 63 const GURL& origin, | 63 void EnumerateCaches(const GURL& origin, |
| 64 const std::string& cache_name, | 64 const CacheStorage::StringsAndErrorCallback& callback); |
| 65 const ServiceWorkerCacheStorage::BoolAndErrorCallback& callback); | |
| 66 void EnumerateCaches( | |
| 67 const GURL& origin, | |
| 68 const ServiceWorkerCacheStorage::StringsAndErrorCallback& callback); | |
| 69 void MatchCache(const GURL& origin, | 65 void MatchCache(const GURL& origin, |
| 70 const std::string& cache_name, | 66 const std::string& cache_name, |
| 71 scoped_ptr<ServiceWorkerFetchRequest> request, | 67 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 72 const ServiceWorkerCache::ResponseCallback& callback); | 68 const CacheStorageCache::ResponseCallback& callback); |
| 73 void MatchAllCaches(const GURL& origin, | 69 void MatchAllCaches(const GURL& origin, |
| 74 scoped_ptr<ServiceWorkerFetchRequest> request, | 70 scoped_ptr<ServiceWorkerFetchRequest> request, |
| 75 const ServiceWorkerCache::ResponseCallback& callback); | 71 const CacheStorageCache::ResponseCallback& callback); |
| 76 | 72 |
| 77 // This must be called before creating any of the public *Cache functions | 73 // This must be called before creating any of the public *Cache functions |
| 78 // above. | 74 // above. |
| 79 void SetBlobParametersForCache( | 75 void SetBlobParametersForCache( |
| 80 net::URLRequestContext* request_context, | 76 net::URLRequestContext* request_context, |
| 81 base::WeakPtr<storage::BlobStorageContext> blob_storage_context); | 77 base::WeakPtr<storage::BlobStorageContext> blob_storage_context); |
| 82 | 78 |
| 83 base::WeakPtr<ServiceWorkerCacheStorageManager> AsWeakPtr() { | 79 base::WeakPtr<CacheStorageManager> AsWeakPtr() { |
| 84 return weak_ptr_factory_.GetWeakPtr(); | 80 return weak_ptr_factory_.GetWeakPtr(); |
| 85 } | 81 } |
| 86 | 82 |
| 87 private: | 83 private: |
| 88 friend class ServiceWorkerCacheQuotaClient; | 84 friend class CacheStorageQuotaClient; |
| 89 friend class ServiceWorkerCacheStorageManagerTest; | 85 friend class CacheStorageManagerTest; |
| 90 friend class ServiceWorkerCacheStorageMigrationTest; | 86 friend class CacheStorageMigrationTest; |
| 91 | 87 |
| 92 typedef std::map<GURL, ServiceWorkerCacheStorage*> | 88 typedef std::map<GURL, CacheStorage*> CacheStorageMap; |
| 93 ServiceWorkerCacheStorageMap; | |
| 94 | 89 |
| 95 ServiceWorkerCacheStorageManager( | 90 CacheStorageManager( |
| 96 const base::FilePath& path, | 91 const base::FilePath& path, |
| 97 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner, | 92 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner, |
| 98 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy); | 93 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy); |
| 99 | 94 |
| 100 // The returned ServiceWorkerCacheStorage* is owned by | 95 // The returned CacheStorage* is owned by this manager. |
| 101 // service_worker_cache_storages_. | 96 CacheStorage* FindOrCreateCacheStorage(const GURL& origin); |
| 102 ServiceWorkerCacheStorage* FindOrCreateServiceWorkerCacheManager( | |
| 103 const GURL& origin); | |
| 104 | 97 |
| 105 // QuotaClient support | 98 // QuotaClient support |
| 106 void GetOriginUsage(const GURL& origin_url, | 99 void GetOriginUsage(const GURL& origin_url, |
| 107 const storage::QuotaClient::GetUsageCallback& callback); | 100 const storage::QuotaClient::GetUsageCallback& callback); |
| 108 void GetOrigins(const storage::QuotaClient::GetOriginsCallback& callback); | 101 void GetOrigins(const storage::QuotaClient::GetOriginsCallback& callback); |
| 109 void GetOriginsForHost( | 102 void GetOriginsForHost( |
| 110 const std::string& host, | 103 const std::string& host, |
| 111 const storage::QuotaClient::GetOriginsCallback& callback); | 104 const storage::QuotaClient::GetOriginsCallback& callback); |
| 112 void DeleteOriginData(const GURL& origin, | 105 void DeleteOriginData(const GURL& origin, |
| 113 const storage::QuotaClient::DeletionCallback& callback); | 106 const storage::QuotaClient::DeletionCallback& callback); |
| 114 static void DeleteOriginDidClose( | 107 static void DeleteOriginDidClose( |
| 115 const GURL& origin, | 108 const GURL& origin, |
| 116 const storage::QuotaClient::DeletionCallback& callback, | 109 const storage::QuotaClient::DeletionCallback& callback, |
| 117 scoped_ptr<ServiceWorkerCacheStorage> cache_storage, | 110 scoped_ptr<CacheStorage> cache_storage, |
| 118 base::WeakPtr<ServiceWorkerCacheStorageManager> cache_manager); | 111 base::WeakPtr<CacheStorageManager> cache_manager); |
| 119 | 112 |
| 120 net::URLRequestContext* url_request_context() const { | 113 net::URLRequestContext* url_request_context() const { |
| 121 return request_context_; | 114 return request_context_; |
| 122 } | 115 } |
| 123 base::WeakPtr<storage::BlobStorageContext> blob_storage_context() const { | 116 base::WeakPtr<storage::BlobStorageContext> blob_storage_context() const { |
| 124 return blob_context_; | 117 return blob_context_; |
| 125 } | 118 } |
| 126 base::FilePath root_path() const { return root_path_; } | 119 base::FilePath root_path() const { return root_path_; } |
| 127 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner() const { | 120 const scoped_refptr<base::SequencedTaskRunner>& cache_task_runner() const { |
| 128 return cache_task_runner_; | 121 return cache_task_runner_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 145 static void MigrateOriginOnTaskRunner(const base::FilePath& old_path, | 138 static void MigrateOriginOnTaskRunner(const base::FilePath& old_path, |
| 146 const base::FilePath& new_path); | 139 const base::FilePath& new_path); |
| 147 | 140 |
| 148 base::FilePath root_path_; | 141 base::FilePath root_path_; |
| 149 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; | 142 scoped_refptr<base::SequencedTaskRunner> cache_task_runner_; |
| 150 | 143 |
| 151 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; | 144 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 152 | 145 |
| 153 // The map owns the CacheStorages and the CacheStorages are only accessed on | 146 // The map owns the CacheStorages and the CacheStorages are only accessed on |
| 154 // |cache_task_runner_|. | 147 // |cache_task_runner_|. |
| 155 ServiceWorkerCacheStorageMap cache_storage_map_; | 148 CacheStorageMap cache_storage_map_; |
| 156 | 149 |
| 157 net::URLRequestContext* request_context_; | 150 net::URLRequestContext* request_context_; |
| 158 base::WeakPtr<storage::BlobStorageContext> blob_context_; | 151 base::WeakPtr<storage::BlobStorageContext> blob_context_; |
| 159 | 152 |
| 160 base::WeakPtrFactory<ServiceWorkerCacheStorageManager> weak_ptr_factory_; | 153 base::WeakPtrFactory<CacheStorageManager> weak_ptr_factory_; |
| 161 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCacheStorageManager); | 154 DISALLOW_COPY_AND_ASSIGN(CacheStorageManager); |
| 162 }; | 155 }; |
| 163 | 156 |
| 164 } // namespace content | 157 } // namespace content |
| 165 | 158 |
| 166 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_STORAGE_MANAGER_H
_ | 159 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_MANAGER_H_ |
| OLD | NEW |