OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/barrier_closure.h" | |
9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
12 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 13 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
13 #include "content/browser/service_worker/service_worker_context_core.h" | 14 #include "content/browser/service_worker/service_worker_context_core.h" |
14 #include "content/browser/service_worker/service_worker_context_observer.h" | 15 #include "content/browser/service_worker/service_worker_context_observer.h" |
15 #include "content/browser/service_worker/service_worker_process_manager.h" | 16 #include "content/browser/service_worker/service_worker_process_manager.h" |
17 #include "content/browser/service_worker/service_worker_quota_client.h" | |
16 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
18 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
19 #include "storage/browser/blob/blob_storage_context.h" | 21 #include "storage/browser/blob/blob_storage_context.h" |
20 #include "storage/browser/quota/quota_manager_proxy.h" | 22 #include "storage/browser/quota/quota_manager_proxy.h" |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( | 26 ServiceWorkerContextWrapper::ServiceWorkerContextWrapper( |
25 BrowserContext* browser_context) | 27 BrowserContext* browser_context) |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 origins.begin(); | 178 origins.begin(); |
177 it != origins.end(); | 179 it != origins.end(); |
178 ++it) { | 180 ++it) { |
179 usage_infos.push_back(it->second); | 181 usage_infos.push_back(it->second); |
180 } | 182 } |
181 | 183 |
182 callback.Run(usage_infos); | 184 callback.Run(usage_infos); |
183 } | 185 } |
184 | 186 |
185 namespace { | 187 namespace { |
188 void ConvertUnregisterToBool( | |
jsbell
2014/10/13 20:54:25
How about: StatusCodeToBoolCallbackAdapter ?
dmurph
2014/10/14 00:16:31
Done.
| |
189 const ServiceWorkerContext::ResultCallback& callback, | |
190 ServiceWorkerStatusCode code) { | |
191 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); | |
192 } | |
186 | 193 |
187 void EmptySuccessCallback(bool success) { | 194 void EmptySuccessCallback(bool success) { |
188 } | 195 } |
189 | |
190 } // namespace | 196 } // namespace |
191 | 197 |
192 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { | 198 void ServiceWorkerContextWrapper::DeleteForOrigin( |
199 const GURL& origin_url, | |
200 const ResultCallback& result) { | |
193 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 201 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
194 context_core_->storage()->GetAllRegistrations(base::Bind( | 202 context_core_->UnregisterServiceWorkers( |
195 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin, | 203 origin_url, base::Bind(&ConvertUnregisterToBool, result)); |
196 this, | |
197 origin_url)); | |
198 } | 204 } |
199 | 205 |
200 void ServiceWorkerContextWrapper::DidGetAllRegistrationsForDeleteForOrigin( | 206 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { |
201 const GURL& origin, | 207 DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback)); |
202 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { | |
203 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
204 | |
205 for (std::vector<ServiceWorkerRegistrationInfo>::const_iterator it = | |
206 registrations.begin(); | |
207 it != registrations.end(); | |
208 ++it) { | |
209 const ServiceWorkerRegistrationInfo& registration_info = *it; | |
210 if (origin == registration_info.pattern.GetOrigin()) { | |
211 UnregisterServiceWorker(registration_info.pattern, | |
212 base::Bind(&EmptySuccessCallback)); | |
213 } | |
214 } | |
215 } | 208 } |
216 | 209 |
217 void ServiceWorkerContextWrapper::AddObserver( | 210 void ServiceWorkerContextWrapper::AddObserver( |
218 ServiceWorkerContextObserver* observer) { | 211 ServiceWorkerContextObserver* observer) { |
219 observer_list_->AddObserver(observer); | 212 observer_list_->AddObserver(observer); |
220 } | 213 } |
221 | 214 |
222 void ServiceWorkerContextWrapper::RemoveObserver( | 215 void ServiceWorkerContextWrapper::RemoveObserver( |
223 ServiceWorkerContextObserver* observer) { | 216 ServiceWorkerContextObserver* observer) { |
224 observer_list_->RemoveObserver(observer); | 217 observer_list_->RemoveObserver(observer); |
(...skipping 24 matching lines...) Expand all Loading... | |
249 base::Bind(&ServiceWorkerContextWrapper::InitInternal, | 242 base::Bind(&ServiceWorkerContextWrapper::InitInternal, |
250 this, | 243 this, |
251 user_data_directory, | 244 user_data_directory, |
252 stores_task_runner, | 245 stores_task_runner, |
253 database_task_runner, | 246 database_task_runner, |
254 disk_cache_thread, | 247 disk_cache_thread, |
255 make_scoped_refptr(quota_manager_proxy))); | 248 make_scoped_refptr(quota_manager_proxy))); |
256 return; | 249 return; |
257 } | 250 } |
258 DCHECK(!context_core_); | 251 DCHECK(!context_core_); |
252 if (quota_manager_proxy) { | |
253 quota_manager_proxy->RegisterClient(new ServiceWorkerQuotaClient(this)); | |
254 } | |
259 context_core_.reset(new ServiceWorkerContextCore(user_data_directory, | 255 context_core_.reset(new ServiceWorkerContextCore(user_data_directory, |
260 stores_task_runner, | 256 stores_task_runner, |
261 database_task_runner, | 257 database_task_runner, |
262 disk_cache_thread, | 258 disk_cache_thread, |
263 quota_manager_proxy, | 259 quota_manager_proxy, |
264 observer_list_.get(), | 260 observer_list_.get(), |
265 this)); | 261 this)); |
266 } | 262 } |
267 | 263 |
268 void ServiceWorkerContextWrapper::ShutdownOnIO() { | 264 void ServiceWorkerContextWrapper::ShutdownOnIO() { |
269 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 265 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
270 context_core_.reset(); | 266 context_core_.reset(); |
271 } | 267 } |
272 | 268 |
273 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( | 269 void ServiceWorkerContextWrapper::DidDeleteAndStartOver( |
274 ServiceWorkerStatusCode status) { | 270 ServiceWorkerStatusCode status) { |
275 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 271 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
276 if (status != SERVICE_WORKER_OK) { | 272 if (status != SERVICE_WORKER_OK) { |
277 context_core_.reset(); | 273 context_core_.reset(); |
278 return; | 274 return; |
279 } | 275 } |
280 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 276 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
281 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 277 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
282 } | 278 } |
283 | 279 |
284 } // namespace content | 280 } // namespace content |
OLD | NEW |