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