Remove obsolete DEPS override in c/b/history.
[chromium-blink-merge.git] / device / usb / usb_device_impl.h
blob3e9c8d0cc435455626918372c3cd96b9a9e23af4
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;
18 struct libusb_device_handle;
20 namespace base {
21 class SequencedTaskRunner;
24 namespace dbus {
25 class FileDescriptor;
28 namespace device {
30 class UsbDeviceHandleImpl;
31 class UsbContext;
33 typedef struct libusb_device* PlatformUsbDevice;
34 typedef struct libusb_config_descriptor* PlatformUsbConfigDescriptor;
35 typedef struct libusb_device_handle* PlatformUsbDeviceHandle;
37 class UsbDeviceImpl : public UsbDevice {
38 public:
39 // UsbDevice implementation:
40 #if defined(OS_CHROMEOS)
41 void CheckUsbAccess(const ResultCallback& callback) override;
42 #endif // OS_CHROMEOS
43 void Open(const OpenCallback& callback) override;
44 bool Close(scoped_refptr<UsbDeviceHandle> handle) override;
45 const UsbConfigDescriptor* GetConfiguration() override;
47 // These functions are used during enumeration only. The values must not
48 // change during the object's lifetime.
49 void set_manufacturer_string(const base::string16& value) {
50 manufacturer_string_ = value;
52 void set_product_string(const base::string16& value) {
53 product_string_ = value;
55 void set_serial_number(const base::string16& value) {
56 serial_number_ = value;
58 void set_device_path(const std::string& value) { device_path_ = value; }
60 PlatformUsbDevice platform_device() const { return platform_device_; }
62 protected:
63 friend class UsbServiceImpl;
64 friend class UsbDeviceHandleImpl;
66 // Called by UsbServiceImpl only;
67 UsbDeviceImpl(scoped_refptr<UsbContext> context,
68 PlatformUsbDevice platform_device,
69 uint16 vendor_id,
70 uint16 product_id,
71 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
73 ~UsbDeviceImpl() override;
75 // Called only by UsbServiceImpl.
76 void set_visited(bool visited) { visited_ = visited; }
77 bool was_visited() const { return visited_; }
78 void OnDisconnect();
80 // Called by UsbDeviceHandleImpl.
81 void RefreshConfiguration();
83 private:
84 #if defined(OS_CHROMEOS)
85 void OnOpenRequestComplete(const OpenCallback& callback,
86 dbus::FileDescriptor fd);
87 void OpenOnBlockingThreadWithFd(dbus::FileDescriptor fd,
88 const OpenCallback& callback);
89 #endif
90 void OpenOnBlockingThread(const OpenCallback& callback);
91 void Opened(PlatformUsbDeviceHandle platform_handle,
92 const OpenCallback& callback);
94 base::ThreadChecker thread_checker_;
95 PlatformUsbDevice platform_device_;
96 bool visited_ = false;
98 // On Chrome OS device path is necessary to request access from the permission
99 // broker.
100 std::string device_path_;
102 // The current device configuration descriptor. May be null if the device is
103 // in an unconfigured state.
104 scoped_ptr<UsbConfigDescriptor> configuration_;
106 // Retain the context so that it will not be released before UsbDevice.
107 scoped_refptr<UsbContext> context_;
109 // Opened handles.
110 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector;
111 HandlesVector handles_;
113 scoped_refptr<base::SequencedTaskRunner> task_runner_;
114 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
116 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
119 } // namespace device
121 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_