| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" | 5 #include "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| 11 #include "core/dom/TaskRunnerHelper.h" |
| 11 #include "modules/audio_output_devices/AudioOutputDeviceClient.h" | 12 #include "modules/audio_output_devices/AudioOutputDeviceClient.h" |
| 12 #include "modules/audio_output_devices/SetSinkIdCallbacks.h" | 13 #include "modules/audio_output_devices/SetSinkIdCallbacks.h" |
| 13 #include "public/platform/WebSecurityOrigin.h" | 14 #include "public/platform/WebSecurityOrigin.h" |
| 14 #include "wtf/PtrUtil.h" | 15 #include "wtf/PtrUtil.h" |
| 15 #include <memory> | 16 #include <memory> |
| 16 | 17 |
| 17 namespace blink { | 18 namespace blink { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class SetSinkIdResolver : public ScriptPromiseResolver { | 22 class SetSinkIdResolver : public ScriptPromiseResolver { |
| 22 WTF_MAKE_NONCOPYABLE(SetSinkIdResolver); | 23 WTF_MAKE_NONCOPYABLE(SetSinkIdResolver); |
| 23 | 24 |
| 24 public: | 25 public: |
| 25 static SetSinkIdResolver* create(ScriptState*, | 26 static SetSinkIdResolver* create(ScriptState*, |
| 26 HTMLMediaElement&, | 27 HTMLMediaElement&, |
| 27 const String& sinkId); | 28 const String& sinkId); |
| 28 ~SetSinkIdResolver() override = default; | 29 ~SetSinkIdResolver() override = default; |
| 29 void startAsync(); | 30 void startAsync(); |
| 30 | 31 |
| 31 DECLARE_VIRTUAL_TRACE(); | 32 DECLARE_VIRTUAL_TRACE(); |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 SetSinkIdResolver(ScriptState*, HTMLMediaElement&, const String& sinkId); | 35 SetSinkIdResolver(ScriptState*, HTMLMediaElement&, const String& sinkId); |
| 35 void timerFired(TimerBase*); | 36 void timerFired(TimerBase*); |
| 36 | 37 |
| 37 Member<HTMLMediaElement> m_element; | 38 Member<HTMLMediaElement> m_element; |
| 38 String m_sinkId; | 39 String m_sinkId; |
| 39 Timer<SetSinkIdResolver> m_timer; | 40 TaskRunnerTimer<SetSinkIdResolver> m_timer; |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 SetSinkIdResolver* SetSinkIdResolver::create(ScriptState* scriptState, | 43 SetSinkIdResolver* SetSinkIdResolver::create(ScriptState* scriptState, |
| 43 HTMLMediaElement& element, | 44 HTMLMediaElement& element, |
| 44 const String& sinkId) { | 45 const String& sinkId) { |
| 45 SetSinkIdResolver* resolver = | 46 SetSinkIdResolver* resolver = |
| 46 new SetSinkIdResolver(scriptState, element, sinkId); | 47 new SetSinkIdResolver(scriptState, element, sinkId); |
| 47 resolver->suspendIfNeeded(); | 48 resolver->suspendIfNeeded(); |
| 48 resolver->keepAliveWhilePending(); | 49 resolver->keepAliveWhilePending(); |
| 49 return resolver; | 50 return resolver; |
| 50 } | 51 } |
| 51 | 52 |
| 52 SetSinkIdResolver::SetSinkIdResolver(ScriptState* scriptState, | 53 SetSinkIdResolver::SetSinkIdResolver(ScriptState* scriptState, |
| 53 HTMLMediaElement& element, | 54 HTMLMediaElement& element, |
| 54 const String& sinkId) | 55 const String& sinkId) |
| 55 : ScriptPromiseResolver(scriptState), | 56 : ScriptPromiseResolver(scriptState), |
| 56 m_element(element), | 57 m_element(element), |
| 57 m_sinkId(sinkId), | 58 m_sinkId(sinkId), |
| 58 m_timer(this, &SetSinkIdResolver::timerFired) {} | 59 m_timer(TaskRunnerHelper::get(TaskType::MiscPlatformAPI, scriptState), |
| 60 this, |
| 61 &SetSinkIdResolver::timerFired) {} |
| 59 | 62 |
| 60 void SetSinkIdResolver::startAsync() { | 63 void SetSinkIdResolver::startAsync() { |
| 61 m_timer.startOneShot(0, BLINK_FROM_HERE); | 64 m_timer.startOneShot(0, BLINK_FROM_HERE); |
| 62 } | 65 } |
| 63 | 66 |
| 64 void SetSinkIdResolver::timerFired(TimerBase* timer) { | 67 void SetSinkIdResolver::timerFired(TimerBase* timer) { |
| 65 ExecutionContext* context = getExecutionContext(); | 68 ExecutionContext* context = getExecutionContext(); |
| 66 ASSERT(context && context->isDocument()); | 69 ASSERT(context && context->isDocument()); |
| 67 std::unique_ptr<SetSinkIdCallbacks> callbacks = | 70 std::unique_ptr<SetSinkIdCallbacks> callbacks = |
| 68 WTF::wrapUnique(new SetSinkIdCallbacks(this, *m_element, m_sinkId)); | 71 WTF::wrapUnique(new SetSinkIdCallbacks(this, *m_element, m_sinkId)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 provideTo(element, supplementName(), supplement); | 141 provideTo(element, supplementName(), supplement); |
| 139 } | 142 } |
| 140 return *supplement; | 143 return *supplement; |
| 141 } | 144 } |
| 142 | 145 |
| 143 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) { | 146 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) { |
| 144 Supplement<HTMLMediaElement>::trace(visitor); | 147 Supplement<HTMLMediaElement>::trace(visitor); |
| 145 } | 148 } |
| 146 | 149 |
| 147 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |