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

Unified Diff: Source/modules/serviceworkers/ServiceWorkerContainer.cpp

Issue 476043002: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (1/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix win build 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: Source/modules/serviceworkers/ServiceWorkerContainer.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
index a34f7748184e6c31e2d037b800df954a000843ca..5a1f485a77a393d97e2131c0247694fcbf6426db 100644
--- a/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerContainer.cpp
@@ -48,12 +48,10 @@
#include "platform/RuntimeEnabledFeatures.h"
#include "public/platform/WebServiceWorker.h"
#include "public/platform/WebServiceWorkerProvider.h"
+#include "public/platform/WebServiceWorkerRegistration.h"
#include "public/platform/WebString.h"
#include "public/platform/WebURL.h"
-using blink::WebServiceWorker;
-using blink::WebServiceWorkerProvider;
-
namespace blink {
PassRefPtrWillBeRawPtr<ServiceWorkerContainer> ServiceWorkerContainer::create(ExecutionContext* executionContext)
@@ -218,32 +216,48 @@ static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker)
delete serviceWorker;
}
+static void deleteIfNoExistingOwner(WebServiceWorkerRegistration* registration)
+{
+ if (registration && !registration->proxy())
+ delete registration;
+}
+
+void ServiceWorkerContainer::setReady(WebServiceWorkerRegistration* registration)
michaeln 2014/09/03 22:27:29 should there be an assertion here that registratio
nhiroki 2014/09/04 08:55:58 Done.
+{
+ if (!executionContext()) {
+ deleteIfNoExistingOwner(registration);
+ return;
+ }
+
+ RefPtrWillBeRawPtr<ServiceWorkerRegistration> previousReadyRegistration = m_readyRegistration;
michaeln 2014/09/03 22:27:29 is it ever expected that the previous reg is not n
nhiroki 2014/09/04 08:55:58 I think the previous reg could be non-null, for ex
nhiroki 2014/09/04 10:45:10 Ah, you're right! The previous reg should always b
nhiroki 2014/09/04 13:06:57 Done. Removed checkReadyChanged() and added ASSERT
+ m_readyRegistration = ServiceWorkerRegistration::from(executionContext(), registration);
+ checkReadyChanged(previousReadyRegistration.release());
+}
+
void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker)
{
if (!executionContext()) {
deleteIfNoExistingOwner(serviceWorker);
return;
}
- RefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker = m_active;
m_active = ServiceWorker::from(executionContext(), serviceWorker);
- checkReadyChanged(previousReadyWorker.release());
}
-void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker)
+void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> previousReadyRegistration)
{
- ServiceWorker* currentReadyWorker = m_active.get();
+ ServiceWorkerRegistration* currentReadyRegistration = m_readyRegistration.get();
- if (previousReadyWorker == currentReadyWorker)
+ if (previousReadyRegistration == currentReadyRegistration)
return;
if (m_ready->state() != ReadyProperty::Pending) {
// Already resolved Promises are now stale because the
- // ready worker changed
+ // ready registration changed
m_ready = createReadyProperty();
}
- if (currentReadyWorker)
- m_ready->resolve(currentReadyWorker);
+ if (currentReadyRegistration)
+ m_ready->resolve(currentReadyRegistration);
}
void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker)

Powered by Google App Engine
This is Rietveld 408576698