Chromium Code Reviews| 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" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 USBDevice::USBDevice(usb::DeviceInfoPtr deviceInfo, usb::DevicePtr device, Execu tionContext* context) | 94 USBDevice::USBDevice(usb::DeviceInfoPtr deviceInfo, usb::DevicePtr device, Execu tionContext* context) |
| 95 : ContextLifecycleObserver(context) | 95 : ContextLifecycleObserver(context) |
| 96 , m_deviceInfo(std::move(deviceInfo)) | 96 , m_deviceInfo(std::move(deviceInfo)) |
| 97 , m_device(std::move(device)) | 97 , m_device(std::move(device)) |
| 98 , m_opened(false) | 98 , m_opened(false) |
| 99 , m_deviceStateChangeInProgress(false) | 99 , m_deviceStateChangeInProgress(false) |
| 100 , m_configurationIndex(-1) | 100 , m_configurationIndex(-1) |
| 101 { | 101 { |
| 102 if (m_device) { | 102 if (m_device) |
| 103 m_device.set_connection_error_handler([this]() { | 103 m_device.set_connection_error_handler(createBaseCallback(bind(&USBDevice ::onConnectionError, WeakPersistentThisPointer<USBDevice>(this)))); |
|
haraken
2016/04/25 08:47:05
Just to confirm: Your intention is that the error
| |
| 104 m_device.reset(); | |
| 105 m_opened = false; | |
| 106 for (ScriptPromiseResolver* resolver : m_deviceRequests) { | |
| 107 if (isActive(resolver)) | |
| 108 resolver->reject(DOMException::create(NotFoundError, kDevice Unavailable)); | |
| 109 } | |
| 110 }); | |
| 111 } | |
| 112 int configurationIndex = findConfigurationIndex(info().active_configuration) ; | 104 int configurationIndex = findConfigurationIndex(info().active_configuration) ; |
| 113 if (configurationIndex != -1) | 105 if (configurationIndex != -1) |
| 114 onConfigurationSelected(true /* success */, configurationIndex); | 106 onConfigurationSelected(true /* success */, configurationIndex); |
| 115 } | 107 } |
| 116 | 108 |
| 117 USBDevice::~USBDevice() | 109 USBDevice::~USBDevice() |
| 118 { | 110 { |
| 119 DCHECK(!m_device); | 111 // |m_device| may still be valid but there should be no more outstanding |
| 112 // requests because each holds a persistent handle to this object. | |
| 120 DCHECK(m_deviceRequests.isEmpty()); | 113 DCHECK(m_deviceRequests.isEmpty()); |
| 121 } | 114 } |
| 122 | 115 |
| 123 bool USBDevice::isInterfaceClaimed(size_t configurationIndex, size_t interfaceIn dex) const | 116 bool USBDevice::isInterfaceClaimed(size_t configurationIndex, size_t interfaceIn dex) const |
| 124 { | 117 { |
| 125 return m_configurationIndex != -1 && static_cast<size_t>(m_configurationInde x) == configurationIndex && m_claimedInterfaces.get(interfaceIndex); | 118 return m_configurationIndex != -1 && static_cast<size_t>(m_configurationInde x) == configurationIndex && m_claimedInterfaces.get(interfaceIndex); |
| 126 } | 119 } |
| 127 | 120 |
| 128 size_t USBDevice::selectedAlternateInterface(size_t interfaceIndex) const | 121 size_t USBDevice::selectedAlternateInterface(size_t interfaceIndex) const |
| 129 { | 122 { |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 m_deviceRequests.remove(resolver); | 783 m_deviceRequests.remove(resolver); |
| 791 if (!isActive(resolver)) | 784 if (!isActive(resolver)) |
| 792 return; | 785 return; |
| 793 | 786 |
| 794 if (success) | 787 if (success) |
| 795 resolver->resolve(); | 788 resolver->resolve(); |
| 796 else | 789 else |
| 797 resolver->reject(DOMException::create(NetworkError, "Unable to reset the device.")); | 790 resolver->reject(DOMException::create(NetworkError, "Unable to reset the device.")); |
| 798 } | 791 } |
| 799 | 792 |
| 793 void USBDevice::onConnectionError() | |
| 794 { | |
| 795 m_device.reset(); | |
| 796 m_opened = false; | |
| 797 for (ScriptPromiseResolver* resolver : m_deviceRequests) { | |
| 798 if (isActive(resolver)) | |
| 799 resolver->reject(DOMException::create(NotFoundError, kDeviceUnavaila ble)); | |
| 800 } | |
| 801 m_deviceRequests.clear(); | |
| 802 } | |
| 803 | |
| 800 } // namespace blink | 804 } // namespace blink |
| OLD | NEW |