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

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

Issue 473743002: ServiceWorker: register() should return the existing registration object if available (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix Created 6 years, 4 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/ServiceWorkerRegistration.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerRegistration.cpp b/Source/modules/serviceworkers/ServiceWorkerRegistration.cpp
index ed64100f932e181505add1178506e4b8efb8f8f9..455cf938f645e0b621a2c6ab62ad3218c7b28b06 100644
--- a/Source/modules/serviceworkers/ServiceWorkerRegistration.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerRegistration.cpp
@@ -88,7 +88,7 @@ PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::tak
{
if (!registration)
return nullptr;
- return create(resolver->scriptState()->executionContext(), adoptPtr(registration));
+ return getOrCreate(resolver->scriptState()->executionContext(), adoptPtr(registration));
}
void ServiceWorkerRegistration::dispose(WebType* registration)
@@ -123,8 +123,20 @@ ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState)
return promise;
}
-PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::create(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration)
+PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::getOrCreate(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration)
{
+ if (!outerRegistration)
+ return nullptr;
+
+ WebServiceWorkerRegistrationProxy* proxy = outerRegistration->proxy();
+ if (proxy) {
+ ServiceWorkerRegistration* existingRegistration = *proxy;
+ if (existingRegistration) {
+ ASSERT(existingRegistration->executionContext() == executionContext);
+ return existingRegistration;
+ }
+ }
+
RefPtrWillBeRawPtr<ServiceWorkerRegistration> registration = adoptRefWillBeRefCountedGarbageCollected(new ServiceWorkerRegistration(executionContext, outerRegistration));
registration->suspendIfNeeded();
return registration.release();
@@ -132,6 +144,7 @@ PassRefPtrWillBeRawPtr<ServiceWorkerRegistration> ServiceWorkerRegistration::cre
ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* executionContext, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration)
: ActiveDOMObject(executionContext)
+ , WebServiceWorkerRegistrationProxy(this)
, m_outerRegistration(outerRegistration)
, m_provider(0)
{

Powered by Google App Engine
This is Rietveld 408576698