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

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

Issue 2752523002: Handle USB device disconnection during early setup. (Closed)
Patch Set: Created 3 years, 9 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/usb_device_handle_impl.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 8c6a2f06d7eaacb210ea58b56785674c55f9e811..68b8074e8971b3c884fe650057c79a2df7220dde 100644
--- a/device/usb/mojo/device_impl.cc
+++ b/device/usb/mojo/device_impl.cc
@@ -172,12 +172,20 @@ bool DeviceImpl::HasControlTransferPermission(
}
}
-void DeviceImpl::OnOpen(const OpenCallback& callback,
+// static
+void DeviceImpl::OnOpen(base::WeakPtr<DeviceImpl> self,
+ const OpenCallback& callback,
scoped_refptr<UsbDeviceHandle> handle) {
- device_handle_ = handle;
- if (device_handle_ && permission_provider_)
- permission_provider_->IncrementConnectionCount();
- callback.Run(handle ? OpenDeviceError::OK : OpenDeviceError::ACCESS_DENIED);
+ if (!self) {
+ handle->Close();
+ return;
+ }
+
+ self->device_handle_ = std::move(handle);
+ if (self->device_handle_ && self->permission_provider_)
+ self->permission_provider_->IncrementConnectionCount();
+ callback.Run(self->device_handle_ ? OpenDeviceError::OK
+ : OpenDeviceError::ACCESS_DENIED);
}
void DeviceImpl::OnPermissionGrantedForOpen(const OpenCallback& callback,
« no previous file with comments | « device/usb/mojo/device_impl.h ('k') | device/usb/usb_device_handle_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698