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 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/barrier_closure.h" | 12 #include "base/barrier_closure.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
19 #include "content/browser/service_worker/service_worker_context_core.h" | 19 #include "content/browser/service_worker/service_worker_context_core.h" |
20 #include "content/browser/service_worker/service_worker_context_observer.h" | 20 #include "content/browser/service_worker/service_worker_context_observer.h" |
21 #include "content/browser/service_worker/service_worker_process_manager.h" | 21 #include "content/browser/service_worker/service_worker_process_manager.h" |
22 #include "content/browser/service_worker/service_worker_quota_client.h" | 22 #include "content/browser/service_worker/service_worker_quota_client.h" |
23 #include "content/browser/service_worker/service_worker_request_handler.h" | 23 #include "content/browser/service_worker/service_worker_request_handler.h" |
24 #include "content/browser/service_worker/service_worker_utils.h" | |
24 #include "content/browser/storage_partition_impl.h" | 25 #include "content/browser/storage_partition_impl.h" |
25 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/service_worker_context.h" | 28 #include "content/public/browser/service_worker_context.h" |
28 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
30 #include "net/base/net_util.h" | |
29 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
30 #include "storage/browser/blob/blob_storage_context.h" | 32 #include "storage/browser/blob/blob_storage_context.h" |
31 #include "storage/browser/quota/quota_manager_proxy.h" | 33 #include "storage/browser/quota/quota_manager_proxy.h" |
32 #include "storage/browser/quota/special_storage_policy.h" | 34 #include "storage/browser/quota/special_storage_policy.h" |
33 | 35 |
34 namespace content { | 36 namespace content { |
35 | 37 |
36 namespace { | 38 namespace { |
37 | 39 |
38 typedef std::set<std::string> HeaderNameSet; | 40 typedef std::set<std::string> HeaderNameSet; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 usage_info.scopes.push_back(registration_info.pattern); | 273 usage_info.scopes.push_back(registration_info.pattern); |
272 usage_info.total_size_bytes += registration_info.stored_version_size_bytes; | 274 usage_info.total_size_bytes += registration_info.stored_version_size_bytes; |
273 } | 275 } |
274 | 276 |
275 for (const auto& origin_info_pair : origins) { | 277 for (const auto& origin_info_pair : origins) { |
276 usage_infos.push_back(origin_info_pair.second); | 278 usage_infos.push_back(origin_info_pair.second); |
277 } | 279 } |
278 callback.Run(usage_infos); | 280 callback.Run(usage_infos); |
279 } | 281 } |
280 | 282 |
283 void ServiceWorkerContextWrapper:: | |
284 DidFindRegistrationForCheckHasSameServiceWorker( | |
285 const GURL& other_url, | |
286 const CheckHasSameServiceWorkerCallback& callback, | |
287 ServiceWorkerStatusCode status, | |
288 const scoped_refptr<ServiceWorkerRegistration>& registration) { | |
289 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
290 | |
291 bool has_same = status == SERVICE_WORKER_OK; | |
292 if (has_same) { | |
293 DCHECK(registration); | |
294 has_same = | |
295 ServiceWorkerUtils::ScopeMatches(registration->pattern(), other_url); | |
falken
2015/02/05 10:26:11
There might be a bug here depending on the use cas
benwells
2015/02/05 12:38:29
That's interesting, I didn't realise that could be
| |
296 } | |
297 | |
298 callback.Run(has_same); | |
falken
2015/02/05 10:26:11
subjective style nit: the use of has_same is a bit
benwells
2015/02/05 12:38:29
Done.
| |
299 } | |
300 | |
281 namespace { | 301 namespace { |
282 void StatusCodeToBoolCallbackAdapter( | 302 void StatusCodeToBoolCallbackAdapter( |
283 const ServiceWorkerContext::ResultCallback& callback, | 303 const ServiceWorkerContext::ResultCallback& callback, |
284 ServiceWorkerStatusCode code) { | 304 ServiceWorkerStatusCode code) { |
285 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); | 305 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); |
286 } | 306 } |
287 | 307 |
288 void EmptySuccessCallback(bool success) { | 308 void EmptySuccessCallback(bool success) { |
289 } | 309 } |
290 } // namespace | 310 } // namespace |
(...skipping 11 matching lines...) Expand all Loading... | |
302 return; | 322 return; |
303 } | 323 } |
304 context()->UnregisterServiceWorkers( | 324 context()->UnregisterServiceWorkers( |
305 origin_url, base::Bind(&StatusCodeToBoolCallbackAdapter, result)); | 325 origin_url, base::Bind(&StatusCodeToBoolCallbackAdapter, result)); |
306 } | 326 } |
307 | 327 |
308 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { | 328 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { |
309 DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback)); | 329 DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback)); |
310 } | 330 } |
311 | 331 |
332 void ServiceWorkerContextWrapper::CheckHasSameServiceWorker( | |
333 const GURL& url, | |
334 const GURL& other_url, | |
335 const CheckHasSameServiceWorkerCallback& callback) { | |
no sievers
2015/02/04 19:46:05
This is a bit odd: It can be called from any threa
benwells
2015/02/05 02:09:25
Fair enough. I've outlined some options below, it
falken
2015/02/05 10:26:11
I chatted a bit offline with Ben, I think it's OK
benwells
2015/02/05 12:38:29
I've changed it to reply on the UI thread.
kinuko
2015/02/05 14:24:24
Yep, we ended up with the current code after a few
| |
336 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
337 BrowserThread::PostTask( | |
338 BrowserThread::IO, FROM_HERE, | |
339 base::Bind(&ServiceWorkerContextWrapper::CheckHasSameServiceWorker, | |
340 this, url, other_url, callback)); | |
341 return; | |
342 } | |
343 if (!context_core_.get()) { | |
344 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
345 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
346 base::Bind(callback, false)); | |
347 return; | |
348 } | |
349 GURL stripped_url = net::SimplifyUrlForRequest(url); | |
350 context()->storage()->FindRegistrationForDocument( | |
351 stripped_url, | |
352 base::Bind(&ServiceWorkerContextWrapper:: | |
353 DidFindRegistrationForCheckHasSameServiceWorker, | |
354 this, other_url, callback)); | |
355 } | |
356 | |
312 void ServiceWorkerContextWrapper::AddObserver( | 357 void ServiceWorkerContextWrapper::AddObserver( |
313 ServiceWorkerContextObserver* observer) { | 358 ServiceWorkerContextObserver* observer) { |
314 observer_list_->AddObserver(observer); | 359 observer_list_->AddObserver(observer); |
315 } | 360 } |
316 | 361 |
317 void ServiceWorkerContextWrapper::RemoveObserver( | 362 void ServiceWorkerContextWrapper::RemoveObserver( |
318 ServiceWorkerContextObserver* observer) { | 363 ServiceWorkerContextObserver* observer) { |
319 observer_list_->RemoveObserver(observer); | 364 observer_list_->RemoveObserver(observer); |
320 } | 365 } |
321 | 366 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 context_core_.reset(); | 423 context_core_.reset(); |
379 return; | 424 return; |
380 } | 425 } |
381 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 426 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
382 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 427 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
383 | 428 |
384 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); | 429 observer_list_->Notify(&ServiceWorkerContextObserver::OnStorageWiped); |
385 } | 430 } |
386 | 431 |
387 } // namespace content | 432 } // namespace content |
OLD | NEW |