Chromium Code Reviews| Index: content/browser/service_worker/service_worker_context_core.cc |
| diff --git a/content/browser/service_worker/service_worker_context_core.cc b/content/browser/service_worker/service_worker_context_core.cc |
| index a0bbc665b4cbcdbdb437d04c5d49de1439778830..0fda0541a16585491ba75c026503ed8472dc6711 100644 |
| --- a/content/browser/service_worker/service_worker_context_core.cc |
| +++ b/content/browser/service_worker/service_worker_context_core.cc |
| @@ -32,6 +32,7 @@ |
| #include "content/browser/service_worker/service_worker_register_job.h" |
| #include "content/browser/service_worker/service_worker_registration.h" |
| #include "content/browser/service_worker/service_worker_storage.h" |
| +#include "content/browser/service_worker/service_worker_version.h" |
| #include "content/common/service_worker/service_worker_utils.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "ipc/ipc_message.h" |
| @@ -43,6 +44,25 @@ |
| namespace content { |
| namespace { |
| +void CheckFetchHandlerOfRegisteredServiceWorker( |
| + const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback, |
| + scoped_refptr<ServiceWorkerRegistration> registration) { |
| + ServiceWorkerVersion* sw_version = registration->active_version() |
| + ? registration->active_version() |
| + : registration->waiting_version(); |
| + |
| + DCHECK(sw_version); |
| + |
| + ServiceWorkerVersion::FetchHandlerExistence existence = |
| + sw_version->fetch_handler_existence(); |
| + |
| + DCHECK(existence != ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
| + |
| + callback.Run(existence == ServiceWorkerVersion::FetchHandlerExistence::EXISTS |
| + ? ServiceWorkerStatus::SERVICE_WORKER_WITH_FETCH_HANDLER |
| + : ServiceWorkerStatus::SERVICE_WORKER_NO_FETCH_HANDLER); |
| +} |
| + |
| void SuccessCollectorCallback(const base::Closure& done_closure, |
| bool* overall_success, |
| ServiceWorkerStatusCode status) { |
| @@ -697,13 +717,13 @@ void ServiceWorkerContextCore::ClearAllServiceWorkersForTest( |
| AsWeakPtr())); |
| } |
| -void ServiceWorkerContextCore::CheckHasServiceWorker( |
| +void ServiceWorkerContextCore::CheckServiceWorkerStatus( |
| const GURL& url, |
| const GURL& other_url, |
| - const ServiceWorkerContext::CheckHasServiceWorkerCallback callback) { |
| + const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback) { |
| storage()->FindRegistrationForDocument( |
| url, base::Bind(&ServiceWorkerContextCore:: |
| - DidFindRegistrationForCheckHasServiceWorker, |
| + DidFindRegistrationForCheckServiceWorkerStatus, |
| AsWeakPtr(), other_url, callback)); |
| } |
| @@ -850,42 +870,47 @@ ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { |
| return wrapper_->process_manager(); |
| } |
| -void ServiceWorkerContextCore::DidFindRegistrationForCheckHasServiceWorker( |
| +void ServiceWorkerContextCore::DidFindRegistrationForCheckServiceWorkerStatus( |
| const GURL& other_url, |
| - const ServiceWorkerContext::CheckHasServiceWorkerCallback callback, |
| + const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback, |
| ServiceWorkerStatusCode status, |
| scoped_refptr<ServiceWorkerRegistration> registration) { |
| if (status != SERVICE_WORKER_OK) { |
| - callback.Run(false); |
| + callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); |
| return; |
| } |
| if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), other_url)) { |
| - callback.Run(false); |
| + callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); |
| return; |
| } |
| if (registration->is_uninstalling() || registration->is_uninstalled()) { |
| - callback.Run(false); |
| + callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); |
| return; |
| } |
| if (!registration->active_version() && !registration->waiting_version()) { |
| registration->RegisterRegistrationFinishedCallback( |
| base::Bind(&ServiceWorkerContextCore:: |
| - OnRegistrationFinishedForCheckHasServiceWorker, |
| + OnRegistrationFinishedForCheckServiceWorkerStatus, |
| AsWeakPtr(), callback, registration)); |
| return; |
| } |
| - callback.Run(true); |
| + content::CheckFetchHandlerOfRegisteredServiceWorker(callback, registration); |
|
dominickn
2017/03/16 06:21:57
Nit: this is all inside the content namespace, so
piotrs
2017/03/17 02:21:38
Done.
|
| } |
| -void ServiceWorkerContextCore::OnRegistrationFinishedForCheckHasServiceWorker( |
| - const ServiceWorkerContext::CheckHasServiceWorkerCallback callback, |
| - scoped_refptr<ServiceWorkerRegistration> registration) { |
| - callback.Run(registration->active_version() || |
| - registration->waiting_version()); |
| +void ServiceWorkerContextCore:: |
| + OnRegistrationFinishedForCheckServiceWorkerStatus( |
| + const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback, |
| + scoped_refptr<ServiceWorkerRegistration> registration) { |
| + if (!registration->active_version() && !registration->waiting_version()) { |
| + callback.Run(ServiceWorkerStatus::NO_SERVICE_WORKER); |
| + return; |
| + } |
| + |
| + content::CheckFetchHandlerOfRegisteredServiceWorker(callback, registration); |
|
dominickn
2017/03/16 06:21:57
Nit: this is all inside the content namespace, so
piotrs
2017/03/17 02:21:38
Done.
|
| } |
| } // namespace content |