Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: content/browser/service_worker/service_worker_cache.h

Issue 701403002: [ServiceWorkerCache Cleanup] Make the state of the cache backend explicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@close_async
Patch Set: Nits Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); 102 base::WeakPtr<ServiceWorkerCache> AsWeakPtr();
103 103
104 private: 104 private:
105 friend class base::RefCounted<ServiceWorkerCache>; 105 friend class base::RefCounted<ServiceWorkerCache>;
106 friend class TestServiceWorkerCache; 106 friend class TestServiceWorkerCache;
107 107
108 class BlobReader; 108 class BlobReader;
109 struct KeysContext; 109 struct KeysContext;
110 struct PutContext; 110 struct PutContext;
111
112 // The backend progresses from uninitialized, to open, to closed, and cannot
113 // reverse direction. The open step may be skipped.
114 enum BackendState {
115 BackendUninitialized, // No backend, create backend on first operation.
falken 2014/11/07 05:03:21 Style nit: chromium enums are SNAKE_CASE
jkarlin 2014/11/07 18:55:57 Thanks! Done in https://codereview.chromium.org/69
116 BackendOpen, // Backend can be used.
117 BackendClosed // Backend cannot be used. All ops should fail.
118 };
119
111 typedef std::vector<disk_cache::Entry*> Entries; 120 typedef std::vector<disk_cache::Entry*> Entries;
112 121
113 ServiceWorkerCache( 122 ServiceWorkerCache(
114 const GURL& origin, 123 const GURL& origin,
115 const base::FilePath& path, 124 const base::FilePath& path,
116 net::URLRequestContext* request_context, 125 net::URLRequestContext* request_context,
117 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy, 126 const scoped_refptr<storage::QuotaManagerProxy>& quota_manager_proxy,
118 base::WeakPtr<storage::BlobStorageContext> blob_context); 127 base::WeakPtr<storage::BlobStorageContext> blob_context);
119 128
120 // Operations in progress will complete after the cache is deleted but pending 129 // Operations in progress will complete after the cache is deleted but pending
(...skipping 20 matching lines...) Expand all
141 const Entries::iterator& iter); 150 const Entries::iterator& iter);
142 static void KeysDidReadMetadata( 151 static void KeysDidReadMetadata(
143 scoped_ptr<KeysContext> keys_context, 152 scoped_ptr<KeysContext> keys_context,
144 const Entries::iterator& iter, 153 const Entries::iterator& iter,
145 scoped_ptr<ServiceWorkerCacheMetadata> metadata); 154 scoped_ptr<ServiceWorkerCacheMetadata> metadata);
146 155
147 // Loads the backend and calls the callback with the result (true for 156 // Loads the backend and calls the callback with the result (true for
148 // success). The callback will always be called. Virtual for tests. 157 // success). The callback will always be called. Virtual for tests.
149 virtual void CreateBackend(const ErrorCallback& callback); 158 virtual void CreateBackend(const ErrorCallback& callback);
150 159
151 void Init(const base::Closure& callback); 160 void InitBackend(const base::Closure& callback);
152 void InitDone(ErrorType error); 161 void InitDone(ErrorType error);
153 162
154 void IncPendingOps() { pending_ops_++; } 163 void IncPendingOps() { pending_ops_++; }
155 void DecPendingOps(); 164 void DecPendingOps();
156 void PendingErrorCallback(const ErrorCallback& callback, ErrorType error); 165 void PendingErrorCallback(const ErrorCallback& callback, ErrorType error);
157 void PendingResponseCallback( 166 void PendingResponseCallback(
158 const ResponseCallback& callback, 167 const ResponseCallback& callback,
159 ErrorType error, 168 ErrorType error,
160 scoped_ptr<ServiceWorkerResponse> response, 169 scoped_ptr<ServiceWorkerResponse> response,
161 scoped_ptr<storage::BlobDataHandle> blob_data_handle); 170 scoped_ptr<storage::BlobDataHandle> blob_data_handle);
162 void PendingRequestsCallback(const RequestsCallback& callback, 171 void PendingRequestsCallback(const RequestsCallback& callback,
163 ErrorType error, 172 ErrorType error,
164 scoped_ptr<Requests> requests); 173 scoped_ptr<Requests> requests);
165 174
166 // The backend can be deleted via the Close function at any time so always 175 // The backend can be deleted via the Close function at any time so always
167 // check for its existence before use. 176 // check for its existence before use.
168 scoped_ptr<disk_cache::Backend> backend_; 177 scoped_ptr<disk_cache::Backend> backend_;
169 GURL origin_; 178 GURL origin_;
170 base::FilePath path_; 179 base::FilePath path_;
171 net::URLRequestContext* request_context_; 180 net::URLRequestContext* request_context_;
172 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_; 181 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy_;
173 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; 182 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
174 bool initialized_; 183 BackendState backend_state_;
175 std::vector<base::Closure> init_callbacks_; 184 std::vector<base::Closure> init_callbacks_;
176 185
177 // Whether or not to store data in disk or memory. 186 // Whether or not to store data in disk or memory.
178 bool memory_only_; 187 bool memory_only_;
179 188
180 // The number of started operations that have yet to complete. 189 // The number of started operations that have yet to complete.
181 // TODO(jkarlin): pending_ops_ gets double counted on lazy initialization (say 190 // TODO(jkarlin): pending_ops_ gets double counted on lazy initialization (say
182 // in ::Put). The counting still works but pending_ops_ doesn't accurately 191 // in ::Put). The counting still works but pending_ops_ doesn't accurately
183 // represent the number of operations in flight. Fix this by having the lazy 192 // represent the number of operations in flight. Fix this by having the lazy
184 // init callback call a different function than the original caller (::Put). 193 // init callback call a different function than the original caller (::Put).
185 size_t pending_ops_; 194 size_t pending_ops_;
186 base::Closure ops_complete_callback_; 195 base::Closure ops_complete_callback_;
187 196
188 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; 197 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_;
189 198
190 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); 199 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache);
191 }; 200 };
192 201
193 } // namespace content 202 } // namespace content
194 203
195 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ 204 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698