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

Unified Diff: device/usb/mojo/device_impl.cc

Issue 1695643002: Destroy DeviceImpl when the underlying UsbDevice is disconnected. (Closed) Base URL: reillyg-linux.mtv.corp.google.com:/src/chromium/src@mojo_device_autoclose
Patch Set: Revert change to web_usb_device_impl.cc. Created 4 years, 10 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 | « device/usb/mojo/device_impl.h ('k') | device/usb/mojo/device_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/mojo/device_impl.cc
diff --git a/device/usb/mojo/device_impl.cc b/device/usb/mojo/device_impl.cc
index 0d1c64f6a2dd1336fe8b659ce9407633af9dbdf7..ae5f4bb53bef88d4f4324f13b163606e3df0f381 100644
--- a/device/usb/mojo/device_impl.cc
+++ b/device/usb/mojo/device_impl.cc
@@ -179,13 +179,17 @@ void OnIsochronousTransferOut(
DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device,
PermissionProviderPtr permission_provider,
mojo::InterfaceRequest<Device> request)
- : binding_(this, std::move(request)),
- device_(device),
+ : device_(device),
+ observer_(this),
permission_provider_(std::move(permission_provider)),
+ binding_(this, std::move(request)),
weak_factory_(this) {
- // This object owns itself and will be destroyed if either the message pipe
- // it is bound to is closed or the PermissionProvider it depends on is
- // unavailable.
+ DCHECK(device_);
+ // This object owns itself and will be destroyed if,
+ // * the device is disconnected,
+ // * the message pipe it is bound to is closed, or
+ // * the PermissionProvider it depends on is unavailable.
+ observer_.Add(device_.get());
binding_.set_connection_error_handler([this]() { delete this; });
permission_provider_.set_connection_error_handler([this]() { delete this; });
}
@@ -463,5 +467,10 @@ void DeviceImpl::IsochronousTransferOut(
base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr)));
}
+void DeviceImpl::OnDeviceRemoved(scoped_refptr<UsbDevice> device) {
+ DCHECK_EQ(device_, device);
+ delete this;
+}
+
} // namespace usb
} // namespace device
« no previous file with comments | « device/usb/mojo/device_impl.h ('k') | device/usb/mojo/device_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698