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

Side by Side Diff: Source/modules/webaudio/AudioContext.cpp

Issue 783423003: Make ScriptPromiseResolver RefCountedWillBeRefCountedGarbageCollected. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 AutoLocker locker(this); 621 AutoLocker locker(this);
622 622
623 if (isOfflineContext()) { 623 if (isOfflineContext()) {
624 return ScriptPromise::rejectWithDOMException( 624 return ScriptPromise::rejectWithDOMException(
625 scriptState, 625 scriptState,
626 DOMException::create( 626 DOMException::create(
627 InvalidStateError, 627 InvalidStateError,
628 "cannot suspend an OfflineAudioContext")); 628 "cannot suspend an OfflineAudioContext"));
629 } 629 }
630 630
631 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 631 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
632 ScriptPromise promise = resolver->promise(); 632 ScriptPromise promise = resolver->promise();
633 633
634 // Save the resolver which will get resolved at the end of the rendering qua ntum. 634 // Save the resolver which will get resolved at the end of the rendering qua ntum.
635 m_suspendResolvers.append(resolver); 635 m_suspendResolvers.append(resolver);
636 636
637 return promise; 637 return promise;
638 } 638 }
639 639
640 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) 640 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState)
641 { 641 {
642 ASSERT(isMainThread()); 642 ASSERT(isMainThread());
643 AutoLocker locker(this); 643 AutoLocker locker(this);
644 644
645 if (isOfflineContext()) { 645 if (isOfflineContext()) {
646 return ScriptPromise::rejectWithDOMException( 646 return ScriptPromise::rejectWithDOMException(
647 scriptState, 647 scriptState,
648 DOMException::create( 648 DOMException::create(
649 InvalidStateError, 649 InvalidStateError,
650 "cannot resume an OfflineAudioContext")); 650 "cannot resume an OfflineAudioContext"));
651 } 651 }
652 652
653 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState); 653 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
654 ScriptPromise promise = resolver->promise(); 654 ScriptPromise promise = resolver->promise();
655 655
656 // Restart the destination node to pull on the audio graph. 656 // Restart the destination node to pull on the audio graph.
657 if (m_destinationNode) 657 if (m_destinationNode)
658 startRendering(); 658 startRendering();
659 659
660 // Save the resolver which will get resolved when the destination node start s pulling on the 660 // Save the resolver which will get resolved when the destination node start s pulling on the
661 // graph again. 661 // graph again.
662 m_resumeResolvers.append(resolver); 662 m_resumeResolvers.append(resolver);
663 663
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 945
946 for (unsigned i = 0; i < m_renderingAutomaticPullNodes.size(); ++i) 946 for (unsigned i = 0; i < m_renderingAutomaticPullNodes.size(); ++i)
947 m_renderingAutomaticPullNodes[i]->processIfNecessary(framesToProcess); 947 m_renderingAutomaticPullNodes[i]->processIfNecessary(framesToProcess);
948 } 948 }
949 949
950 void AudioContext::resolvePromisesForResumeOnMainThread() 950 void AudioContext::resolvePromisesForResumeOnMainThread()
951 { 951 {
952 ASSERT(isMainThread()); 952 ASSERT(isMainThread());
953 AutoLocker locker(this); 953 AutoLocker locker(this);
954 954
955 for (RefPtr<ScriptPromiseResolver> resolver : m_resumeResolvers) { 955 for (auto& resolver : m_resumeResolvers) {
956 if (m_contextState == Closed) { 956 if (m_contextState == Closed) {
957 resolver->reject( 957 resolver->reject(
958 DOMException::create(InvalidStateError, "Cannot resume a context that has been closed")); 958 DOMException::create(InvalidStateError, "Cannot resume a context that has been closed"));
959 } else { 959 } else {
960 resolver->resolve(); 960 resolver->resolve();
961 } 961 }
962 } 962 }
963 963
964 m_resumeResolvers.clear(); 964 m_resumeResolvers.clear();
965 m_isResolvingResumePromises = false; 965 m_isResolvingResumePromises = false;
(...skipping 16 matching lines...) Expand all
982 982
983 void AudioContext::resolvePromisesForSuspendOnMainThread() 983 void AudioContext::resolvePromisesForSuspendOnMainThread()
984 { 984 {
985 ASSERT(isMainThread()); 985 ASSERT(isMainThread());
986 AutoLocker locker(this); 986 AutoLocker locker(this);
987 987
988 // We can stop rendering now. 988 // We can stop rendering now.
989 if (m_destinationNode) 989 if (m_destinationNode)
990 stopRendering(); 990 stopRendering();
991 991
992 for (RefPtr<ScriptPromiseResolver> resolver : m_suspendResolvers) { 992 for (auto& resolver : m_suspendResolvers) {
993 if (m_contextState == Closed) { 993 if (m_contextState == Closed) {
994 resolver->reject( 994 resolver->reject(
995 DOMException::create(InvalidStateError, "Cannot suspend a contex t that has been closed")); 995 DOMException::create(InvalidStateError, "Cannot suspend a contex t that has been closed"));
996 } else { 996 } else {
997 resolver->resolve(); 997 resolver->resolve();
998 } 998 }
999 } 999 }
1000 1000
1001 m_suspendResolvers.clear(); 1001 m_suspendResolvers.clear();
1002 } 1002 }
(...skipping 10 matching lines...) Expand all
1013 1013
1014 } 1014 }
1015 1015
1016 void AudioContext::rejectPendingResolvers() 1016 void AudioContext::rejectPendingResolvers()
1017 { 1017 {
1018 ASSERT(isMainThread()); 1018 ASSERT(isMainThread());
1019 1019
1020 // Audio context is closing down so reject any suspend or resume promises th at are still 1020 // Audio context is closing down so reject any suspend or resume promises th at are still
1021 // pending. 1021 // pending.
1022 1022
1023 for (RefPtr<ScriptPromiseResolver> resolver : m_suspendResolvers) { 1023 for (auto& resolver : m_suspendResolvers) {
1024 resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away")); 1024 resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away"));
1025 } 1025 }
1026 m_suspendResolvers.clear(); 1026 m_suspendResolvers.clear();
1027 1027
1028 for (RefPtr<ScriptPromiseResolver> resolver : m_resumeResolvers) { 1028 for (auto& resolver : m_resumeResolvers) {
1029 resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away")); 1029 resolver->reject(DOMException::create(InvalidStateError, "Audio context is going away"));
1030 } 1030 }
1031 m_resumeResolvers.clear(); 1031 m_resumeResolvers.clear();
1032 m_isResolvingResumePromises = false; 1032 m_isResolvingResumePromises = false;
1033 } 1033 }
1034 1034
1035 const AtomicString& AudioContext::interfaceName() const 1035 const AtomicString& AudioContext::interfaceName() const
1036 { 1036 {
1037 return EventTargetNames::AudioContext; 1037 return EventTargetNames::AudioContext;
1038 } 1038 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 visitor->trace(m_destinationNode); 1093 visitor->trace(m_destinationNode);
1094 visitor->trace(m_listener); 1094 visitor->trace(m_listener);
1095 // trace() can be called in AudioContext constructor, and 1095 // trace() can be called in AudioContext constructor, and
1096 // m_contextGraphMutex might be unavailable. 1096 // m_contextGraphMutex might be unavailable.
1097 if (m_didInitializeContextGraphMutex) { 1097 if (m_didInitializeContextGraphMutex) {
1098 AutoLocker lock(this); 1098 AutoLocker lock(this);
1099 visitor->trace(m_referencedNodes); 1099 visitor->trace(m_referencedNodes);
1100 } else { 1100 } else {
1101 visitor->trace(m_referencedNodes); 1101 visitor->trace(m_referencedNodes);
1102 } 1102 }
1103 visitor->trace(m_resumeResolvers);
1104 visitor->trace(m_suspendResolvers);
1103 visitor->trace(m_liveNodes); 1105 visitor->trace(m_liveNodes);
1104 visitor->trace(m_liveAudioSummingJunctions); 1106 visitor->trace(m_liveAudioSummingJunctions);
1105 EventTargetWithInlineData::trace(visitor); 1107 EventTargetWithInlineData::trace(visitor);
1106 } 1108 }
1107 1109
1108 void AudioContext::addChangedChannelCountMode(AudioNode* node) 1110 void AudioContext::addChangedChannelCountMode(AudioNode* node)
1109 { 1111 {
1110 ASSERT(isGraphOwner()); 1112 ASSERT(isGraphOwner());
1111 ASSERT(isMainThread()); 1113 ASSERT(isMainThread());
1112 m_deferredCountModeChange.add(node); 1114 m_deferredCountModeChange.add(node);
(...skipping 12 matching lines...) Expand all
1125 1127
1126 for (HashSet<AudioNode*>::iterator k = m_deferredCountModeChange.begin(); k != m_deferredCountModeChange.end(); ++k) 1128 for (HashSet<AudioNode*>::iterator k = m_deferredCountModeChange.begin(); k != m_deferredCountModeChange.end(); ++k)
1127 (*k)->updateChannelCountMode(); 1129 (*k)->updateChannelCountMode();
1128 1130
1129 m_deferredCountModeChange.clear(); 1131 m_deferredCountModeChange.clear();
1130 } 1132 }
1131 1133
1132 } // namespace blink 1134 } // namespace blink
1133 1135
1134 #endif // ENABLE(WEB_AUDIO) 1136 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698