| Index: third_party/WebKit/Source/modules/webusb/USBDevice.cpp
|
| diff --git a/third_party/WebKit/Source/modules/webusb/USBDevice.cpp b/third_party/WebKit/Source/modules/webusb/USBDevice.cpp
|
| index 9bd6d54379d462477d90c10619d5dbd07149a9f7..efde5b47a001960074fcb0bc2c5b434acf783d49 100644
|
| --- a/third_party/WebKit/Source/modules/webusb/USBDevice.cpp
|
| +++ b/third_party/WebKit/Source/modules/webusb/USBDevice.cpp
|
| @@ -99,16 +99,8 @@ USBDevice::USBDevice(usb::DeviceInfoPtr deviceInfo, usb::DevicePtr device, Execu
|
| , m_deviceStateChangeInProgress(false)
|
| , m_configurationIndex(-1)
|
| {
|
| - if (m_device) {
|
| - m_device.set_connection_error_handler([this]() {
|
| - m_device.reset();
|
| - m_opened = false;
|
| - for (ScriptPromiseResolver* resolver : m_deviceRequests) {
|
| - if (isActive(resolver))
|
| - resolver->reject(DOMException::create(NotFoundError, kDeviceUnavailable));
|
| - }
|
| - });
|
| - }
|
| + if (m_device)
|
| + m_device.set_connection_error_handler(createBaseCallback(bind(&USBDevice::onConnectionError, WeakPersistentThisPointer<USBDevice>(this))));
|
| int configurationIndex = findConfigurationIndex(info().active_configuration);
|
| if (configurationIndex != -1)
|
| onConfigurationSelected(true /* success */, configurationIndex);
|
| @@ -116,7 +108,8 @@ USBDevice::USBDevice(usb::DeviceInfoPtr deviceInfo, usb::DevicePtr device, Execu
|
|
|
| USBDevice::~USBDevice()
|
| {
|
| - DCHECK(!m_device);
|
| + // |m_device| may still be valid but there should be no more outstanding
|
| + // requests because each holds a persistent handle to this object.
|
| DCHECK(m_deviceRequests.isEmpty());
|
| }
|
|
|
| @@ -797,4 +790,15 @@ void USBDevice::asyncReset(ScriptPromiseResolver* resolver, bool success)
|
| resolver->reject(DOMException::create(NetworkError, "Unable to reset the device."));
|
| }
|
|
|
| +void USBDevice::onConnectionError()
|
| +{
|
| + m_device.reset();
|
| + m_opened = false;
|
| + for (ScriptPromiseResolver* resolver : m_deviceRequests) {
|
| + if (isActive(resolver))
|
| + resolver->reject(DOMException::create(NotFoundError, kDeviceUnavailable));
|
| + }
|
| + m_deviceRequests.clear();
|
| +}
|
| +
|
| } // namespace blink
|
|
|