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