Fixes for Android GN build input/outputs
[chromium-blink-merge.git] / device / usb / usb_device.h
blob1054a3b667d0e9d3dc9f65285398719509be449e
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 // A unique identifier which remains stable for the lifetime of this device
29 // object (i.e., until the device is unplugged or the USB service dies.)
30 const std::string& guid() const { return guid_; }
32 // Accessors to basic information.
33 uint16 vendor_id() const { return vendor_id_; }
34 uint16 product_id() const { return product_id_; }
35 const base::string16& manufacturer_string() const {
36 return manufacturer_string_;
38 const base::string16& product_string() const { return product_string_; }
39 const base::string16& serial_number() const { return serial_number_; }
41 // On ChromeOS the permission_broker service is used to change the ownership
42 // of USB device nodes so that Chrome can open them. On other platforms these
43 // functions are no-ops and always return true.
44 virtual void CheckUsbAccess(const ResultCallback& callback);
46 // Like CheckUsbAccess but actually changes the ownership of the device node.
47 virtual void RequestUsbAccess(int interface_id,
48 const ResultCallback& callback);
50 // Creates a UsbDeviceHandle for further manipulation.
51 virtual void Open(const OpenCallback& callback) = 0;
53 // Explicitly closes a device handle. This method will be automatically called
54 // by the destructor of a UsbDeviceHandle as well.
55 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
57 // Gets the UsbConfigDescriptor for the active device configuration or nullptr
58 // if the device is unconfigured.
59 virtual const UsbConfigDescriptor* GetConfiguration() = 0;
61 protected:
62 UsbDevice(uint16 vendor_id,
63 uint16 product_id,
64 const base::string16& manufacturer_string,
65 const base::string16& product_string,
66 const base::string16& serial_number);
67 virtual ~UsbDevice();
69 private:
70 friend class base::RefCountedThreadSafe<UsbDevice>;
72 const std::string guid_;
73 const uint16 vendor_id_;
74 const uint16 product_id_;
75 const base::string16 manufacturer_string_;
76 const base::string16 product_string_;
77 const base::string16 serial_number_;
79 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
82 } // namespace device
84 #endif // DEVICE_USB_USB_DEVICE_H_