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

Unified Diff: Source/modules/webaudio/AudioContext.cpp

Issue 1123603002: Process suspend() and resume() in call order (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update according to review Created 5 years, 7 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/webaudio/AudioContext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webaudio/AudioContext.cpp
diff --git a/Source/modules/webaudio/AudioContext.cpp b/Source/modules/webaudio/AudioContext.cpp
index 1764b43b07152918cbc22777983d92388d4b52f3..845d729fa5598817b70e1853536a9758697f6fdb 100644
--- a/Source/modules/webaudio/AudioContext.cpp
+++ b/Source/modules/webaudio/AudioContext.cpp
@@ -151,7 +151,6 @@ AudioContext::~AudioContext()
ASSERT(!m_isInitialized);
ASSERT(!m_activeSourceNodes.size());
ASSERT(!m_finishedSourceHandlers.size());
- ASSERT(!m_suspendResolvers.size());
ASSERT(!m_isResolvingResumePromises);
ASSERT(!m_resumeResolvers.size());
}
@@ -762,14 +761,17 @@ ScriptPromise AudioContext::suspendContext(ScriptState* scriptState)
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- // Save the resolver. If the context is running, it will get resolved at the end of a rendering
- // quantum. Otherwise, resolve it now.
- m_suspendResolvers.append(resolver);
+ if (m_contextState == Closed) {
+ resolver->reject(
+ DOMException::create(InvalidStateError, "Cannot suspend a context that has been closed"));
+ } else {
+ // Stop rendering now.
+ if (m_destinationNode)
+ stopRendering();
- if (m_contextState != Running) {
- // Context is not running so we can't wait for a rendering quantum to resolve the
- // promise. Just resolve it now (along with any other pending suspend promises).
- resolvePromisesForSuspendOnMainThread();
+ // Since we don't have any way of knowing when the hardware actually stops, we'll just
+ // resolve the promise now.
+ resolver->resolve();
}
return promise;
@@ -902,8 +904,6 @@ void AudioContext::handlePostRenderTasks()
deferredTaskHandler().handleDeferredTasks();
deferredTaskHandler().requestToDeleteHandlersOnMainThread();
- resolvePromisesForSuspend();
-
unlock();
}
}
@@ -941,49 +941,11 @@ void AudioContext::resolvePromisesForResume()
}
}
-void AudioContext::resolvePromisesForSuspendOnMainThread()
-{
- ASSERT(isMainThread());
- AutoLocker locker(this);
-
- // We can stop rendering now.
- if (m_destinationNode)
- stopRendering();
-
- for (auto& resolver : m_suspendResolvers) {
- if (m_contextState == Closed) {
- resolver->reject(
- DOMException::create(InvalidStateError, "Cannot suspend a context that has been closed"));
- } else {
- resolver->resolve();
- }
- }
-
- m_suspendResolvers.clear();
-}
-
-void AudioContext::resolvePromisesForSuspend()
-{
- // This runs inside the AudioContext's lock when handling pre-render tasks.
- ASSERT(isAudioThread());
- ASSERT(isGraphOwner());
-
- // Resolve any pending promises created by suspend()
- if (m_suspendResolvers.size() > 0)
- Platform::current()->mainThread()->postTask(FROM_HERE, threadSafeBind(&AudioContext::resolvePromisesForSuspendOnMainThread, this));
-}
-
void AudioContext::rejectPendingResolvers()
{
ASSERT(isMainThread());
- // Audio context is closing down so reject any suspend or resume promises that are still
- // pending.
-
- for (auto& resolver : m_suspendResolvers) {
- resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away"));
- }
- m_suspendResolvers.clear();
+ // Audio context is closing down so reject any resume promises that are still pending.
for (auto& resolver : m_resumeResolvers) {
resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away"));
@@ -1067,7 +1029,6 @@ DEFINE_TRACE(AudioContext)
visitor->trace(m_activeSourceNodes);
}
visitor->trace(m_resumeResolvers);
- visitor->trace(m_suspendResolvers);
RefCountedGarbageCollectedEventTargetWithInlineData<AudioContext>::trace(visitor);
ActiveDOMObject::trace(visitor);
}
« no previous file with comments | « Source/modules/webaudio/AudioContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698