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

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

Issue 330173003: Make ServiceWorker an ActiveDOMObject (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: patch for landing 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
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorker.h ('k') | Source/modules/serviceworkers/ServiceWorker.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/ServiceWorker.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorker.cpp b/Source/modules/serviceworkers/ServiceWorker.cpp
index b1de87b41bdaa829ed13beb2cea9383ad9f28c18..84bca65e79e81427d9d0f4b574245993cbde3738 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,58 @@ PassRefPtr<ServiceWorker> ServiceWorker::from(ScriptPromiseResolverWithContext*
return serviceWorker;
}
+void ServiceWorker::setProxyState(ProxyState state)
+{
+ 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 (AbstractWorker::hasPendingActivity())
+ return true;
+ 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 +224,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);
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorker.h ('k') | Source/modules/serviceworkers/ServiceWorker.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698