| 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 |
| 6 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ | 6 #ifndef CHROME_BROWSER_USB_USB_DEVICE_H_ |
| 7 #define CHROME_BROWSER_USB_USB_DEVICE_H_ | 7 #define CHROME_BROWSER_USB_USB_DEVICE_H_ |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // A UsbDevice object represents a detected USB device, providing basic | 22 // A UsbDevice object represents a detected USB device, providing basic |
| 23 // information about it. For further manipulation of the device, a | 23 // information about it. For further manipulation of the device, a |
| 24 // UsbDeviceHandle must be created from Open() method. | 24 // UsbDeviceHandle must be created from Open() method. |
| 25 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { | 25 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> { |
| 26 public: | 26 public: |
| 27 // Accessors to basic information. | 27 // Accessors to basic information. |
| 28 PlatformUsbDevice platform_device() const { return platform_device_; } | 28 PlatformUsbDevice platform_device() const { return platform_device_; } |
| 29 uint16 vendor_id() const { return vendor_id_; } | 29 uint16 vendor_id() const { return vendor_id_; } |
| 30 uint16 product_id() const { return product_id_; } | 30 uint16 product_id() const { return product_id_; } |
| 31 uint32 unique_id() const { return unique_id_; } |
| 31 | 32 |
| 32 // Creates a UsbDeviceHandle for further manipulation. | 33 // Creates a UsbDeviceHandle for further manipulation. |
| 33 // Blocking method. Must be called on FILE thread. | 34 // Blocking method. Must be called on FILE thread. |
| 34 virtual scoped_refptr<UsbDeviceHandle> Open(); | 35 virtual scoped_refptr<UsbDeviceHandle> Open(); |
| 35 | 36 |
| 36 // Explicitly closes a device handle. This method will be automatically called | 37 // Explicitly closes a device handle. This method will be automatically called |
| 37 // by the destructor of a UsbDeviceHandle as well. | 38 // by the destructor of a UsbDeviceHandle as well. |
| 38 // Closing a closed handle is a safe | 39 // Closing a closed handle is a safe |
| 39 // Blocking method. Must be called on FILE thread. | 40 // Blocking method. Must be called on FILE thread. |
| 40 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle); | 41 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle); |
| 41 | 42 |
| 42 // Lists the interfaces provided by the device and fills the given | 43 // Lists the interfaces provided by the device and fills the given |
| 43 // UsbConfigDescriptor. | 44 // UsbConfigDescriptor. |
| 44 // Blocking method. Must be called on FILE thread. | 45 // Blocking method. Must be called on FILE thread. |
| 45 virtual scoped_refptr<UsbConfigDescriptor> ListInterfaces(); | 46 virtual scoped_refptr<UsbConfigDescriptor> ListInterfaces(); |
| 46 | 47 |
| 47 protected: | 48 protected: |
| 48 friend class UsbService; | 49 friend class UsbService; |
| 49 friend class base::RefCountedThreadSafe<UsbDevice>; | 50 friend class base::RefCountedThreadSafe<UsbDevice>; |
| 50 | 51 |
| 51 // Called by UsbService only; | 52 // Called by UsbService only; |
| 52 UsbDevice(scoped_refptr<UsbContext> context, | 53 UsbDevice(scoped_refptr<UsbContext> context, |
| 53 PlatformUsbDevice platform_device, | 54 PlatformUsbDevice platform_device, |
| 54 uint16 vendor_id, | 55 uint16 vendor_id, |
| 55 uint16 product_id); | 56 uint16 product_id, |
| 57 uint32 unique_id); |
| 56 | 58 |
| 57 // Constructor called in test only. | 59 // Constructor called in test only. |
| 58 UsbDevice(); | 60 UsbDevice(); |
| 59 virtual ~UsbDevice(); | 61 virtual ~UsbDevice(); |
| 60 | 62 |
| 61 // Called only be UsbService. | 63 // Called only be UsbService. |
| 62 virtual void OnDisconnect(); | 64 virtual void OnDisconnect(); |
| 63 | 65 |
| 64 private: | 66 private: |
| 65 PlatformUsbDevice platform_device_; | 67 PlatformUsbDevice platform_device_; |
| 66 uint16 vendor_id_; | 68 uint16 vendor_id_; |
| 67 uint16 product_id_; | 69 uint16 product_id_; |
| 70 uint32 unique_id_; |
| 68 | 71 |
| 69 // Retain the context so that it will not be released before UsbDevice. | 72 // Retain the context so that it will not be released before UsbDevice. |
| 70 scoped_refptr<UsbContext> context_; | 73 scoped_refptr<UsbContext> context_; |
| 71 | 74 |
| 72 // Opened handles. | 75 // Opened handles. |
| 73 typedef std::vector<scoped_refptr<UsbDeviceHandle> > HandlesVector; | 76 typedef std::vector<scoped_refptr<UsbDeviceHandle> > HandlesVector; |
| 74 HandlesVector handles_; | 77 HandlesVector handles_; |
| 75 | 78 |
| 76 base::ThreadChecker thread_checker_; | 79 base::ThreadChecker thread_checker_; |
| 77 | 80 |
| 78 DISALLOW_COPY_AND_ASSIGN(UsbDevice); | 81 DISALLOW_COPY_AND_ASSIGN(UsbDevice); |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ | 84 #endif // CHROME_BROWSER_USB_USB_DEVICE_H_ |
| OLD | NEW |