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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerRegistration.cpp

Issue 1317473002: ServiceWorker: Clean up ownership management of WebServiceWorkerRegistration (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "ServiceWorkerRegistration.h" 6 #include "ServiceWorkerRegistration.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker) 57 void ServiceWorkerRegistration::setActive(WebServiceWorker* serviceWorker)
58 { 58 {
59 if (!executionContext()) { 59 if (!executionContext()) {
60 deleteIfNoExistingOwner(serviceWorker); 60 deleteIfNoExistingOwner(serviceWorker);
61 return; 61 return;
62 } 62 }
63 m_active = ServiceWorker::from(executionContext(), serviceWorker); 63 m_active = ServiceWorker::from(executionContext(), serviceWorker);
64 } 64 }
65 65
66 ServiceWorkerRegistration* ServiceWorkerRegistration::from(ExecutionContext* exe cutionContext, WebServiceWorkerRegistration* registration) 66 ServiceWorkerRegistration* ServiceWorkerRegistration::create(ExecutionContext* e xecutionContext, PassOwnPtr<WebServiceWorkerRegistration> webRegistration)
67 { 67 {
68 if (!registration) 68 if (!webRegistration)
69 return 0; 69 return nullptr;
70 return getOrCreate(executionContext, registration); 70 ServiceWorkerRegistration* registration = new ServiceWorkerRegistration(exec utionContext, webRegistration);
71 registration->suspendIfNeeded();
72 return registration;
71 } 73 }
72 74
73 ServiceWorkerRegistration* ServiceWorkerRegistration::take(ScriptPromiseResolver * resolver, WebServiceWorkerRegistration* registration) 75 ServiceWorkerRegistration* ServiceWorkerRegistration::take(ScriptPromiseResolver * resolver, PassOwnPtr<WebServiceWorkerRegistration> registration)
74 { 76 {
75 return from(resolver->scriptState()->executionContext(), registration); 77 return create(resolver->scriptState()->executionContext(), registration);
76 }
77
78 void ServiceWorkerRegistration::dispose(WebServiceWorkerRegistration* registrati on)
79 {
80 if (registration && !registration->proxy())
81 delete registration;
82 } 78 }
83 79
84 String ServiceWorkerRegistration::scope() const 80 String ServiceWorkerRegistration::scope() const
85 { 81 {
86 return m_outerRegistration->scope().string(); 82 return m_outerRegistration->scope().string();
87 } 83 }
88 84
89 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState) 85 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState)
90 { 86 {
91 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 87 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
(...skipping 15 matching lines...) Expand all
107 103
108 if (!m_provider) { 104 if (!m_provider) {
109 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre gister a ServiceWorkerRegistration: No associated provider is available.")); 105 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre gister a ServiceWorkerRegistration: No associated provider is available."));
110 return promise; 106 return promise;
111 } 107 }
112 108
113 m_outerRegistration->unregister(m_provider, new CallbackPromiseAdapter<bool, ServiceWorkerError>(resolver)); 109 m_outerRegistration->unregister(m_provider, new CallbackPromiseAdapter<bool, ServiceWorkerError>(resolver));
114 return promise; 110 return promise;
115 } 111 }
116 112
117 ServiceWorkerRegistration* ServiceWorkerRegistration::getOrCreate(ExecutionConte xt* executionContext, WebServiceWorkerRegistration* outerRegistration)
118 {
119 if (!outerRegistration)
120 return 0;
121
122 ServiceWorkerRegistration* existingRegistration = static_cast<ServiceWorkerR egistration*>(outerRegistration->proxy());
123 if (existingRegistration) {
124 ASSERT(existingRegistration->executionContext() == executionContext);
125 return existingRegistration;
126 }
127
128 ServiceWorkerRegistration* registration = new ServiceWorkerRegistration(exec utionContext, adoptPtr(outerRegistration));
129 registration->suspendIfNeeded();
130 return registration;
131 }
132
133 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration) 113 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution Context, PassOwnPtr<WebServiceWorkerRegistration> outerRegistration)
134 : ActiveDOMObject(executionContext) 114 : ActiveDOMObject(executionContext)
135 , m_outerRegistration(outerRegistration) 115 , m_outerRegistration(outerRegistration)
136 , m_provider(0) 116 , m_provider(nullptr)
137 , m_stopped(false) 117 , m_stopped(false)
138 { 118 {
139 ASSERT(m_outerRegistration); 119 ASSERT(m_outerRegistration);
120 ASSERT(!m_outerRegistration->proxy());
140 121
141 if (!executionContext) 122 if (!executionContext)
142 return; 123 return;
143 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext)) 124 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro m(executionContext))
144 m_provider = client->provider(); 125 m_provider = client->provider();
145 m_outerRegistration->setProxy(this); 126 m_outerRegistration->setProxy(this);
146 } 127 }
147 128
148 ServiceWorkerRegistration::~ServiceWorkerRegistration() 129 ServiceWorkerRegistration::~ServiceWorkerRegistration()
149 { 130 {
(...skipping 16 matching lines...) Expand all
166 147
167 void ServiceWorkerRegistration::stop() 148 void ServiceWorkerRegistration::stop()
168 { 149 {
169 if (m_stopped) 150 if (m_stopped)
170 return; 151 return;
171 m_stopped = true; 152 m_stopped = true;
172 m_outerRegistration->proxyStopped(); 153 m_outerRegistration->proxyStopped();
173 } 154 }
174 155
175 } // namespace blink 156 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698