OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/remoteplayback/RemotePlayback.h" | 5 #include "modules/remoteplayback/RemotePlayback.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h" | 8 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h" |
9 #include "core/HTMLNames.h" | 9 #include "core/HTMLNames.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
12 #include "core/dom/ExecutionContextTask.h" | |
13 #include "core/dom/TaskRunnerHelper.h" | 12 #include "core/dom/TaskRunnerHelper.h" |
14 #include "core/events/Event.h" | 13 #include "core/events/Event.h" |
15 #include "core/html/HTMLMediaElement.h" | 14 #include "core/html/HTMLMediaElement.h" |
| 15 #include "core/inspector/InspectorInstrumentation.h" |
16 #include "modules/EventTargetModules.h" | 16 #include "modules/EventTargetModules.h" |
17 #include "platform/MemoryCoordinator.h" | 17 #include "platform/MemoryCoordinator.h" |
18 #include "platform/UserGestureIndicator.h" | 18 #include "platform/UserGestureIndicator.h" |
19 | 19 |
20 namespace blink { | 20 namespace blink { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const AtomicString& remotePlaybackStateToString(WebRemotePlaybackState state) { | 24 const AtomicString& remotePlaybackStateToString(WebRemotePlaybackState state) { |
25 DEFINE_STATIC_LOCAL(const AtomicString, connectingValue, ("connecting")); | 25 DEFINE_STATIC_LOCAL(const AtomicString, connectingValue, ("connecting")); |
26 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); | 26 DEFINE_STATIC_LOCAL(const AtomicString, connectedValue, ("connected")); |
27 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected")); | 27 DEFINE_STATIC_LOCAL(const AtomicString, disconnectedValue, ("disconnected")); |
28 | 28 |
29 switch (state) { | 29 switch (state) { |
30 case WebRemotePlaybackState::Connecting: | 30 case WebRemotePlaybackState::Connecting: |
31 return connectingValue; | 31 return connectingValue; |
32 case WebRemotePlaybackState::Connected: | 32 case WebRemotePlaybackState::Connected: |
33 return connectedValue; | 33 return connectedValue; |
34 case WebRemotePlaybackState::Disconnected: | 34 case WebRemotePlaybackState::Disconnected: |
35 return disconnectedValue; | 35 return disconnectedValue; |
36 } | 36 } |
37 | 37 |
38 ASSERT_NOT_REACHED(); | 38 ASSERT_NOT_REACHED(); |
39 return disconnectedValue; | 39 return disconnectedValue; |
40 } | 40 } |
41 | 41 |
| 42 void runNotifyInitialAvailabilityTask(ExecutionContext* context, |
| 43 std::unique_ptr<WTF::Closure> task) { |
| 44 InspectorInstrumentation::AsyncTask asyncTask(context, task.get()); |
| 45 (*task)(); |
| 46 } |
| 47 |
42 } // anonymous namespace | 48 } // anonymous namespace |
43 | 49 |
44 // static | 50 // static |
45 RemotePlayback* RemotePlayback::create(HTMLMediaElement& element) { | 51 RemotePlayback* RemotePlayback::create(HTMLMediaElement& element) { |
46 return new RemotePlayback(element); | 52 return new RemotePlayback(element); |
47 } | 53 } |
48 | 54 |
49 RemotePlayback::RemotePlayback(HTMLMediaElement& element) | 55 RemotePlayback::RemotePlayback(HTMLMediaElement& element) |
50 : m_state(element.isPlayingRemotely() | 56 : m_state(element.isPlayingRemotely() |
51 ? WebRemotePlaybackState::Connected | 57 ? WebRemotePlaybackState::Connected |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 int id; | 89 int id; |
84 do { | 90 do { |
85 id = getExecutionContext()->circularSequentialID(); | 91 id = getExecutionContext()->circularSequentialID(); |
86 } while ( | 92 } while ( |
87 !m_availabilityCallbacks | 93 !m_availabilityCallbacks |
88 .insert(id, TraceWrapperMember<RemotePlaybackAvailabilityCallback>( | 94 .insert(id, TraceWrapperMember<RemotePlaybackAvailabilityCallback>( |
89 this, callback)) | 95 this, callback)) |
90 .isNewEntry); | 96 .isNewEntry); |
91 | 97 |
92 // Report the current availability via the callback. | 98 // Report the current availability via the callback. |
93 getExecutionContext()->postTask( | 99 // TODO(yuryu): Wrapping notifyInitialAvailability with WTF::Closure as |
94 TaskType::MediaElementEvent, BLINK_FROM_HERE, | 100 // InspectorInstrumentation requires a globally unique pointer to track tasks. |
95 createSameThreadTask(&RemotePlayback::notifyInitialAvailability, | 101 // We can remove the wrapper if InspectorInstrumentation returns a task id. |
96 wrapPersistent(this), id), | 102 std::unique_ptr<WTF::Closure> task = WTF::bind( |
97 "watchAvailabilityCallback"); | 103 &RemotePlayback::notifyInitialAvailability, wrapPersistent(this), id); |
| 104 InspectorInstrumentation::asyncTaskScheduled( |
| 105 getExecutionContext(), "watchAvailabilityCallback", task.get()); |
| 106 TaskRunnerHelper::get(TaskType::MediaElementEvent, getExecutionContext()) |
| 107 ->postTask(BLINK_FROM_HERE, |
| 108 WTF::bind(runNotifyInitialAvailabilityTask, |
| 109 wrapPersistent(getExecutionContext()), |
| 110 WTF::passed(std::move(task)))); |
98 | 111 |
99 // TODO(avayvod): Currently the availability is tracked for each media element | 112 // TODO(avayvod): Currently the availability is tracked for each media element |
100 // as soon as it's created, we probably want to limit that to when the | 113 // as soon as it's created, we probably want to limit that to when the |
101 // page/element is visible (see https://crbug.com/597281) and has default | 114 // page/element is visible (see https://crbug.com/597281) and has default |
102 // controls. If there are no default controls, we should also start tracking | 115 // controls. If there are no default controls, we should also start tracking |
103 // availability on demand meaning the Promise returned by watchAvailability() | 116 // availability on demand meaning the Promise returned by watchAvailability() |
104 // will be resolved asynchronously. | 117 // will be resolved asynchronously. |
105 resolver->resolve(id); | 118 resolver->resolve(id); |
106 return promise; | 119 return promise; |
107 } | 120 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 314 } |
302 | 315 |
303 DEFINE_TRACE_WRAPPERS(RemotePlayback) { | 316 DEFINE_TRACE_WRAPPERS(RemotePlayback) { |
304 for (auto callback : m_availabilityCallbacks.values()) { | 317 for (auto callback : m_availabilityCallbacks.values()) { |
305 visitor->traceWrappers(callback); | 318 visitor->traceWrappers(callback); |
306 } | 319 } |
307 EventTargetWithInlineData::traceWrappers(visitor); | 320 EventTargetWithInlineData::traceWrappers(visitor); |
308 } | 321 } |
309 | 322 |
310 } // namespace blink | 323 } // namespace blink |
OLD | NEW |