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

Unified Diff: device/usb/usb_device_handle_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.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/usb/usb_device_handle_impl.cc
diff --git a/device/usb/usb_device_handle_impl.cc b/device/usb/usb_device_handle_impl.cc
index 1b7e5609d7cf011ae1b2375ef05fc962300b718e..d8b28a923100fe6b534060c5b84149c8d81b51f0 100644
--- a/device/usb/usb_device_handle_impl.cc
+++ b/device/usb/usb_device_handle_impl.cc
@@ -830,6 +830,11 @@ void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread(
void UsbDeviceHandleImpl::SetConfigurationComplete(
bool success,
const ResultCallback& callback) {
+ if (!device_) {
+ callback.Run(false);
+ return;
+ }
+
if (success) {
device_->RefreshActiveConfiguration();
RefreshEndpointMap();
@@ -857,6 +862,16 @@ void UsbDeviceHandleImpl::ClaimInterfaceOnBlockingThread(
void UsbDeviceHandleImpl::ClaimInterfaceComplete(
scoped_refptr<InterfaceClaimer> interface_claimer,
const ResultCallback& callback) {
+ if (!device_) {
+ // Ensure that the InterfaceClaimer is released on the blocking thread.
+ InterfaceClaimer* raw_interface_claimer = interface_claimer.get();
+ interface_claimer->AddRef();
+ interface_claimer = nullptr;
+ blocking_task_runner_->ReleaseSoon(FROM_HERE, raw_interface_claimer);
+ callback.Run(false);
+ return;
+ }
+
if (interface_claimer) {
claimed_interfaces_[interface_claimer->interface_number()] =
interface_claimer;
@@ -888,6 +903,11 @@ void UsbDeviceHandleImpl::SetInterfaceAlternateSettingComplete(
int alternate_setting,
bool success,
const ResultCallback& callback) {
+ if (!device_) {
+ callback.Run(false);
+ return;
+ }
+
if (success) {
claimed_interfaces_[interface_number]->set_alternate_setting(
alternate_setting);
@@ -919,6 +939,7 @@ void UsbDeviceHandleImpl::ClearHaltOnBlockingThread(
void UsbDeviceHandleImpl::RefreshEndpointMap() {
DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(device_);
endpoint_map_.clear();
const UsbConfigDescriptor* config = device_->active_configuration();
if (config) {
« no previous file with comments | « device/usb/mojo/device_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698