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 #include "device/usb/usb_service.h" | 5 #include "device/usb/usb_service.h" |
6 | 6 |
| 7 #include <list> |
| 8 #include <unordered_map> |
| 9 |
7 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/scoped_observer.h" |
| 13 #include "device/base/device_monitor_win.h" |
| 14 #include "device/usb/usb_device_win.h" |
| 15 |
| 16 namespace base { |
| 17 class SequencedTaskRunner; |
| 18 } |
8 | 19 |
9 namespace device { | 20 namespace device { |
10 | 21 |
11 class UsbServiceWin : public UsbService { | 22 class UsbServiceWin : public DeviceMonitorWin::Observer, public UsbService { |
12 public: | 23 public: |
13 explicit UsbServiceWin( | 24 explicit UsbServiceWin( |
14 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | 25 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); |
15 ~UsbServiceWin() override; | 26 ~UsbServiceWin() override; |
16 | 27 |
17 private: | 28 private: |
| 29 class BlockingThreadHelper; |
| 30 |
| 31 // device::UsbService implementation |
| 32 void GetDevices(const GetDevicesCallback& callback) override; |
| 33 |
| 34 // device::DeviceMonitorWin::Observer implementation |
| 35 void OnDeviceAdded(const GUID& class_guid, |
| 36 const std::string& device_path) override; |
| 37 void OnDeviceRemoved(const GUID& class_guid, |
| 38 const std::string& device_path) override; |
| 39 |
| 40 // Methods called by BlockingThreadHelper |
| 41 void HelperStarted(); |
| 42 void CreateDeviceObject(const std::string& device_path, |
| 43 const std::string& hub_path, |
| 44 int port_number); |
| 45 |
| 46 void DeviceReady(scoped_refptr<UsbDeviceWin> device, bool success); |
| 47 |
| 48 bool enumeration_ready() { |
| 49 return helper_started_ && first_enumeration_countdown_ == 0; |
| 50 } |
| 51 |
| 52 // Enumeration callbacks are queued until an enumeration completes. |
| 53 bool helper_started_ = false; |
| 54 uint32_t first_enumeration_countdown_ = 0; |
| 55 std::list<GetDevicesCallback> enumeration_callbacks_; |
| 56 |
| 57 BlockingThreadHelper* helper_; |
| 58 std::unordered_map<std::string, scoped_refptr<UsbDeviceWin>> devices_by_path_; |
| 59 |
| 60 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; |
| 61 |
| 62 base::WeakPtrFactory<UsbServiceWin> weak_factory_; |
| 63 |
18 DISALLOW_COPY_AND_ASSIGN(UsbServiceWin); | 64 DISALLOW_COPY_AND_ASSIGN(UsbServiceWin); |
19 }; | 65 }; |
20 | 66 |
21 } // namespace device | 67 } // namespace device |
OLD | NEW |