Chromium Code Reviews| 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> | |
| 9 | |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "device/usb/usb_descriptors.h" | |
| 12 | 15 |
| 13 namespace device { | 16 namespace device { |
| 14 | 17 |
| 15 class UsbDeviceHandle; | 18 class UsbDeviceHandle; |
| 16 struct UsbConfigDescriptor; | |
| 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)>; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 45 | 47 |
| 46 // Creates a UsbDeviceHandle for further manipulation. | 48 // Creates a UsbDeviceHandle for further manipulation. |
| 47 virtual void Open(const OpenCallback& callback) = 0; | 49 virtual void Open(const OpenCallback& callback) = 0; |
| 48 | 50 |
| 49 // Explicitly closes a device handle. This method will be automatically called | 51 // Explicitly closes a device handle. This method will be automatically called |
| 50 // by the destructor of a UsbDeviceHandle as well. | 52 // by the destructor of a UsbDeviceHandle as well. |
| 51 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0; | 53 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0; |
| 52 | 54 |
| 53 // Gets the UsbConfigDescriptor for the active device configuration or nullptr | 55 // Gets the UsbConfigDescriptor for the active device configuration or nullptr |
| 54 // if the device is unconfigured. | 56 // if the device is unconfigured. |
| 55 virtual const UsbConfigDescriptor* GetConfiguration() = 0; | 57 virtual const UsbConfigDescriptor* GetActiveConfiguration() = 0; |
| 58 | |
| 59 // Gets all the UsbConfigDescriptor for the device configuration. | |
|
Reilly Grant (use Gerrit)
2015/08/03 18:04:04
"Gets all of the device's UsbConfigDescriptors."
juncai
2015/08/03 21:56:25
Done.
| |
| 60 const std::vector<UsbConfigDescriptor>& configurations() { | |
| 61 return configurations_; | |
| 62 } | |
| 56 | 63 |
| 57 protected: | 64 protected: |
| 58 UsbDevice(uint16 vendor_id, | 65 UsbDevice(uint16 vendor_id, |
| 59 uint16 product_id, | 66 uint16 product_id, |
| 60 const base::string16& manufacturer_string, | 67 const base::string16& manufacturer_string, |
| 61 const base::string16& product_string, | 68 const base::string16& product_string, |
| 62 const base::string16& serial_number); | 69 const base::string16& serial_number); |
| 63 virtual ~UsbDevice(); | 70 virtual ~UsbDevice(); |
| 64 | 71 |
| 65 // These members must be mutable by subclasses as necessary during device | 72 // These members must be mutable by subclasses as necessary during device |
| 66 // enumeration. To preserve the thread safety of this object they must remain | 73 // enumeration. To preserve the thread safety of this object they must remain |
| 67 // constant afterwards. | 74 // constant afterwards. |
| 68 base::string16 manufacturer_string_; | 75 base::string16 manufacturer_string_; |
| 69 base::string16 product_string_; | 76 base::string16 product_string_; |
| 70 base::string16 serial_number_; | 77 base::string16 serial_number_; |
| 71 | 78 |
| 79 // The device's all configuration descriptors. | |
|
Reilly Grant (use Gerrit)
2015/08/03 18:04:04
"All of the device's configuration descriptors."
juncai
2015/08/03 21:56:25
Done.
| |
| 80 std::vector<UsbConfigDescriptor> configurations_; | |
| 81 | |
| 72 private: | 82 private: |
| 73 friend class base::RefCountedThreadSafe<UsbDevice>; | 83 friend class base::RefCountedThreadSafe<UsbDevice>; |
| 74 | 84 |
| 75 const std::string guid_; | 85 const std::string guid_; |
| 76 const uint16 vendor_id_; | 86 const uint16 vendor_id_; |
| 77 const uint16 product_id_; | 87 const uint16 product_id_; |
| 78 | 88 |
| 79 DISALLOW_COPY_AND_ASSIGN(UsbDevice); | 89 DISALLOW_COPY_AND_ASSIGN(UsbDevice); |
| 80 }; | 90 }; |
| 81 | 91 |
| 82 } // namespace device | 92 } // namespace device |
| 83 | 93 |
| 84 #endif // DEVICE_USB_USB_DEVICE_H_ | 94 #endif // DEVICE_USB_USB_DEVICE_H_ |
| OLD | NEW |