| 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_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/common/service_worker/service_worker_types.h" | 12 #include "content/common/service_worker/service_worker_types.h" |
| 13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 14 #include "net/disk_cache/disk_cache.h" | 14 #include "net/disk_cache/disk_cache.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class URLRequestContext; | 17 class URLRequestContext; |
| 18 class IOBufferWithSize; | 18 class IOBufferWithSize; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace storage { | 21 namespace storage { |
| 22 class BlobData; | 22 class BlobData; |
| 23 class BlobDataHandle; | 23 class BlobDataHandle; |
| 24 class BlobStorageContext; | 24 class BlobStorageContext; |
| 25 class QuotaManagerProxy; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 class ChromeBlobStorageContext; | 29 class ChromeBlobStorageContext; |
| 29 class ServiceWorkerRequestResponseHeaders; | 30 class ServiceWorkerRequestResponseHeaders; |
| 30 | 31 |
| 31 // TODO(jkarlin): Unload cache backend from memory once the cache object is no | 32 // TODO(jkarlin): Unload cache backend from memory once the cache object is no |
| 32 // longer referenced in javascript. | 33 // longer referenced in javascript. |
| 33 | 34 |
| 34 // Represents a ServiceWorker Cache as seen in | 35 // Represents a ServiceWorker Cache as seen in |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 typedef base::Callback<void(ErrorType)> ErrorCallback; | 48 typedef base::Callback<void(ErrorType)> ErrorCallback; |
| 48 typedef base::Callback<void(ErrorType, | 49 typedef base::Callback<void(ErrorType, |
| 49 scoped_ptr<ServiceWorkerResponse>, | 50 scoped_ptr<ServiceWorkerResponse>, |
| 50 scoped_ptr<storage::BlobDataHandle>)> | 51 scoped_ptr<storage::BlobDataHandle>)> |
| 51 ResponseCallback; | 52 ResponseCallback; |
| 52 typedef std::vector<ServiceWorkerFetchRequest> Requests; | 53 typedef std::vector<ServiceWorkerFetchRequest> Requests; |
| 53 typedef base::Callback<void(ErrorType, scoped_ptr<Requests>)> | 54 typedef base::Callback<void(ErrorType, scoped_ptr<Requests>)> |
| 54 RequestsCallback; | 55 RequestsCallback; |
| 55 | 56 |
| 56 static scoped_refptr<ServiceWorkerCache> CreateMemoryCache( | 57 static scoped_refptr<ServiceWorkerCache> CreateMemoryCache( |
| 58 const GURL& origin, |
| 57 net::URLRequestContext* request_context, | 59 net::URLRequestContext* request_context, |
| 60 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, |
| 58 base::WeakPtr<storage::BlobStorageContext> blob_context); | 61 base::WeakPtr<storage::BlobStorageContext> blob_context); |
| 59 static scoped_refptr<ServiceWorkerCache> CreatePersistentCache( | 62 static scoped_refptr<ServiceWorkerCache> CreatePersistentCache( |
| 63 const GURL& origin, |
| 60 const base::FilePath& path, | 64 const base::FilePath& path, |
| 61 net::URLRequestContext* request_context, | 65 net::URLRequestContext* request_context, |
| 66 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, |
| 62 base::WeakPtr<storage::BlobStorageContext> blob_context); | 67 base::WeakPtr<storage::BlobStorageContext> blob_context); |
| 63 | 68 |
| 64 // Returns ErrorTypeNotFound if not found. The callback will always be called. | 69 // Returns ErrorTypeNotFound if not found. The callback will always be called. |
| 65 void Match(scoped_ptr<ServiceWorkerFetchRequest> request, | 70 void Match(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 66 const ResponseCallback& callback); | 71 const ResponseCallback& callback); |
| 67 | 72 |
| 68 // Puts the request and response object in the cache. The response body (if | 73 // Puts the request and response object in the cache. The response body (if |
| 69 // present) is stored in the cache, but not the request body. Returns | 74 // present) is stored in the cache, but not the request body. Returns |
| 70 // ErrorTypeOK on success. The callback will always be called. | 75 // ErrorTypeOK on success. The callback will always be called. |
| 71 void Put(scoped_ptr<ServiceWorkerFetchRequest> request, | 76 void Put(scoped_ptr<ServiceWorkerFetchRequest> request, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 } | 95 } |
| 91 | 96 |
| 92 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); | 97 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); |
| 93 | 98 |
| 94 private: | 99 private: |
| 95 friend class base::RefCounted<ServiceWorkerCache>; | 100 friend class base::RefCounted<ServiceWorkerCache>; |
| 96 | 101 |
| 97 struct KeysContext; | 102 struct KeysContext; |
| 98 typedef std::vector<disk_cache::Entry*> Entries; | 103 typedef std::vector<disk_cache::Entry*> Entries; |
| 99 | 104 |
| 100 ServiceWorkerCache(const base::FilePath& path, | 105 ServiceWorkerCache( |
| 101 net::URLRequestContext* request_context, | 106 const GURL& origin, |
| 102 base::WeakPtr<storage::BlobStorageContext> blob_context); | 107 const base::FilePath& path, |
| 108 net::URLRequestContext* request_context, |
| 109 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, |
| 110 base::WeakPtr<storage::BlobStorageContext> blob_context); |
| 103 | 111 |
| 104 // Operations in progress will complete after the cache is deleted but pending | 112 // Operations in progress will complete after the cache is deleted but pending |
| 105 // operations (those operations waiting for init to finish) won't. | 113 // operations (those operations waiting for init to finish) won't. |
| 106 virtual ~ServiceWorkerCache(); | 114 virtual ~ServiceWorkerCache(); |
| 107 | 115 |
| 108 void PutImpl(scoped_ptr<ServiceWorkerFetchRequest> request, | 116 void PutImpl(scoped_ptr<ServiceWorkerFetchRequest> request, |
| 109 scoped_ptr<ServiceWorkerResponse> response, | 117 scoped_ptr<ServiceWorkerResponse> response, |
| 110 scoped_ptr<storage::BlobDataHandle> blob_data_handle, | 118 scoped_ptr<storage::BlobDataHandle> blob_data_handle, |
| 111 const ResponseCallback& callback); | 119 const ResponseCallback& callback); |
| 112 | 120 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 123 // Loads the backend and calls the callback with the result (true for | 131 // Loads the backend and calls the callback with the result (true for |
| 124 // success). The callback will always be called. | 132 // success). The callback will always be called. |
| 125 void CreateBackend(const ErrorCallback& callback); | 133 void CreateBackend(const ErrorCallback& callback); |
| 126 | 134 |
| 127 void Init(const base::Closure& callback); | 135 void Init(const base::Closure& callback); |
| 128 void InitDone(ErrorType error); | 136 void InitDone(ErrorType error); |
| 129 | 137 |
| 130 // The backend can be deleted via the Close function at any time so always | 138 // The backend can be deleted via the Close function at any time so always |
| 131 // check for its existence before use. | 139 // check for its existence before use. |
| 132 scoped_ptr<disk_cache::Backend> backend_; | 140 scoped_ptr<disk_cache::Backend> backend_; |
| 141 GURL origin_; |
| 133 base::FilePath path_; | 142 base::FilePath path_; |
| 134 net::URLRequestContext* request_context_; | 143 net::URLRequestContext* request_context_; |
| 144 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; |
| 135 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 145 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 136 bool initialized_; | 146 bool initialized_; |
| 137 std::vector<base::Closure> init_callbacks_; | 147 std::vector<base::Closure> init_callbacks_; |
| 138 | 148 |
| 139 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; | 149 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; |
| 140 | 150 |
| 141 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); | 151 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); |
| 142 }; | 152 }; |
| 143 | 153 |
| 144 } // namespace content | 154 } // namespace content |
| 145 | 155 |
| 146 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ | 156 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ |
| OLD | NEW |