| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "components/device_event_log/device_event_log.h" | 17 #include "components/device_event_log/device_event_log.h" |
| 18 #include "device/usb/usb_context.h" | 18 #include "device/usb/usb_context.h" |
| 19 #include "device/usb/usb_descriptors.h" | |
| 20 #include "device/usb/usb_device_impl.h" | 19 #include "device/usb/usb_device_impl.h" |
| 21 #include "device/usb/usb_error.h" | 20 #include "device/usb/usb_error.h" |
| 22 #include "device/usb/usb_service.h" | 21 #include "device/usb/usb_service.h" |
| 23 #include "third_party/libusb/src/libusb/libusb.h" | 22 #include "third_party/libusb/src/libusb/libusb.h" |
| 24 | 23 |
| 25 namespace device { | 24 namespace device { |
| 26 | 25 |
| 27 typedef libusb_device* PlatformUsbDevice; | 26 typedef libusb_device* PlatformUsbDevice; |
| 28 | 27 |
| 29 void HandleTransferCompletion(PlatformUsbTransferHandle transfer); | 28 void HandleTransferCompletion(PlatformUsbTransferHandle transfer); |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 if (rv != LIBUSB_SUCCESS) { | 768 if (rv != LIBUSB_SUCCESS) { |
| 770 USB_LOG(EVENT) << "Failed to reset device: " | 769 USB_LOG(EVENT) << "Failed to reset device: " |
| 771 << ConvertPlatformUsbErrorToString(rv); | 770 << ConvertPlatformUsbErrorToString(rv); |
| 772 } | 771 } |
| 773 task_runner_->PostTask(FROM_HERE, base::Bind(callback, rv == LIBUSB_SUCCESS)); | 772 task_runner_->PostTask(FROM_HERE, base::Bind(callback, rv == LIBUSB_SUCCESS)); |
| 774 } | 773 } |
| 775 | 774 |
| 776 void UsbDeviceHandleImpl::RefreshEndpointMap() { | 775 void UsbDeviceHandleImpl::RefreshEndpointMap() { |
| 777 DCHECK(thread_checker_.CalledOnValidThread()); | 776 DCHECK(thread_checker_.CalledOnValidThread()); |
| 778 endpoint_map_.clear(); | 777 endpoint_map_.clear(); |
| 779 const UsbConfigDescriptor* config = device_->GetConfiguration(); | 778 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); |
| 780 if (config) { | 779 if (config) { |
| 781 for (const auto& map_entry : claimed_interfaces_) { | 780 for (const auto& map_entry : claimed_interfaces_) { |
| 782 int interface_number = map_entry.first; | 781 int interface_number = map_entry.first; |
| 783 const scoped_refptr<InterfaceClaimer>& claimed_iface = map_entry.second; | 782 const scoped_refptr<InterfaceClaimer>& claimed_iface = map_entry.second; |
| 784 | 783 |
| 785 for (const UsbInterfaceDescriptor& iface : config->interfaces) { | 784 for (const UsbInterfaceDescriptor& iface : config->interfaces) { |
| 786 if (iface.interface_number == interface_number && | 785 if (iface.interface_number == interface_number && |
| 787 iface.alternate_setting == claimed_iface->alternate_setting()) { | 786 iface.alternate_setting == claimed_iface->alternate_setting()) { |
| 788 for (const UsbEndpointDescriptor& endpoint : iface.endpoints) { | 787 for (const UsbEndpointDescriptor& endpoint : iface.endpoints) { |
| 789 endpoint_map_[endpoint.address] = interface_number; | 788 endpoint_map_[endpoint.address] = interface_number; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 // Attempt-release all the interfaces. | 977 // Attempt-release all the interfaces. |
| 979 // It will be retained until the transfer cancellation is finished. | 978 // It will be retained until the transfer cancellation is finished. |
| 980 claimed_interfaces_.clear(); | 979 claimed_interfaces_.clear(); |
| 981 | 980 |
| 982 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to | 981 // Cannot close device handle here. Need to wait for libusb_cancel_transfer to |
| 983 // finish. | 982 // finish. |
| 984 device_ = NULL; | 983 device_ = NULL; |
| 985 } | 984 } |
| 986 | 985 |
| 987 } // namespace device | 986 } // namespace device |
| OLD | NEW |