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 COMPONENTS_USB_SERVICE_USB_DEVICE_H_
6 #define COMPONENTS_USB_SERVICE_USB_DEVICE_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "components/usb_service/usb_service_export.h"
13 namespace usb_service
{
15 class UsbDeviceHandle
;
16 class 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 USB_SERVICE_EXPORT UsbDevice
22 : public base::RefCountedThreadSafe
<UsbDevice
> {
24 // Accessors to basic information.
25 uint16
vendor_id() const { return vendor_id_
; }
26 uint16
product_id() const { return product_id_
; }
27 uint32
unique_id() const { return unique_id_
; }
29 #if defined(OS_CHROMEOS)
30 // On ChromeOS, if an interface of a claimed device is not claimed, the
31 // permission broker can change the owner of the device so that the unclaimed
32 // interfaces can be used. If this argument is missing, permission broker will
33 // not be used and this method fails if the device is claimed.
34 virtual void RequestUsbAccess(
36 const base::Callback
<void(bool success
)>& callback
) = 0;
39 // Creates a UsbDeviceHandle for further manipulation.
40 // Blocking method. Must be called on FILE thread.
41 virtual scoped_refptr
<UsbDeviceHandle
> Open() = 0;
43 // Explicitly closes a device handle. This method will be automatically called
44 // by the destructor of a UsbDeviceHandle as well.
45 // Closing a closed handle is a safe
46 // Blocking method. Must be called on FILE thread.
47 virtual bool Close(scoped_refptr
<UsbDeviceHandle
> handle
) = 0;
49 // Lists the interfaces provided by the device and fills the given
50 // UsbConfigDescriptor.
51 // Blocking method. Must be called on FILE thread.
52 virtual scoped_refptr
<UsbConfigDescriptor
> ListInterfaces() = 0;
55 UsbDevice(uint16 vendor_id
, uint16 product_id
, uint32 unique_id
)
56 : vendor_id_(vendor_id
), product_id_(product_id
), unique_id_(unique_id
) {}
58 virtual ~UsbDevice() {}
61 friend class base::RefCountedThreadSafe
<UsbDevice
>;
63 const uint16 vendor_id_
;
64 const uint16 product_id_
;
65 const uint32 unique_id_
;
67 DISALLOW_COPY_AND_ASSIGN(UsbDevice
);
70 } // namespace usb_service
72 #endif // COMPONENTS_USB_SERVICE_USB_DEVICE_H_