GN + Android: extract android_standalone_library rule.
[chromium-blink-merge.git] / device / usb / usb_device_impl.h
blob379d4019854de018a6b9c9536e0a23e150631238
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 virtual 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;
49 // Called by UsbServiceImpl only;
50 UsbDeviceImpl(scoped_refptr<UsbContext> context,
51 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
52 PlatformUsbDevice platform_device,
53 uint16 vendor_id,
54 uint16 product_id,
55 uint32 unique_id);
57 ~UsbDeviceImpl() override;
59 // Called only by UsbService.
60 void OnDisconnect();
62 private:
63 base::ThreadChecker thread_checker_;
64 PlatformUsbDevice platform_device_;
66 // On Linux these properties are read from sysfs when the device is enumerated
67 // to avoid hitting the permission broker on Chrome OS for a real string
68 // descriptor request.
69 base::string16 manufacturer_;
70 base::string16 product_;
71 base::string16 serial_number_;
72 #if !defined(USE_UDEV)
73 // On other platforms the device must be opened in order to cache them. This
74 // should be delayed until the strings are needed to avoid poor interactions
75 // with other applications.
76 void CacheStrings();
77 bool strings_cached_;
78 #endif
79 #if defined(OS_CHROMEOS)
80 // On Chrome OS save the devnode string for requesting path access from
81 // permission broker.
82 std::string devnode_;
83 #endif
85 // The active configuration descriptor is not read immediately but cached for
86 // later use.
87 bool current_configuration_cached_;
88 UsbConfigDescriptor current_configuration_;
90 // Retain the context so that it will not be released before UsbDevice.
91 scoped_refptr<UsbContext> context_;
93 // Opened handles.
94 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector;
95 HandlesVector handles_;
97 // Reference to the UI thread for permission-broker calls.
98 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
100 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
103 } // namespace device
105 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_