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

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: rebase on 478693005 (Ship Oilpan for serviceworkers/) 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 be2a0a8785d3ed7374eda6447310306503d8eead..2a6352767a6c3b46e0efe5176a073b3160816f66 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 {
ServiceWorkerContainer* ServiceWorkerContainer::create(ExecutionContext* executionContext)
@@ -80,6 +78,7 @@ void ServiceWorkerContainer::trace(Visitor* visitor)
visitor->trace(m_controller);
visitor->trace(m_installing);
visitor->trace(m_waiting);
+ visitor->trace(m_readyRegistration);
visitor->trace(m_ready);
}
@@ -195,32 +194,39 @@ static void deleteIfNoExistingOwner(WebServiceWorker* serviceWorker)
delete serviceWorker;
}
-void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker)
+static void deleteIfNoExistingOwner(WebServiceWorkerRegistration* registration)
+{
+ if (registration && !registration->proxy())
+ delete registration;
+}
+
+void ServiceWorkerContainer::setReadyRegistration(WebServiceWorkerRegistration* registration)
{
if (!executionContext()) {
- deleteIfNoExistingOwner(serviceWorker);
+ deleteIfNoExistingOwner(registration);
return;
}
- RefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker = m_active;
- m_active = ServiceWorker::from(executionContext(), serviceWorker);
- checkReadyChanged(previousReadyWorker.release());
-}
-void ServiceWorkerContainer::checkReadyChanged(PassRefPtrWillBeRawPtr<ServiceWorker> previousReadyWorker)
-{
- ServiceWorker* currentReadyWorker = m_active.get();
+ ServiceWorkerRegistration* readyRegistration = ServiceWorkerRegistration::from(executionContext(), registration);
+ ASSERT(readyRegistration->active());
- if (previousReadyWorker == currentReadyWorker)
+ if (m_readyRegistration) {
+ ASSERT(m_readyRegistration == readyRegistration);
+ ASSERT(m_ready->state() == ReadyProperty::Resolved);
return;
-
- if (m_ready->state() != ReadyProperty::Pending) {
- // Already resolved Promises are now stale because the
- // ready worker changed
- m_ready = createReadyProperty();
}
- if (currentReadyWorker)
- m_ready->resolve(currentReadyWorker);
+ m_readyRegistration = readyRegistration;
+ m_ready->resolve(readyRegistration);
+}
+
+void ServiceWorkerContainer::setActive(WebServiceWorker* serviceWorker)
+{
+ if (!executionContext()) {
+ deleteIfNoExistingOwner(serviceWorker);
+ return;
+ }
+ m_active = ServiceWorker::from(executionContext(), serviceWorker);
}
void ServiceWorkerContainer::setController(WebServiceWorker* serviceWorker)
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerContainer.h ('k') | Source/modules/serviceworkers/ServiceWorkerRegistration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698