| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_WIN_H_ | 5 #ifndef DEVICE_USB_USB_DEVICE_WIN_H_ |
| 6 #define DEVICE_USB_USB_DEVICE_WIN_H_ | 6 #define DEVICE_USB_USB_DEVICE_WIN_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 12 #include "device/usb/usb_device.h" | 12 #include "device/usb/usb_device.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 class SequencedTaskRunner; | 15 class SequencedTaskRunner; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace device { | 18 namespace device { |
| 19 | 19 |
| 20 struct UsbDeviceDescriptor; |
| 21 |
| 20 class UsbDeviceWin : public UsbDevice { | 22 class UsbDeviceWin : public UsbDevice { |
| 21 public: | 23 public: |
| 22 // UsbDevice implementation: | 24 // UsbDevice implementation: |
| 23 void Open(const OpenCallback& callback) override; | 25 void Open(const OpenCallback& callback) override; |
| 24 | 26 |
| 25 protected: | 27 protected: |
| 26 friend class UsbServiceWin; | 28 friend class UsbServiceWin; |
| 27 friend class UsbDeviceHandleWin; | 29 friend class UsbDeviceHandleWin; |
| 28 | 30 |
| 29 // Called by UsbServiceWin only; | 31 // Called by UsbServiceWin only; |
| 30 UsbDeviceWin(const std::string& device_path, | 32 UsbDeviceWin(const std::string& device_path, |
| 31 const std::string& hub_path, | 33 const std::string& hub_path, |
| 32 int port_number, | 34 int port_number, |
| 33 scoped_refptr<base::SequencedTaskRunner> task_runner); | 35 scoped_refptr<base::SequencedTaskRunner> task_runner); |
| 34 | 36 |
| 35 ~UsbDeviceWin() override; | 37 ~UsbDeviceWin() override; |
| 36 | 38 |
| 37 const std::string& device_path() const { return device_path_; } | 39 const std::string& device_path() const { return device_path_; } |
| 38 int port_number() const { return port_number_; } | 40 int port_number() const { return port_number_; } |
| 39 | 41 |
| 42 // Opens the device's parent hub in order to read the device, configuration |
| 43 // and string descriptors. |
| 44 void ReadDescriptors(const base::Callback<void(bool)>& callback); |
| 45 |
| 46 private: |
| 47 void OpenOnBlockingThread(const OpenCallback& callback); |
| 48 void OnReadDescriptors(const base::Callback<void(bool)>& callback, |
| 49 scoped_refptr<UsbDeviceHandle> device_handle, |
| 50 std::unique_ptr<UsbDeviceDescriptor> descriptor); |
| 51 void OnReadStringDescriptors( |
| 52 const base::Callback<void(bool)>& callback, |
| 53 scoped_refptr<UsbDeviceHandle> device_handle, |
| 54 std::unique_ptr<std::map<uint8_t, base::string16>> string_map); |
| 55 |
| 40 private: | 56 private: |
| 41 base::ThreadChecker thread_checker_; | 57 base::ThreadChecker thread_checker_; |
| 42 | 58 |
| 43 const std::string device_path_; | 59 const std::string device_path_; |
| 44 const std::string hub_path_; | 60 const std::string hub_path_; |
| 45 const int port_number_; | 61 const int port_number_; |
| 46 | 62 |
| 47 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 63 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 48 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 64 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 49 | 65 |
| 50 DISALLOW_COPY_AND_ASSIGN(UsbDeviceWin); | 66 DISALLOW_COPY_AND_ASSIGN(UsbDeviceWin); |
| 51 }; | 67 }; |
| 52 | 68 |
| 53 } // namespace device | 69 } // namespace device |
| 54 | 70 |
| 55 #endif // DEVICE_USB_USB_DEVICE_WIN_H_ | 71 #endif // DEVICE_USB_USB_DEVICE_WIN_H_ |
| OLD | NEW |