Cleanup favicon after componentization completion
[chromium-blink-merge.git] / device / usb / usb_device_impl.h
blob897b4910fe045d33e37bdf4c3df97057ebc9d7a1
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 // Only overridden on Chrome OS.
36 void CheckUsbAccess(const ResultCallback& callback) override;
37 void RequestUsbAccess(int interface_id,
38 const ResultCallback& callback) override;
39 #endif // OS_CHROMEOS
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;
47 protected:
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,
55 uint16 vendor_id,
56 uint16 product_id,
57 uint32 unique_id);
59 ~UsbDeviceImpl() override;
61 // Called only by UsbServiceImpl.
62 void OnDisconnect();
64 // Called by UsbDeviceHandleImpl.
65 void RefreshConfiguration();
67 private:
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.
81 void CacheStrings();
82 bool strings_cached_;
83 #endif
84 #if defined(OS_CHROMEOS)
85 // On Chrome OS save the devnode string for requesting path access from
86 // permission broker.
87 std::string devnode_;
88 #endif
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_;
97 // Opened handles.
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_