| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/usb/usb_device_handle_impl.h" | 5 #include "device/usb/usb_device_handle_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 : device_(device), | 775 : device_(device), |
| 776 handle_(handle), | 776 handle_(handle), |
| 777 context_(context), | 777 context_(context), |
| 778 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 778 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 779 blocking_task_runner_(blocking_task_runner) { | 779 blocking_task_runner_(blocking_task_runner) { |
| 780 DCHECK(handle) << "Cannot create device with NULL handle."; | 780 DCHECK(handle) << "Cannot create device with NULL handle."; |
| 781 } | 781 } |
| 782 | 782 |
| 783 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() { | 783 UsbDeviceHandleImpl::~UsbDeviceHandleImpl() { |
| 784 // This class is RefCountedThreadSafe and so the destructor may be called on | 784 // This class is RefCountedThreadSafe and so the destructor may be called on |
| 785 // any thread. | 785 // any thread. libusb is not safe to reentrancy so be sure not to try to close |
| 786 libusb_close(handle_); | 786 // the device from inside a transfer completion callback. |
| 787 if (blocking_task_runner_->RunsTasksOnCurrentThread()) { |
| 788 libusb_close(handle_); |
| 789 } else { |
| 790 blocking_task_runner_->PostTask(FROM_HERE, |
| 791 base::Bind(&libusb_close, handle_)); |
| 792 } |
| 787 } | 793 } |
| 788 | 794 |
| 789 void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread( | 795 void UsbDeviceHandleImpl::SetConfigurationOnBlockingThread( |
| 790 int configuration_value, | 796 int configuration_value, |
| 791 const ResultCallback& callback) { | 797 const ResultCallback& callback) { |
| 792 int rv = libusb_set_configuration(handle_, configuration_value); | 798 int rv = libusb_set_configuration(handle_, configuration_value); |
| 793 if (rv != LIBUSB_SUCCESS) { | 799 if (rv != LIBUSB_SUCCESS) { |
| 794 USB_LOG(EVENT) << "Failed to set configuration " << configuration_value | 800 USB_LOG(EVENT) << "Failed to set configuration " << configuration_value |
| 795 << ": " << ConvertPlatformUsbErrorToString(rv); | 801 << ": " << ConvertPlatformUsbErrorToString(rv); |
| 796 } | 802 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 map_entry.second = nullptr; | 1126 map_entry.second = nullptr; |
| 1121 blocking_task_runner_->ReleaseSoon(FROM_HERE, interface_claimer); | 1127 blocking_task_runner_->ReleaseSoon(FROM_HERE, interface_claimer); |
| 1122 } | 1128 } |
| 1123 | 1129 |
| 1124 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to | 1130 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to |
| 1125 // finish. | 1131 // finish. |
| 1126 device_ = nullptr; | 1132 device_ = nullptr; |
| 1127 } | 1133 } |
| 1128 | 1134 |
| 1129 } // namespace device | 1135 } // namespace device |
| OLD | NEW |