Update V8 to version 4.6.55.
[chromium-blink-merge.git] / device / usb / usb_device_impl.h
blobbb6654bb07527fb8fca307153aae610e0532eae0
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"
15 #include "device/usb/webusb_descriptors.h"
17 struct libusb_device;
18 struct libusb_config_descriptor;
19 struct libusb_device_handle;
21 namespace base {
22 class SequencedTaskRunner;
25 namespace dbus {
26 class FileDescriptor;
29 namespace device {
31 class UsbDeviceHandleImpl;
32 class UsbContext;
34 typedef struct libusb_device* PlatformUsbDevice;
35 typedef struct libusb_config_descriptor* PlatformUsbConfigDescriptor;
36 typedef struct libusb_device_handle* PlatformUsbDeviceHandle;
38 class UsbDeviceImpl : public UsbDevice {
39 public:
40 // UsbDevice implementation:
41 #if defined(OS_CHROMEOS)
42 void CheckUsbAccess(const ResultCallback& callback) override;
43 #endif // OS_CHROMEOS
44 void Open(const OpenCallback& callback) override;
45 bool Close(scoped_refptr<UsbDeviceHandle> handle) override;
46 const UsbConfigDescriptor* GetActiveConfiguration() override;
48 // These functions are used during enumeration only. The values must not
49 // change during the object's lifetime.
50 void set_manufacturer_string(const base::string16& value) {
51 manufacturer_string_ = value;
53 void set_product_string(const base::string16& value) {
54 product_string_ = value;
56 void set_serial_number(const base::string16& value) {
57 serial_number_ = value;
59 void set_device_path(const std::string& value) { device_path_ = value; }
60 void set_webusb_allowed_origins(scoped_ptr<WebUsbDescriptorSet> descriptors) {
61 webusb_allowed_origins_ = descriptors.Pass();
63 void set_webusb_landing_page(const GURL& url) { webusb_landing_page_ = url; }
65 PlatformUsbDevice platform_device() const { return platform_device_; }
67 protected:
68 friend class UsbServiceImpl;
69 friend class UsbDeviceHandleImpl;
71 // Called by UsbServiceImpl only;
72 UsbDeviceImpl(scoped_refptr<UsbContext> context,
73 PlatformUsbDevice platform_device,
74 uint16 vendor_id,
75 uint16 product_id,
76 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
78 ~UsbDeviceImpl() override;
80 // Called only by UsbServiceImpl.
81 void set_visited(bool visited) { visited_ = visited; }
82 bool was_visited() const { return visited_; }
83 void OnDisconnect();
84 void ReadAllConfigurations();
86 // Called by UsbDeviceHandleImpl.
87 void RefreshActiveConfiguration();
89 private:
90 void GetAllConfigurations();
91 #if defined(OS_CHROMEOS)
92 void OnOpenRequestComplete(const OpenCallback& callback,
93 dbus::FileDescriptor fd);
94 void OpenOnBlockingThreadWithFd(dbus::FileDescriptor fd,
95 const OpenCallback& callback);
96 #endif
97 void OpenOnBlockingThread(const OpenCallback& callback);
98 void Opened(PlatformUsbDeviceHandle platform_handle,
99 const OpenCallback& callback);
101 base::ThreadChecker thread_checker_;
102 PlatformUsbDevice platform_device_;
103 bool visited_ = false;
105 // On Chrome OS device path is necessary to request access from the permission
106 // broker.
107 std::string device_path_;
109 // The current device configuration descriptor. May be null if the device is
110 // in an unconfigured state; if not null, it is a pointer to one of the
111 // items at UsbDevice::configurations_.
112 const UsbConfigDescriptor* active_configuration_;
114 // Retain the context so that it will not be released before UsbDevice.
115 scoped_refptr<UsbContext> context_;
117 // Opened handles.
118 typedef std::vector<scoped_refptr<UsbDeviceHandleImpl> > HandlesVector;
119 HandlesVector handles_;
121 scoped_refptr<base::SequencedTaskRunner> task_runner_;
122 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
124 DISALLOW_COPY_AND_ASSIGN(UsbDeviceImpl);
127 } // namespace device
129 #endif // DEVICE_USB_USB_DEVICE_IMPL_H_