Roll src/third_party/WebKit d67e6d4:0cefbbd (svn 194847:194848)
[chromium-blink-merge.git] / device / usb / usb_device.h
blob22864678b0eefaae23cec82caeb769c1a6842e2c
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_H_
6 #define DEVICE_USB_USB_DEVICE_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h"
13 namespace device {
15 class UsbDeviceHandle;
16 struct UsbConfigDescriptor;
18 // A UsbDevice object represents a detected USB device, providing basic
19 // information about it. Methods other than simple property accessors must be
20 // called from the thread on which this object was created. For further
21 // manipulation of the device, a UsbDeviceHandle must be created from Open()
22 // method.
23 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
24 public:
25 using OpenCallback = base::Callback<void(scoped_refptr<UsbDeviceHandle>)>;
26 using ResultCallback = base::Callback<void(bool success)>;
28 // Accessors to basic information.
29 uint16 vendor_id() const { return vendor_id_; }
30 uint16 product_id() const { return product_id_; }
31 uint32 unique_id() const { return unique_id_; }
32 const base::string16& manufacturer_string() const {
33 return manufacturer_string_;
35 const base::string16& product_string() const { return product_string_; }
36 const base::string16& serial_number() const { return serial_number_; }
38 // On ChromeOS the permission_broker service is used to change the ownership
39 // of USB device nodes so that Chrome can open them. On other platforms these
40 // functions are no-ops and always return true.
41 virtual void CheckUsbAccess(const ResultCallback& callback);
43 // Like CheckUsbAccess but actually changes the ownership of the device node.
44 virtual void RequestUsbAccess(int interface_id,
45 const ResultCallback& callback);
47 // Creates a UsbDeviceHandle for further manipulation.
48 virtual void Open(const OpenCallback& callback) = 0;
50 // Explicitly closes a device handle. This method will be automatically called
51 // by the destructor of a UsbDeviceHandle as well.
52 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
54 // Gets the UsbConfigDescriptor for the active device configuration or nullptr
55 // if the device is unconfigured.
56 virtual const UsbConfigDescriptor* GetConfiguration() = 0;
58 protected:
59 UsbDevice(uint16 vendor_id,
60 uint16 product_id,
61 uint32 unique_id,
62 const base::string16& manufacturer_string,
63 const base::string16& product_string,
64 const base::string16& serial_number);
65 virtual ~UsbDevice();
67 private:
68 friend class base::RefCountedThreadSafe<UsbDevice>;
70 const uint16 vendor_id_;
71 const uint16 product_id_;
72 const uint32 unique_id_;
73 const base::string16 manufacturer_string_;
74 const base::string16 product_string_;
75 const base::string16 serial_number_;
77 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
80 } // namespace device
82 #endif // DEVICE_USB_USB_DEVICE_H_