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 29 matching lines...) Expand all Loading... |
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 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( | 49 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( |
50 const std::string& name, | |
51 net::URLRequestContext* request_context, | 50 net::URLRequestContext* request_context, |
52 base::WeakPtr<storage::BlobStorageContext> blob_context); | 51 base::WeakPtr<storage::BlobStorageContext> blob_context); |
53 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( | 52 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( |
54 const base::FilePath& path, | 53 const base::FilePath& path, |
55 const std::string& name, | |
56 net::URLRequestContext* request_context, | 54 net::URLRequestContext* request_context, |
57 base::WeakPtr<storage::BlobStorageContext> blob_context); | 55 base::WeakPtr<storage::BlobStorageContext> blob_context); |
58 | 56 |
59 virtual ~ServiceWorkerCache(); | 57 virtual ~ServiceWorkerCache(); |
60 | 58 |
61 // Loads the backend and calls the callback with the result (true for | 59 // Loads the backend and calls the callback with the result (true for |
62 // success). This must be called before member functions that require a | 60 // success). This must be called before member functions that require a |
63 // backend are called. The callback will always be called. | 61 // backend are called. The callback will always be called. |
64 void CreateBackend(const ErrorCallback& callback); | 62 void CreateBackend(const ErrorCallback& callback); |
65 | 63 |
(...skipping 15 matching lines...) Expand all Loading... |
81 // valid until the callback is called. | 79 // valid until the callback is called. |
82 void Delete(ServiceWorkerFetchRequest* request, | 80 void Delete(ServiceWorkerFetchRequest* request, |
83 const ErrorCallback& callback); | 81 const ErrorCallback& callback); |
84 | 82 |
85 // Call to determine if CreateBackend must be called. | 83 // Call to determine if CreateBackend must be called. |
86 bool HasCreatedBackend() const; | 84 bool HasCreatedBackend() const; |
87 | 85 |
88 void set_backend(scoped_ptr<disk_cache::Backend> backend) { | 86 void set_backend(scoped_ptr<disk_cache::Backend> backend) { |
89 backend_ = backend.Pass(); | 87 backend_ = backend.Pass(); |
90 } | 88 } |
91 void set_name(const std::string& name) { name_ = name; } | |
92 const std::string& name() const { return name_; } | |
93 int32 id() const { return id_; } | |
94 void set_id(int32 id) { id_ = id; } | |
95 | 89 |
96 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); | 90 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); |
97 | 91 |
98 private: | 92 private: |
99 ServiceWorkerCache(const base::FilePath& path, | 93 ServiceWorkerCache(const base::FilePath& path, |
100 const std::string& name, | |
101 net::URLRequestContext* request_context, | 94 net::URLRequestContext* request_context, |
102 base::WeakPtr<storage::BlobStorageContext> blob_context); | 95 base::WeakPtr<storage::BlobStorageContext> blob_context); |
103 | 96 |
104 scoped_ptr<disk_cache::Backend> backend_; | 97 scoped_ptr<disk_cache::Backend> backend_; |
105 base::FilePath path_; | 98 base::FilePath path_; |
106 std::string name_; | |
107 net::URLRequestContext* request_context_; | 99 net::URLRequestContext* request_context_; |
108 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 100 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
109 int32 id_; | |
110 | 101 |
111 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; | 102 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; |
112 | 103 |
113 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); | 104 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); |
114 }; | 105 }; |
115 | 106 |
116 } // namespace content | 107 } // namespace content |
117 | 108 |
118 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ | 109 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ |
OLD | NEW |