| 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_IMPL_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_IMPL_H_ |
| 6 #define DEVICE_USB_USB_DEVICE_IMPL_H_ | 6 #define DEVICE_USB_USB_DEVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "device/usb/usb_descriptors.h" |
| 13 #include "device/usb/usb_device.h" | 14 #include "device/usb/usb_device.h" |
| 14 | 15 |
| 15 struct libusb_device; | 16 struct libusb_device; |
| 16 struct libusb_config_descriptor; | 17 struct libusb_config_descriptor; |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace device { | 23 namespace device { |
| 23 | 24 |
| 24 class UsbDeviceHandleImpl; | 25 class UsbDeviceHandleImpl; |
| 25 class UsbContext; | 26 class UsbContext; |
| 26 | 27 |
| 27 typedef libusb_device* PlatformUsbDevice; | 28 typedef libusb_device* PlatformUsbDevice; |
| 28 typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; | 29 typedef libusb_config_descriptor* PlatformUsbConfigDescriptor; |
| 29 | 30 |
| 30 class UsbDeviceImpl : public UsbDevice { | 31 class UsbDeviceImpl : public UsbDevice { |
| 31 public: | 32 public: |
| 32 // UsbDevice implementation: | 33 // UsbDevice implementation: |
| 33 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 34 virtual void RequestUsbAccess( | 35 virtual void RequestUsbAccess( |
| 35 int interface_id, | 36 int interface_id, |
| 36 const base::Callback<void(bool success)>& callback) OVERRIDE; | 37 const base::Callback<void(bool success)>& callback) OVERRIDE; |
| 37 #endif // OS_CHROMEOS | 38 #endif // OS_CHROMEOS |
| 38 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE; | 39 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE; |
| 39 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE; | 40 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE; |
| 40 virtual scoped_refptr<UsbConfigDescriptor> ListInterfaces() OVERRIDE; | 41 virtual const UsbConfigDescriptor& GetConfiguration() OVERRIDE; |
| 41 | 42 |
| 42 protected: | 43 protected: |
| 43 friend class UsbServiceImpl; | 44 friend class UsbServiceImpl; |
| 44 | 45 |
| 45 // Called by UsbServiceImpl only; | 46 // Called by UsbServiceImpl only; |
| 46 UsbDeviceImpl(scoped_refptr<UsbContext> context, | 47 UsbDeviceImpl(scoped_refptr<UsbContext> context, |
| 47 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 48 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 48 PlatformUsbDevice platform_device, | 49 PlatformUsbDevice platform_device, |
| 49 uint16 vendor_id, | 50 uint16 vendor_id, |
| 50 uint16 product_id, | 51 uint16 product_id, |
| 51 uint32 unique_id); | 52 uint32 unique_id); |
| 52 | 53 |
| 53 virtual ~UsbDeviceImpl(); | 54 virtual ~UsbDeviceImpl(); |
| 54 | 55 |
| 55 // Called only be UsbService. | 56 // Called only be UsbService. |
| 56 void OnDisconnect(); | 57 void OnDisconnect(); |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 base::ThreadChecker thread_checker_; | 60 base::ThreadChecker thread_checker_; |
| 60 PlatformUsbDevice platform_device_; | 61 PlatformUsbDevice platform_device_; |
| 61 | 62 |
| 63 // The active configuration descriptor is not read immediately but cached for |
| 64 // later use. |
| 65 bool current_configuration_cached_; |
| 66 UsbConfigDescriptor current_configuration_; |
| 67 |
| 62 // Retain the context so that it will not be released before UsbDevice. | 68 // Retain the context so that it will not be released before UsbDevice. |
| 63 scoped_refptr<UsbContext> context_; | 69 scoped_refptr<UsbContext> context_; |
| 64 | 70 |
| 65 // Opened handles. | 71 // Opened handles. |
| 66 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector; | 72 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector; |
| 67 HandlesVector handles_; | 73 HandlesVector handles_; |
| 68 | 74 |
| 69 // Reference to the UI thread for permission-broker calls. | 75 // Reference to the UI thread for permission-broker calls. |
| 70 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 76 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 71 | 77 |
| 72 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl); | 78 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl); |
| 73 }; | 79 }; |
| 74 | 80 |
| 75 } // namespace device | 81 } // namespace device |
| 76 | 82 |
| 77 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_ | 83 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_ |
| OLD | NEW |