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
;
18 struct libusb_device_handle
;
21 class SequencedTaskRunner
;
26 class UsbDeviceHandleImpl
;
29 typedef struct libusb_device
* PlatformUsbDevice
;
30 typedef struct libusb_config_descriptor
* PlatformUsbConfigDescriptor
;
31 typedef struct libusb_device_handle
* PlatformUsbDeviceHandle
;
33 class UsbDeviceImpl
: public UsbDevice
{
35 // UsbDevice implementation:
36 #if defined(OS_CHROMEOS)
37 // Only overridden on Chrome OS.
38 void CheckUsbAccess(const ResultCallback
& callback
) override
;
39 void RequestUsbAccess(int interface_id
,
40 const ResultCallback
& callback
) override
;
42 void Open(const OpenCallback
& callback
) override
;
43 bool Close(scoped_refptr
<UsbDeviceHandle
> handle
) override
;
44 const UsbConfigDescriptor
* GetConfiguration() override
;
47 friend class UsbServiceImpl
;
48 friend class UsbDeviceHandleImpl
;
50 // Called by UsbServiceImpl only;
51 UsbDeviceImpl(scoped_refptr
<UsbContext
> context
,
52 PlatformUsbDevice platform_device
,
56 const base::string16
& manufacturer_string
,
57 const base::string16
& product_string
,
58 const base::string16
& serial_number
,
59 const std::string
& device_node
,
60 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner
);
62 ~UsbDeviceImpl() override
;
64 // Called only by UsbServiceImpl.
65 PlatformUsbDevice
platform_device() const { return platform_device_
; }
66 void set_visited(bool visited
) { visited_
= visited
; }
67 bool was_visited() const { return visited_
; }
70 // Called by UsbDeviceHandleImpl.
71 void RefreshConfiguration();
74 void OpenOnBlockingThread(const OpenCallback
& callback
);
75 void Opened(PlatformUsbDeviceHandle platform_handle
,
76 const OpenCallback
& callback
);
78 base::ThreadChecker thread_checker_
;
79 PlatformUsbDevice platform_device_
;
80 bool visited_
= false;
82 #if defined(OS_CHROMEOS)
83 // On Chrome OS save the devnode string for requesting path access from
88 // The current device configuration descriptor. May be null if the device is
89 // in an unconfigured state.
90 scoped_ptr
<UsbConfigDescriptor
> configuration_
;
92 // Retain the context so that it will not be released before UsbDevice.
93 scoped_refptr
<UsbContext
> context_
;
96 typedef std::vector
<scoped_refptr
<UsbDeviceHandleImpl
> > HandlesVector
;
97 HandlesVector handles_
;
99 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
100 scoped_refptr
<base::SequencedTaskRunner
> blocking_task_runner_
;
102 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl
);
105 } // namespace device
107 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_