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..719c03f595cb79bd4546be9131c999faf68b5c78 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( |
falken
2017/03/17 07:54:37
This name is a bit inconsistent with SW nomenclatu
piotrs
2017/03/21 00:00:43
Chunk of the work of this method is taking right s
|
+ const ServiceWorkerContext::CheckServiceWorkerStatusCallback callback, |
+ scoped_refptr<ServiceWorkerRegistration> registration) { |
+ ServiceWorkerVersion* sw_version = registration->active_version() |
+ ? registration->active_version() |
+ : registration->waiting_version(); |
falken
2017/03/17 07:54:37
Are you sure you want the active version to overri
piotrs
2017/03/21 00:00:43
Done + added a comment for posterity as it's possi
|
+ |
+ DCHECK(sw_version); |
+ |
+ ServiceWorkerVersion::FetchHandlerExistence existence = |
+ sw_version->fetch_handler_existence(); |
+ |
+ DCHECK(existence != ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); |
falken
2017/03/17 07:54:37
nit: Is it possible to use DCHECK_NE here?
piotrs
2017/03/21 00:00:44
Done.
|
+ |
+ 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); |
+ CheckFetchHandlerOfRegisteredServiceWorker(callback, registration); |
} |
-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; |
+ } |
+ |
+ CheckFetchHandlerOfRegisteredServiceWorker(callback, registration); |
} |
} // namespace content |