OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_H_ | |
6 #define COMPONENTS_USB_SERVICE_USB_DEVICE_H_ | |
7 | |
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" | |
12 | |
13 namespace usb_service { | |
14 | |
15 class UsbDeviceHandle; | |
16 class UsbConfigDescriptor; | |
17 | |
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> { | |
23 public: | |
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_; } | |
28 | |
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( | |
35 int interface_id, | |
36 const base::Callback<void(bool success)>& callback) = 0; | |
37 #endif // OS_CHROMEOS | |
38 | |
39 // Creates a UsbDeviceHandle for further manipulation. | |
40 // Blocking method. Must be called on FILE thread. | |
41 virtual scoped_refptr<UsbDeviceHandle> Open() = 0; | |
42 | |
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; | |
48 | |
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; | |
53 | |
54 protected: | |
55 UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id) | |
56 : vendor_id_(vendor_id), product_id_(product_id), unique_id_(unique_id) {} | |
57 | |
58 virtual ~UsbDevice() {} | |
59 | |
60 private: | |
61 friend class base::RefCountedThreadSafe<UsbDevice>; | |
62 | |
63 const uint16 vendor_id_; | |
64 const uint16 product_id_; | |
65 const uint32 unique_id_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(UsbDevice); | |
68 }; | |
69 | |
70 } // namespace usb_service | |
71 | |
72 #endif // COMPONENTS_USB_SERVICE_USB_DEVICE_H_ | |
OLD | NEW |