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

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

Issue 330173003: Make ServiceWorker an ActiveDOMObject (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments Created 6 years, 6 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/ServiceWorker.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorker.cpp b/Source/modules/serviceworkers/ServiceWorker.cpp
index b1de87b41bdaa829ed13beb2cea9383ad9f28c18..1ae06c5eb3928e824c6d4259ab989a5d9f96cb6c 100644
--- a/Source/modules/serviceworkers/ServiceWorker.cpp
+++ b/Source/modules/serviceworkers/ServiceWorker.cpp
@@ -86,7 +86,7 @@ void ServiceWorker::postMessage(PassRefPtr<SerializedScriptValue> message, const
bool ServiceWorker::isReady()
{
- return !m_isPromisePending;
+ return m_proxyState == Ready;
}
void ServiceWorker::dispatchStateChangeEvent()
@@ -161,21 +161,56 @@ PassRefPtr<ServiceWorker> ServiceWorker::from(ScriptPromiseResolverWithContext*
return serviceWorker;
}
+void ServiceWorker::setProxyState(ProxyState state)
dominicc (has gone to gerrit) 2014/06/13 19:55:13 This is very nice and neat.
falken 2014/06/13 22:34:18 Thanks!
+{
+ if (m_proxyState == state)
+ return;
+ switch (m_proxyState) {
+ case Initial:
+ ASSERT(state == RegisterPromisePending || state == ContextStopped);
+ break;
+ case RegisterPromisePending:
+ ASSERT(state == Ready || state == ContextStopped);
+ break;
+ case Ready:
+ ASSERT(state == ContextStopped);
+ break;
+ case ContextStopped:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+
+ ProxyState oldState = m_proxyState;
+ m_proxyState = state;
+ if (oldState == Ready || state == Ready)
+ m_outerWorker->proxyReadyChanged();
+}
+
void ServiceWorker::onPromiseResolved()
{
- ASSERT(m_isPromisePending);
- m_isPromisePending = false;
- m_outerWorker->proxyReadyChanged();
+ if (m_proxyState == ContextStopped)
+ return;
+ setProxyState(Ready);
}
void ServiceWorker::waitOnPromise(ScriptPromise promise)
{
- ASSERT(!m_isPromisePending);
- m_isPromisePending = true;
- m_outerWorker->proxyReadyChanged();
+ setProxyState(RegisterPromisePending);
promise.then(ThenFunction::create(this));
}
+bool ServiceWorker::hasPendingActivity() const
+{
+ if (m_proxyState == ContextStopped)
+ return false;
+ return m_outerWorker->state() != blink::WebServiceWorkerStateDeactivated;
+}
+
+void ServiceWorker::stop()
+{
+ setProxyState(ContextStopped);
+}
+
PassRefPtr<ServiceWorker> ServiceWorker::create(ExecutionContext* executionContext, PassOwnPtr<blink::WebServiceWorker> outerWorker)
{
RefPtr<ServiceWorker> worker = adoptRef(new ServiceWorker(executionContext, outerWorker));
@@ -187,7 +222,7 @@ ServiceWorker::ServiceWorker(ExecutionContext* executionContext, PassOwnPtr<blin
: AbstractWorker(executionContext)
, WebServiceWorkerProxy(this)
, m_outerWorker(worker)
- , m_isPromisePending(false)
+ , m_proxyState(Initial)
{
ScriptWrappable::init(this);
ASSERT(m_outerWorker);

Powered by Google App Engine
This is Rietveld 408576698