| 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 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ |
| 6 #define DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ | 6 #define DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "device/usb/usb_device_handle.h" | 15 #include "device/usb/usb_device_handle.h" |
| 16 #include "device/usb/usb_interface.h" | |
| 17 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 18 #include "third_party/libusb/src/libusb/libusb.h" | 17 #include "third_party/libusb/src/libusb/libusb.h" |
| 19 | 18 |
| 20 namespace base { | 19 namespace base { |
| 21 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace device { | 23 namespace device { |
| 25 | 24 |
| 26 class UsbContext; | 25 class UsbContext; |
| 27 class UsbConfigDescriptor; | 26 struct UsbConfigDescriptor; |
| 28 class UsbDeviceImpl; | 27 class UsbDeviceImpl; |
| 29 | 28 |
| 30 typedef libusb_device_handle* PlatformUsbDeviceHandle; | 29 typedef libusb_device_handle* PlatformUsbDeviceHandle; |
| 31 typedef libusb_iso_packet_descriptor* PlatformUsbIsoPacketDescriptor; | 30 typedef libusb_iso_packet_descriptor* PlatformUsbIsoPacketDescriptor; |
| 32 typedef libusb_transfer* PlatformUsbTransferHandle; | 31 typedef libusb_transfer* PlatformUsbTransferHandle; |
| 33 | 32 |
| 34 // UsbDeviceHandle class provides basic I/O related functionalities. | 33 // UsbDeviceHandle class provides basic I/O related functionalities. |
| 35 class UsbDeviceHandleImpl : public UsbDeviceHandle { | 34 class UsbDeviceHandleImpl : public UsbDeviceHandle { |
| 36 public: | 35 public: |
| 37 virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE; | 36 virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 81 |
| 83 PlatformUsbDeviceHandle handle() const { return handle_; } | 82 PlatformUsbDeviceHandle handle() const { return handle_; } |
| 84 | 83 |
| 85 protected: | 84 protected: |
| 86 friend class UsbDeviceImpl; | 85 friend class UsbDeviceImpl; |
| 87 | 86 |
| 88 // This constructor is called by UsbDevice. | 87 // This constructor is called by UsbDevice. |
| 89 UsbDeviceHandleImpl(scoped_refptr<UsbContext> context, | 88 UsbDeviceHandleImpl(scoped_refptr<UsbContext> context, |
| 90 UsbDeviceImpl* device, | 89 UsbDeviceImpl* device, |
| 91 PlatformUsbDeviceHandle handle, | 90 PlatformUsbDeviceHandle handle, |
| 92 scoped_refptr<UsbConfigDescriptor> interfaces); | 91 const UsbConfigDescriptor& config); |
| 93 | 92 |
| 94 virtual ~UsbDeviceHandleImpl(); | 93 virtual ~UsbDeviceHandleImpl(); |
| 95 | 94 |
| 96 private: | 95 private: |
| 97 class InterfaceClaimer; | 96 class InterfaceClaimer; |
| 98 struct Transfer; | 97 struct Transfer; |
| 99 | 98 |
| 100 // Refresh endpoint_map_ after ClaimInterface, ReleaseInterface and | 99 // Refresh endpoint_map_ after ClaimInterface, ReleaseInterface and |
| 101 // SetInterfaceAlternateSetting. | 100 // SetInterfaceAlternateSetting. |
| 102 void RefreshEndpointMap(); | 101 void RefreshEndpointMap(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 bool GetSupportedLanguages(); | 135 bool GetSupportedLanguages(); |
| 137 bool GetStringDescriptor(uint8 string_id, base::string16* string); | 136 bool GetStringDescriptor(uint8 string_id, base::string16* string); |
| 138 | 137 |
| 139 // Informs the object to drop internal references. | 138 // Informs the object to drop internal references. |
| 140 void InternalClose(); | 139 void InternalClose(); |
| 141 | 140 |
| 142 UsbDeviceImpl* device_; | 141 UsbDeviceImpl* device_; |
| 143 | 142 |
| 144 PlatformUsbDeviceHandle handle_; | 143 PlatformUsbDeviceHandle handle_; |
| 145 | 144 |
| 146 scoped_refptr<UsbConfigDescriptor> interfaces_; | 145 const UsbConfigDescriptor& config_; |
| 147 | 146 |
| 148 std::vector<uint16> languages_; | 147 std::vector<uint16> languages_; |
| 149 std::map<uint8, base::string16> strings_; | 148 std::map<uint8, base::string16> strings_; |
| 150 | 149 |
| 151 typedef std::map<int, scoped_refptr<InterfaceClaimer> > ClaimedInterfaceMap; | 150 typedef std::map<int, scoped_refptr<InterfaceClaimer> > ClaimedInterfaceMap; |
| 152 ClaimedInterfaceMap claimed_interfaces_; | 151 ClaimedInterfaceMap claimed_interfaces_; |
| 153 | 152 |
| 154 typedef std::map<PlatformUsbTransferHandle, Transfer> TransferMap; | 153 typedef std::map<PlatformUsbTransferHandle, Transfer> TransferMap; |
| 155 TransferMap transfers_; | 154 TransferMap transfers_; |
| 156 | 155 |
| 157 // A map from endpoints to interfaces | 156 // A map from endpoints to interfaces |
| 158 typedef std::map<int, int> EndpointMap; | 157 typedef std::map<int, int> EndpointMap; |
| 159 EndpointMap endpoint_map_; | 158 EndpointMap endpoint_map_; |
| 160 | 159 |
| 161 // Retain the UsbContext so that the platform context will not be destroyed | 160 // Retain the UsbContext so that the platform context will not be destroyed |
| 162 // before this handle. | 161 // before this handle. |
| 163 scoped_refptr<UsbContext> context_; | 162 scoped_refptr<UsbContext> context_; |
| 164 | 163 |
| 165 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 164 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 166 | 165 |
| 167 base::ThreadChecker thread_checker_; | 166 base::ThreadChecker thread_checker_; |
| 168 | 167 |
| 169 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleImpl); | 168 DISALLOW_COPY_AND_ASSIGN(UsbDeviceHandleImpl); |
| 170 }; | 169 }; |
| 171 | 170 |
| 172 } // namespace device | 171 } // namespace device |
| 173 | 172 |
| 174 #endif // DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ | 173 #endif // DEVICE_USB_USB_DEVICE_HANDLE_IMPL_H_ |
| OLD | NEW |