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/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 ErrorTypeExists, | 39 ErrorTypeExists, |
40 ErrorTypeStorage, | 40 ErrorTypeStorage, |
41 ErrorTypeNotFound | 41 ErrorTypeNotFound |
42 }; | 42 }; |
43 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY }; | 43 enum EntryIndex { INDEX_HEADERS = 0, INDEX_RESPONSE_BODY }; |
44 typedef base::Callback<void(ErrorType)> ErrorCallback; | 44 typedef base::Callback<void(ErrorType)> ErrorCallback; |
45 typedef base::Callback<void(ErrorType, | 45 typedef base::Callback<void(ErrorType, |
46 scoped_ptr<ServiceWorkerResponse>, | 46 scoped_ptr<ServiceWorkerResponse>, |
47 scoped_ptr<storage::BlobDataHandle>)> | 47 scoped_ptr<storage::BlobDataHandle>)> |
48 ResponseCallback; | 48 ResponseCallback; |
| 49 typedef std::vector<ServiceWorkerFetchRequest> Requests; |
| 50 typedef base::Callback<void(ErrorType, scoped_ptr<Requests>)> |
| 51 RequestsCallback; |
| 52 |
49 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( | 53 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( |
50 net::URLRequestContext* request_context, | 54 net::URLRequestContext* request_context, |
51 base::WeakPtr<storage::BlobStorageContext> blob_context); | 55 base::WeakPtr<storage::BlobStorageContext> blob_context); |
52 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( | 56 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( |
53 const base::FilePath& path, | 57 const base::FilePath& path, |
54 net::URLRequestContext* request_context, | 58 net::URLRequestContext* request_context, |
55 base::WeakPtr<storage::BlobStorageContext> blob_context); | 59 base::WeakPtr<storage::BlobStorageContext> blob_context); |
56 | 60 |
57 virtual ~ServiceWorkerCache(); | 61 virtual ~ServiceWorkerCache(); |
58 | 62 |
(...skipping 14 matching lines...) Expand all Loading... |
73 void Put(ServiceWorkerFetchRequest* request, | 77 void Put(ServiceWorkerFetchRequest* request, |
74 ServiceWorkerResponse* response, | 78 ServiceWorkerResponse* response, |
75 const ErrorCallback& callback); | 79 const ErrorCallback& callback); |
76 | 80 |
77 // Returns ErrorNotFound if not found. Otherwise deletes and returns | 81 // Returns ErrorNotFound if not found. Otherwise deletes and returns |
78 // ErrorTypeOK. The callback will always be called. |request| must remain | 82 // ErrorTypeOK. The callback will always be called. |request| must remain |
79 // valid until the callback is called. | 83 // valid until the callback is called. |
80 void Delete(ServiceWorkerFetchRequest* request, | 84 void Delete(ServiceWorkerFetchRequest* request, |
81 const ErrorCallback& callback); | 85 const ErrorCallback& callback); |
82 | 86 |
| 87 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest. |
| 88 // Returns ErrorTypeOK and a vector of requests if there are no errors. The |
| 89 // callback will always be called. |
| 90 void Keys(const RequestsCallback& callback); |
| 91 |
83 // Call to determine if CreateBackend must be called. | 92 // Call to determine if CreateBackend must be called. |
84 bool HasCreatedBackend() const; | 93 bool HasCreatedBackend() const; |
85 | 94 |
86 void set_backend(scoped_ptr<disk_cache::Backend> backend) { | 95 void set_backend(scoped_ptr<disk_cache::Backend> backend) { |
87 backend_ = backend.Pass(); | 96 backend_ = backend.Pass(); |
88 } | 97 } |
89 | 98 |
| 99 disk_cache::Backend* backend() const { return backend_.get(); } |
| 100 |
90 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); | 101 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); |
91 | 102 |
92 private: | 103 private: |
93 ServiceWorkerCache(const base::FilePath& path, | 104 ServiceWorkerCache(const base::FilePath& path, |
94 net::URLRequestContext* request_context, | 105 net::URLRequestContext* request_context, |
95 base::WeakPtr<storage::BlobStorageContext> blob_context); | 106 base::WeakPtr<storage::BlobStorageContext> blob_context); |
96 | 107 |
97 scoped_ptr<disk_cache::Backend> backend_; | 108 scoped_ptr<disk_cache::Backend> backend_; |
98 base::FilePath path_; | 109 base::FilePath path_; |
99 net::URLRequestContext* request_context_; | 110 net::URLRequestContext* request_context_; |
100 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 111 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
101 | 112 |
102 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; | 113 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; |
103 | 114 |
104 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); | 115 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); |
105 }; | 116 }; |
106 | 117 |
107 } // namespace content | 118 } // namespace content |
108 | 119 |
109 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ | 120 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ |
OLD | NEW |