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
3 // found in the LICENSE file.
5 #ifndef DEVICE_USB_USB_DEVICE_IMPL_H_
6 #define DEVICE_USB_USB_DEVICE_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/threading/thread_checker.h"
13 #include "device/usb/usb_descriptors.h"
14 #include "device/usb/usb_device.h"
17 struct libusb_config_descriptor
;
20 class SingleThreadTaskRunner
;
25 class UsbDeviceHandleImpl
;
28 typedef libusb_device
* PlatformUsbDevice
;
29 typedef libusb_config_descriptor
* PlatformUsbConfigDescriptor
;
31 class UsbDeviceImpl
: public UsbDevice
{
33 // UsbDevice implementation:
34 #if defined(OS_CHROMEOS)
35 // Only overridden on Chrome OS.
36 void CheckUsbAccess(const ResultCallback
& callback
) override
;
37 void RequestUsbAccess(int interface_id
,
38 const ResultCallback
& callback
) override
;
40 scoped_refptr
<UsbDeviceHandle
> Open() override
;
41 bool Close(scoped_refptr
<UsbDeviceHandle
> handle
) override
;
42 const UsbConfigDescriptor
* GetConfiguration() override
;
43 bool GetManufacturer(base::string16
* manufacturer
) override
;
44 bool GetProduct(base::string16
* product
) override
;
45 bool GetSerialNumber(base::string16
* serial_number
) override
;
48 friend class UsbServiceImpl
;
49 friend class UsbDeviceHandleImpl
;
51 // Called by UsbServiceImpl only;
52 UsbDeviceImpl(scoped_refptr
<UsbContext
> context
,
53 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
,
54 PlatformUsbDevice platform_device
,
59 ~UsbDeviceImpl() override
;
61 // Called only by UsbServiceImpl.
64 // Called by UsbDeviceHandleImpl.
65 void RefreshConfiguration();
68 base::ThreadChecker thread_checker_
;
69 PlatformUsbDevice platform_device_
;
71 // On Linux these properties are read from sysfs when the device is enumerated
72 // to avoid hitting the permission broker on Chrome OS for a real string
73 // descriptor request.
74 base::string16 manufacturer_
;
75 base::string16 product_
;
76 base::string16 serial_number_
;
77 #if !defined(USE_UDEV)
78 // On other platforms the device must be opened in order to cache them. This
79 // should be delayed until the strings are needed to avoid poor interactions
80 // with other applications.
84 #if defined(OS_CHROMEOS)
85 // On Chrome OS save the devnode string for requesting path access from
90 // The current device configuration descriptor. May be null if the device is
91 // in an unconfigured state.
92 scoped_ptr
<UsbConfigDescriptor
> configuration_
;
94 // Retain the context so that it will not be released before UsbDevice.
95 scoped_refptr
<UsbContext
> context_
;
98 typedef std::vector
<scoped_refptr
<UsbDeviceHandleImpl
> > HandlesVector
;
99 HandlesVector handles_
;
101 // Reference to the UI thread for permission-broker calls.
102 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner_
;
104 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl
);
107 } // namespace device
109 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_