Chromium Code Reviews| Index: content/browser/service_worker/service_worker_context_wrapper.cc |
| diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc |
| index db0b4e9fffe6c94a3dcb2da3194f3e4629a666a8..802cf90893469ddf653f107946ed6d766a74a70f 100644 |
| --- a/content/browser/service_worker/service_worker_context_wrapper.cc |
| +++ b/content/browser/service_worker/service_worker_context_wrapper.cc |
| @@ -21,11 +21,13 @@ |
| #include "content/browser/service_worker/service_worker_process_manager.h" |
| #include "content/browser/service_worker/service_worker_quota_client.h" |
| #include "content/browser/service_worker/service_worker_request_handler.h" |
| +#include "content/browser/service_worker/service_worker_utils.h" |
| #include "content/browser/storage_partition_impl.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/service_worker_context.h" |
| #include "net/base/net_errors.h" |
| +#include "net/base/net_util.h" |
| #include "net/url_request/url_request_context_getter.h" |
| #include "storage/browser/blob/blob_storage_context.h" |
| #include "storage/browser/quota/quota_manager_proxy.h" |
| @@ -278,6 +280,24 @@ void ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins( |
| callback.Run(usage_infos); |
| } |
| +void ServiceWorkerContextWrapper:: |
| + DidFindRegistrationForCheckHasSameServiceWorker( |
| + const GURL& other_url, |
| + const CheckHasSameServiceWorkerCallback& callback, |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + |
| + bool has_same = status == SERVICE_WORKER_OK; |
| + if (has_same) { |
| + DCHECK(registration); |
| + has_same = |
| + 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
|
| + } |
| + |
| + 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.
|
| +} |
| + |
| namespace { |
| void StatusCodeToBoolCallbackAdapter( |
| const ServiceWorkerContext::ResultCallback& callback, |
| @@ -309,6 +329,31 @@ void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin_url) { |
| DeleteForOrigin(origin_url, base::Bind(&EmptySuccessCallback)); |
| } |
| +void ServiceWorkerContextWrapper::CheckHasSameServiceWorker( |
| + const GURL& url, |
| + const GURL& other_url, |
| + 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
|
| + if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&ServiceWorkerContextWrapper::CheckHasSameServiceWorker, |
| + this, url, other_url, callback)); |
| + return; |
| + } |
| + if (!context_core_.get()) { |
| + LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(callback, false)); |
| + return; |
| + } |
| + GURL stripped_url = net::SimplifyUrlForRequest(url); |
| + context()->storage()->FindRegistrationForDocument( |
| + stripped_url, |
| + base::Bind(&ServiceWorkerContextWrapper:: |
| + DidFindRegistrationForCheckHasSameServiceWorker, |
| + this, other_url, callback)); |
| +} |
| + |
| void ServiceWorkerContextWrapper::AddObserver( |
| ServiceWorkerContextObserver* observer) { |
| observer_list_->AddObserver(observer); |