Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Unified Diff: content/child/service_worker/web_service_worker_provider_impl.cc

Issue 477593007: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/service_worker/web_service_worker_provider_impl.cc
diff --git a/content/child/service_worker/web_service_worker_provider_impl.cc b/content/child/service_worker/web_service_worker_provider_impl.cc
index 5b6edbff80fa45c45105718a9d3b62e1a9ddf50d..c416440b052bbc1b55e44a600d505b5c168ddb40 100644
--- a/content/child/service_worker/web_service_worker_provider_impl.cc
+++ b/content/child/service_worker/web_service_worker_provider_impl.cc
@@ -10,7 +10,9 @@
#include "content/child/service_worker/service_worker_dispatcher.h"
#include "content/child/service_worker/service_worker_handle_reference.h"
#include "content/child/service_worker/service_worker_provider_context.h"
+#include "content/child/service_worker/service_worker_registration_handle_reference.h"
#include "content/child/service_worker/web_service_worker_impl.h"
+#include "content/child/service_worker/web_service_worker_registration_impl.h"
#include "content/child/thread_safe_sender.h"
#include "content/common/service_worker/service_worker_messages.h"
#include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h"
@@ -47,6 +49,30 @@ void WebServiceWorkerProviderImpl::setClient(
// for more context)
GetDispatcher()->AddScriptClient(provider_id_, client);
+ if (!context_->registration()) {
+ // This provider is not associated with any registration.
+ return;
+ }
+
+ // Set .ready if the associated registration has the active service worker.
+ if (context_->active_handle_id() != kInvalidServiceWorkerHandleId) {
+ WebServiceWorkerRegistrationImpl* registration =
+ GetDispatcher()->FindServiceWorkerRegistration(
+ context_->registration()->info(), false);
+ if (!registration) {
+ registration = GetDispatcher()->CreateServiceWorkerRegistration(
+ context_->registration()->info(), false);
+ ServiceWorkerVersionAttributes attrs = context_->GetVersionAttributes();
+ registration->SetInstalling(
+ GetDispatcher()->GetServiceWorker(attrs.installing, false));
+ registration->SetWaiting(
+ GetDispatcher()->GetServiceWorker(attrs.waiting, false));
+ registration->SetActive(
+ GetDispatcher()->GetServiceWorker(attrs.active, false));
+ }
+ client->setReadyRegistration(registration);
+ }
+
if (context_->controller_handle_id() != kInvalidServiceWorkerHandleId) {
client->setController(GetDispatcher()->GetServiceWorker(
context_->controller()->info(), false));

Powered by Google App Engine
This is Rietveld 408576698