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 void RequestUsbAccess(
37 const base::Callback
<void(bool success
)>& callback
) override
;
39 scoped_refptr
<UsbDeviceHandle
> Open() override
;
40 bool Close(scoped_refptr
<UsbDeviceHandle
> handle
) override
;
41 const UsbConfigDescriptor
* GetConfiguration() override
;
42 bool GetManufacturer(base::string16
* manufacturer
) override
;
43 bool GetProduct(base::string16
* product
) override
;
44 bool GetSerialNumber(base::string16
* serial_number
) override
;
47 friend class UsbServiceImpl
;
48 friend class UsbDeviceHandleImpl
;
50 // Called by UsbServiceImpl only;
51 UsbDeviceImpl(scoped_refptr
<UsbContext
> context
,
52 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
,
53 PlatformUsbDevice platform_device
,
58 ~UsbDeviceImpl() override
;
60 // Called only by UsbServiceImpl.
63 // Called by UsbDeviceHandleImpl.
64 void RefreshConfiguration();
67 base::ThreadChecker thread_checker_
;
68 PlatformUsbDevice platform_device_
;
70 // On Linux these properties are read from sysfs when the device is enumerated
71 // to avoid hitting the permission broker on Chrome OS for a real string
72 // descriptor request.
73 base::string16 manufacturer_
;
74 base::string16 product_
;
75 base::string16 serial_number_
;
76 #if !defined(USE_UDEV)
77 // On other platforms the device must be opened in order to cache them. This
78 // should be delayed until the strings are needed to avoid poor interactions
79 // with other applications.
83 #if defined(OS_CHROMEOS)
84 // On Chrome OS save the devnode string for requesting path access from
89 // The current device configuration descriptor. May be null if the device is
90 // in an unconfigured state.
91 scoped_ptr
<UsbConfigDescriptor
> configuration_
;
93 // Retain the context so that it will not be released before UsbDevice.
94 scoped_refptr
<UsbContext
> context_
;
97 typedef std::vector
<scoped_refptr
<UsbDeviceHandleImpl
> > HandlesVector
;
98 HandlesVector handles_
;
100 // Reference to the UI thread for permission-broker calls.
101 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner_
;
103 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl
);
106 } // namespace device
108 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_