Add a custom Robolectric testrunner.
[chromium-blink-merge.git] / device / usb / usb_device_impl.h
blob702b20e6f06e926e463c6e242de771ba4f5bd36f
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_
8 #include <vector>
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"
16 struct libusb_device;
17 struct libusb_config_descriptor;
19 namespace base {
20 class SingleThreadTaskRunner;
23 namespace device {
25 class UsbDeviceHandleImpl;
26 class UsbContext;
28 typedef libusb_device* PlatformUsbDevice;
29 typedef libusb_config_descriptor* PlatformUsbConfigDescriptor;
31 class UsbDeviceImpl : public UsbDevice {
32 public:
33 // UsbDevice implementation:
34 #if defined(OS_CHROMEOS)
35 void RequestUsbAccess(
36 int interface_id,
37 const base::Callback<void(bool success)>& callback) override;
38 #endif // OS_CHROMEOS
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;
46 protected:
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,
54 uint16 vendor_id,
55 uint16 product_id,
56 uint32 unique_id);
58 ~UsbDeviceImpl() override;
60 // Called only by UsbServiceImpl.
61 void OnDisconnect();
63 // Called by UsbDeviceHandleImpl.
64 void RefreshConfiguration();
66 private:
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.
80 void CacheStrings();
81 bool strings_cached_;
82 #endif
83 #if defined(OS_CHROMEOS)
84 // On Chrome OS save the devnode string for requesting path access from
85 // permission broker.
86 std::string devnode_;
87 #endif
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_;
96 // Opened handles.
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_