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