| 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" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 void RemotePlayback::notifyInitialAvailability(int callbackId) { | 198 void RemotePlayback::notifyInitialAvailability(int callbackId) { |
| 199 // May not find the callback if the website cancels it fast enough. | 199 // May not find the callback if the website cancels it fast enough. |
| 200 auto iter = m_availabilityCallbacks.find(callbackId); | 200 auto iter = m_availabilityCallbacks.find(callbackId); |
| 201 if (iter == m_availabilityCallbacks.end()) | 201 if (iter == m_availabilityCallbacks.end()) |
| 202 return; | 202 return; |
| 203 | 203 |
| 204 iter->value->call(this, m_availability); | 204 iter->value->call(this, m_availability); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void RemotePlayback::stateChanged(WebRemotePlaybackState state) { | 207 void RemotePlayback::stateChanged(WebRemotePlaybackState state) { |
| 208 // We may get a "disconnected" state change while in the "disconnected" | 208 if (m_state == state) |
| 209 // state if initiated connection fails. So cleanup the promise resolvers | 209 return; |
| 210 // before checking if anything changed. | 210 |
| 211 // TODO(avayvod): cleanup this logic when implementing the "connecting" | |
| 212 // state. | |
| 213 if (m_promptPromiseResolver) { | 211 if (m_promptPromiseResolver) { |
| 214 // Changing state to Disconnected from "disconnected" or "connecting" means | 212 // Changing state to Disconnected from "disconnected" or "connecting" means |
| 215 // that establishing connection with remote playback device failed. | 213 // that establishing connection with remote playback device failed. |
| 216 // Changing state to anything else means the state change intended by | 214 // Changing state to anything else means the state change intended by |
| 217 // prompt() succeeded. | 215 // prompt() succeeded. |
| 218 if (m_state != WebRemotePlaybackState::Connected && | 216 if (m_state != WebRemotePlaybackState::Connected && |
| 219 state == WebRemotePlaybackState::Disconnected) { | 217 state == WebRemotePlaybackState::Disconnected) { |
| 220 m_promptPromiseResolver->reject(DOMException::create( | 218 m_promptPromiseResolver->reject(DOMException::create( |
| 221 AbortError, "Failed to connect to the remote device.")); | 219 AbortError, "Failed to connect to the remote device.")); |
| 222 } else { | 220 } else { |
| 221 DCHECK((m_state == WebRemotePlaybackState::Disconnected && |
| 222 state == WebRemotePlaybackState::Connecting) || |
| 223 (m_state == WebRemotePlaybackState::Connected && |
| 224 state == WebRemotePlaybackState::Disconnected)); |
| 223 m_promptPromiseResolver->resolve(); | 225 m_promptPromiseResolver->resolve(); |
| 224 } | 226 } |
| 225 m_promptPromiseResolver = nullptr; | 227 m_promptPromiseResolver = nullptr; |
| 226 } | 228 } |
| 227 | 229 |
| 228 if (m_state == state) | |
| 229 return; | |
| 230 | |
| 231 m_state = state; | 230 m_state = state; |
| 232 switch (m_state) { | 231 switch (m_state) { |
| 233 case WebRemotePlaybackState::Connecting: | 232 case WebRemotePlaybackState::Connecting: |
| 234 dispatchEvent(Event::create(EventTypeNames::connecting)); | 233 dispatchEvent(Event::create(EventTypeNames::connecting)); |
| 235 break; | 234 break; |
| 236 case WebRemotePlaybackState::Connected: | 235 case WebRemotePlaybackState::Connected: |
| 237 dispatchEvent(Event::create(EventTypeNames::connect)); | 236 dispatchEvent(Event::create(EventTypeNames::connect)); |
| 238 break; | 237 break; |
| 239 case WebRemotePlaybackState::Disconnected: | 238 case WebRemotePlaybackState::Disconnected: |
| 240 dispatchEvent(Event::create(EventTypeNames::disconnect)); | 239 dispatchEvent(Event::create(EventTypeNames::disconnect)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 287 } |
| 289 | 288 |
| 290 DEFINE_TRACE_WRAPPERS(RemotePlayback) { | 289 DEFINE_TRACE_WRAPPERS(RemotePlayback) { |
| 291 for (auto callback : m_availabilityCallbacks.values()) { | 290 for (auto callback : m_availabilityCallbacks.values()) { |
| 292 visitor->traceWrappers(callback); | 291 visitor->traceWrappers(callback); |
| 293 } | 292 } |
| 294 EventTargetWithInlineData::traceWrappers(visitor); | 293 EventTargetWithInlineData::traceWrappers(visitor); |
| 295 } | 294 } |
| 296 | 295 |
| 297 } // namespace blink | 296 } // namespace blink |
| OLD | NEW |