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/webusb/USBDevice.h" | 5 #include "modules/webusb/USBDevice.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "bindings/core/v8/ToV8.h" | 9 #include "bindings/core/v8/ToV8.h" |
10 #include "core/dom/DOMArrayBuffer.h" | 10 #include "core/dom/DOMArrayBuffer.h" |
11 #include "core/dom/DOMArrayBufferView.h" | 11 #include "core/dom/DOMArrayBufferView.h" |
12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
13 #include "core/dom/ExceptionCode.h" | 13 #include "core/dom/ExceptionCode.h" |
14 #include "core/frame/UseCounter.h" | 14 #include "core/frame/UseCounter.h" |
15 #include "modules/webusb/USBConfiguration.h" | 15 #include "modules/webusb/USBConfiguration.h" |
16 #include "modules/webusb/USBControlTransferParameters.h" | 16 #include "modules/webusb/USBControlTransferParameters.h" |
17 #include "modules/webusb/USBInTransferResult.h" | 17 #include "modules/webusb/USBInTransferResult.h" |
18 #include "modules/webusb/USBIsochronousInTransferResult.h" | 18 #include "modules/webusb/USBIsochronousInTransferResult.h" |
19 #include "modules/webusb/USBIsochronousOutTransferResult.h" | 19 #include "modules/webusb/USBIsochronousOutTransferResult.h" |
20 #include "modules/webusb/USBOutTransferResult.h" | 20 #include "modules/webusb/USBOutTransferResult.h" |
21 #include "platform/mojo/MojoHelper.h" | 21 #include "platform/mojo/MojoHelper.h" |
| 22 #include "public/platform/Platform.h" |
22 #include "wtf/Assertions.h" | 23 #include "wtf/Assertions.h" |
23 | 24 |
24 namespace usb = device::usb::blink; | 25 namespace usb = device::usb::blink; |
25 | 26 |
26 namespace blink { | 27 namespace blink { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const char kDeviceStateChangeInProgress[] = | 31 const char kDeviceStateChangeInProgress[] = |
31 "An operation that changes the device state is in progress."; | 32 "An operation that changes the device state is in progress."; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 96 |
96 USBDevice::USBDevice(usb::DeviceInfoPtr deviceInfo, | 97 USBDevice::USBDevice(usb::DeviceInfoPtr deviceInfo, |
97 usb::DevicePtr device, | 98 usb::DevicePtr device, |
98 ExecutionContext* context) | 99 ExecutionContext* context) |
99 : ContextLifecycleObserver(context), | 100 : ContextLifecycleObserver(context), |
100 m_deviceInfo(std::move(deviceInfo)), | 101 m_deviceInfo(std::move(deviceInfo)), |
101 m_device(std::move(device)), | 102 m_device(std::move(device)), |
102 m_opened(false), | 103 m_opened(false), |
103 m_deviceStateChangeInProgress(false), | 104 m_deviceStateChangeInProgress(false), |
104 m_configurationIndex(-1) { | 105 m_configurationIndex(-1) { |
105 if (m_device) | 106 if (m_device) { |
106 m_device.set_connection_error_handler(convertToBaseCallback( | 107 m_device.set_connection_error_handler(convertToBaseCallback( |
107 WTF::bind(&USBDevice::onConnectionError, wrapWeakPersistent(this)))); | 108 WTF::bind(&USBDevice::onConnectionError, wrapWeakPersistent(this)))); |
| 109 } |
108 int configurationIndex = findConfigurationIndex(info().active_configuration); | 110 int configurationIndex = findConfigurationIndex(info().active_configuration); |
109 if (configurationIndex != -1) | 111 if (configurationIndex != -1) |
110 onConfigurationSelected(true /* success */, configurationIndex); | 112 onConfigurationSelected(true /* success */, configurationIndex); |
111 } | 113 } |
112 | 114 |
113 USBDevice::~USBDevice() { | 115 USBDevice::~USBDevice() { |
114 // |m_device| may still be valid but there should be no more outstanding | 116 // |m_device| may still be valid but there should be no more outstanding |
115 // requests because each holds a persistent handle to this object. | 117 // requests because each holds a persistent handle to this object. |
116 DCHECK(m_deviceRequests.isEmpty()); | 118 DCHECK(m_deviceRequests.isEmpty()); |
117 } | 119 } |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 return; | 932 return; |
931 | 933 |
932 if (success) | 934 if (success) |
933 resolver->resolve(); | 935 resolver->resolve(); |
934 else | 936 else |
935 resolver->reject( | 937 resolver->reject( |
936 DOMException::create(NetworkError, "Unable to reset the device.")); | 938 DOMException::create(NetworkError, "Unable to reset the device.")); |
937 } | 939 } |
938 | 940 |
939 void USBDevice::onConnectionError() { | 941 void USBDevice::onConnectionError() { |
| 942 if (!Platform::current()) { |
| 943 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
| 944 return; |
| 945 } |
| 946 |
940 m_device.reset(); | 947 m_device.reset(); |
941 m_opened = false; | 948 m_opened = false; |
942 for (ScriptPromiseResolver* resolver : m_deviceRequests) | 949 for (ScriptPromiseResolver* resolver : m_deviceRequests) |
943 resolver->reject(DOMException::create(NotFoundError, kDeviceUnavailable)); | 950 resolver->reject(DOMException::create(NotFoundError, kDeviceUnavailable)); |
944 m_deviceRequests.clear(); | 951 m_deviceRequests.clear(); |
945 } | 952 } |
946 | 953 |
947 bool USBDevice::markRequestComplete(ScriptPromiseResolver* resolver) { | 954 bool USBDevice::markRequestComplete(ScriptPromiseResolver* resolver) { |
948 auto requestEntry = m_deviceRequests.find(resolver); | 955 auto requestEntry = m_deviceRequests.find(resolver); |
949 if (requestEntry == m_deviceRequests.end()) | 956 if (requestEntry == m_deviceRequests.end()) |
950 return false; | 957 return false; |
951 m_deviceRequests.remove(requestEntry); | 958 m_deviceRequests.remove(requestEntry); |
952 return true; | 959 return true; |
953 } | 960 } |
954 | 961 |
955 } // namespace blink | 962 } // namespace blink |
OLD | NEW |