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"
15 class UsbDeviceHandle
;
16 struct UsbConfigDescriptor
;
18 // A UsbDevice object represents a detected USB device, providing basic
19 // information about it. For further manipulation of the device, a
20 // UsbDeviceHandle must be created from Open() method.
21 class UsbDevice
: public base::RefCountedThreadSafe
<UsbDevice
> {
23 // Accessors to basic information.
24 uint16
vendor_id() const { return vendor_id_
; }
25 uint16
product_id() const { return product_id_
; }
26 uint32
unique_id() const { return unique_id_
; }
28 #if defined(OS_CHROMEOS)
29 // On ChromeOS, if an interface of a claimed device is not claimed, the
30 // permission broker can change the owner of the device so that the unclaimed
31 // interfaces can be used. If this argument is missing, permission broker will
32 // not be used and this method fails if the device is claimed.
33 virtual void RequestUsbAccess(
35 const base::Callback
<void(bool success
)>& callback
) = 0;
38 // Creates a UsbDeviceHandle for further manipulation.
39 // Blocking method. Must be called on FILE thread.
40 virtual scoped_refptr
<UsbDeviceHandle
> Open() = 0;
42 // Explicitly closes a device handle. This method will be automatically called
43 // by the destructor of a UsbDeviceHandle as well.
44 // Closing a closed handle is a safe
45 // Blocking method. Must be called on FILE thread.
46 virtual bool Close(scoped_refptr
<UsbDeviceHandle
> handle
) = 0;
48 // Gets the UsbConfigDescriptor for the active device configuration or nullptr
49 // if the device is unconfigured.
50 // Blocking method. Must be called on FILE thread.
51 virtual const UsbConfigDescriptor
* GetConfiguration() = 0;
53 // Gets the manufacturer string of the device, or false and an empty
54 // string. This is a blocking method and must be called on FILE thread.
55 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
56 virtual bool GetManufacturer(base::string16
* manufacturer
) = 0;
58 // Gets the product string of the device, or returns false and an empty
59 // string. This is a blocking method and must be called on FILE thread.
60 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
61 virtual bool GetProduct(base::string16
* product
) = 0;
63 // Gets the serial number string of the device, or returns false and an empty
64 // string. This is a blocking method and must be called on FILE thread.
65 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
66 virtual bool GetSerialNumber(base::string16
* serial
) = 0;
69 UsbDevice(uint16 vendor_id
, uint16 product_id
, uint32 unique_id
)
70 : vendor_id_(vendor_id
), product_id_(product_id
), unique_id_(unique_id
) {}
71 virtual ~UsbDevice() {}
74 friend class base::RefCountedThreadSafe
<UsbDevice
>;
76 const uint16 vendor_id_
;
77 const uint16 product_id_
;
78 const uint32 unique_id_
;
80 DISALLOW_COPY_AND_ASSIGN(UsbDevice
);
85 #endif // DEVICE_USB_USB_DEVICE_H_