OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef DEVICE_USB_USB_DEVICE_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_H_ |
6 #define DEVICE_USB_USB_DEVICE_H_ | 6 #define DEVICE_USB_USB_DEVICE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "device/usb/usb_descriptors.h" | 14 #include "device/usb/usb_descriptors.h" |
| 15 #include "url/gurl.h" |
15 | 16 |
16 namespace device { | 17 namespace device { |
17 | 18 |
18 class UsbDeviceHandle; | 19 class UsbDeviceHandle; |
| 20 struct WebUsbDescriptorSet; |
19 | 21 |
20 // A UsbDevice object represents a detected USB device, providing basic | 22 // A UsbDevice object represents a detected USB device, providing basic |
21 // information about it. Methods other than simple property accessors must be | 23 // information about it. Methods other than simple property accessors must be |
22 // called from the thread on which this object was created. For further | 24 // called from the thread on which this object was created. For further |
23 // manipulation of the device, a UsbDeviceHandle must be created from Open() | 25 // manipulation of the device, a UsbDeviceHandle must be created from Open() |
24 // method. | 26 // method. |
25 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { | 27 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { |
26 public: | 28 public: |
27 using OpenCallback = base::Callback<void(scoped_refptr<UsbDeviceHandle>)>; | 29 using OpenCallback = base::Callback<void(scoped_refptr<UsbDeviceHandle>)>; |
28 using ResultCallback = base::Callback<void(bool success)>; | 30 using ResultCallback = base::Callback<void(bool success)>; |
29 | 31 |
30 // A unique identifier which remains stable for the lifetime of this device | 32 // A unique identifier which remains stable for the lifetime of this device |
31 // object (i.e., until the device is unplugged or the USB service dies.) | 33 // object (i.e., until the device is unplugged or the USB service dies.) |
32 const std::string& guid() const { return guid_; } | 34 const std::string& guid() const { return guid_; } |
33 | 35 |
34 // Accessors to basic information. | 36 // Accessors to basic information. |
35 uint16 vendor_id() const { return vendor_id_; } | 37 uint16 vendor_id() const { return vendor_id_; } |
36 uint16 product_id() const { return product_id_; } | 38 uint16 product_id() const { return product_id_; } |
37 const base::string16& manufacturer_string() const { | 39 const base::string16& manufacturer_string() const { |
38 return manufacturer_string_; | 40 return manufacturer_string_; |
39 } | 41 } |
40 const base::string16& product_string() const { return product_string_; } | 42 const base::string16& product_string() const { return product_string_; } |
41 const base::string16& serial_number() const { return serial_number_; } | 43 const base::string16& serial_number() const { return serial_number_; } |
| 44 const WebUsbDescriptorSet* webusb_allowed_origins() const { |
| 45 return webusb_allowed_origins_.get(); |
| 46 } |
| 47 const GURL& webusb_landing_page() const { return webusb_landing_page_; } |
42 | 48 |
43 // On ChromeOS the permission_broker service is used to change the ownership | 49 // On ChromeOS the permission_broker service is used to change the ownership |
44 // of USB device nodes so that Chrome can open them. On other platforms these | 50 // of USB device nodes so that Chrome can open them. On other platforms these |
45 // functions are no-ops and always return true. | 51 // functions are no-ops and always return true. |
46 virtual void CheckUsbAccess(const ResultCallback& callback); | 52 virtual void CheckUsbAccess(const ResultCallback& callback); |
47 | 53 |
48 // Creates a UsbDeviceHandle for further manipulation. | 54 // Creates a UsbDeviceHandle for further manipulation. |
49 virtual void Open(const OpenCallback& callback) = 0; | 55 virtual void Open(const OpenCallback& callback) = 0; |
50 | 56 |
51 // Explicitly closes a device handle. This method will be automatically called | 57 // Explicitly closes a device handle. This method will be automatically called |
(...skipping 16 matching lines...) Expand all Loading... |
68 const base::string16& product_string, | 74 const base::string16& product_string, |
69 const base::string16& serial_number); | 75 const base::string16& serial_number); |
70 virtual ~UsbDevice(); | 76 virtual ~UsbDevice(); |
71 | 77 |
72 // These members must be mutable by subclasses as necessary during device | 78 // These members must be mutable by subclasses as necessary during device |
73 // enumeration. To preserve the thread safety of this object they must remain | 79 // enumeration. To preserve the thread safety of this object they must remain |
74 // constant afterwards. | 80 // constant afterwards. |
75 base::string16 manufacturer_string_; | 81 base::string16 manufacturer_string_; |
76 base::string16 product_string_; | 82 base::string16 product_string_; |
77 base::string16 serial_number_; | 83 base::string16 serial_number_; |
| 84 scoped_ptr<WebUsbDescriptorSet> webusb_allowed_origins_; |
| 85 GURL webusb_landing_page_; |
78 | 86 |
79 // All of the device's configuration descriptors. | 87 // All of the device's configuration descriptors. |
80 std::vector<UsbConfigDescriptor> configurations_; | 88 std::vector<UsbConfigDescriptor> configurations_; |
81 | 89 |
82 private: | 90 private: |
83 friend class base::RefCountedThreadSafe<UsbDevice>; | 91 friend class base::RefCountedThreadSafe<UsbDevice>; |
84 | 92 |
85 const std::string guid_; | 93 const std::string guid_; |
86 const uint16 vendor_id_; | 94 const uint16 vendor_id_; |
87 const uint16 product_id_; | 95 const uint16 product_id_; |
88 | 96 |
89 DISALLOW_COPY_AND_ASSIGN(UsbDevice); | 97 DISALLOW_COPY_AND_ASSIGN(UsbDevice); |
90 }; | 98 }; |
91 | 99 |
92 } // namespace device | 100 } // namespace device |
93 | 101 |
94 #endif // DEVICE_USB_USB_DEVICE_H_ | 102 #endif // DEVICE_USB_USB_DEVICE_H_ |
OLD | NEW |