Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Unified Diff: third_party/WebKit/Source/modules/webusb/USBDevice.cpp

Issue 1912223002: Make new WebUSB implementation more resilient to garbage collection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased again. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webusb/USBDevice.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/WebKit/Source/modules/webusb/USBDevice.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698