OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 #ifndef COMPONENTS_USB_SERVICE_USB_DEVICE_H_ |
6 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ | 6 #define COMPONENTS_USB_SERVICE_USB_DEVICE_H_ |
7 #define CHROME_BROWSER_USB_USB_DEVICE_H_ | |
8 | 7 |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/callback.h" | 11 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
15 #include "chrome/browser/usb/usb_interface.h" | 14 #include "components/usb_service/usb_interface.h" |
| 15 #include "components/usb_service/usb_service_export.h" |
16 | 16 |
17 struct libusb_device; | 17 struct libusb_device; |
| 18 |
| 19 namespace usb_service { |
| 20 |
18 class UsbDeviceHandle; | 21 class UsbDeviceHandle; |
19 class UsbContext; | 22 class UsbContext; |
20 | 23 |
21 typedef libusb_device* PlatformUsbDevice; | 24 typedef libusb_device* PlatformUsbDevice; |
22 | 25 |
23 // A UsbDevice object represents a detected USB device, providing basic | 26 // A UsbDevice object represents a detected USB device, providing basic |
24 // information about it. For further manipulation of the device, a | 27 // information about it. For further manipulation of the device, a |
25 // UsbDeviceHandle must be created from Open() method. | 28 // UsbDeviceHandle must be created from Open() method. |
26 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { | 29 class USB_SERVICE_EXPORT UsbDevice |
| 30 : public base::RefCountedThreadSafe<UsbDevice> { |
27 public: | 31 public: |
28 // Accessors to basic information. | 32 // Accessors to basic information. |
29 PlatformUsbDevice platform_device() const { return platform_device_; } | 33 PlatformUsbDevice platform_device() const { return platform_device_; } |
30 uint16 vendor_id() const { return vendor_id_; } | 34 uint16 vendor_id() const { return vendor_id_; } |
31 uint16 product_id() const { return product_id_; } | 35 uint16 product_id() const { return product_id_; } |
32 uint32 unique_id() const { return unique_id_; } | 36 uint32 unique_id() const { return unique_id_; } |
33 | 37 |
34 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
35 // On ChromeOS, if an interface of a claimed device is not claimed, the | 39 // On ChromeOS, if an interface of a claimed device is not claimed, the |
36 // permission broker can change the owner of the device so that the unclaimed | 40 // permission broker can change the owner of the device so that the unclaimed |
37 // interfaces can be used. If this argument is missing, permission broker will | 41 // interfaces can be used. If this argument is missing, permission broker will |
38 // not be used and this method fails if the device is claimed. | 42 // not be used and this method fails if the device is claimed. |
39 virtual void RequestUsbAcess( | 43 virtual void RequestUsbAcess( |
40 int interface_id, const base::Callback<void(bool success)>& callback); | 44 int interface_id, |
| 45 const base::Callback<void(bool success)>& callback); |
41 #endif // OS_CHROMEOS | 46 #endif // OS_CHROMEOS |
42 | 47 |
43 // Creates a UsbDeviceHandle for further manipulation. | 48 // Creates a UsbDeviceHandle for further manipulation. |
44 // Blocking method. Must be called on FILE thread. | 49 // Blocking method. Must be called on FILE thread. |
45 virtual scoped_refptr<UsbDeviceHandle> Open(); | 50 virtual scoped_refptr<UsbDeviceHandle> Open(); |
46 | 51 |
47 // Explicitly closes a device handle. This method will be automatically called | 52 // Explicitly closes a device handle. This method will be automatically called |
48 // by the destructor of a UsbDeviceHandle as well. | 53 // by the destructor of a UsbDeviceHandle as well. |
49 // Closing a closed handle is a safe | 54 // Closing a closed handle is a safe |
50 // Blocking method. Must be called on FILE thread. | 55 // Blocking method. Must be called on FILE thread. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 89 |
85 // Opened handles. | 90 // Opened handles. |
86 typedef std::vector<scoped_refptr<UsbDeviceHandle> > HandlesVector; | 91 typedef std::vector<scoped_refptr<UsbDeviceHandle> > HandlesVector; |
87 HandlesVector handles_; | 92 HandlesVector handles_; |
88 | 93 |
89 base::ThreadChecker thread_checker_; | 94 base::ThreadChecker thread_checker_; |
90 | 95 |
91 DISALLOW_COPY_AND_ASSIGN(UsbDevice); | 96 DISALLOW_COPY_AND_ASSIGN(UsbDevice); |
92 }; | 97 }; |
93 | 98 |
94 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ | 99 } // namespace usb_service |
| 100 |
| 101 #endif // COMPONENTS_USB_SERVICE_USB_DEVICE_H_ |
OLD | NEW |