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