Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: device/usb/usb_service_win.h

Issue 2885143002: Use the task scheduler in the new Windows USB backend (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 7 #include <list>
8 #include <unordered_map> 8 #include <unordered_map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/scoped_observer.h" 12 #include "base/scoped_observer.h"
13 #include "device/base/device_monitor_win.h" 13 #include "device/base/device_monitor_win.h"
14 #include "device/usb/usb_device_win.h" 14 #include "device/usb/usb_device_win.h"
15 15
16 namespace base {
17 class SequencedTaskRunner;
18 }
19
20 namespace device { 16 namespace device {
21 17
22 class UsbServiceWin : public DeviceMonitorWin::Observer, public UsbService { 18 class UsbServiceWin : public DeviceMonitorWin::Observer, public UsbService {
23 public: 19 public:
24 explicit UsbServiceWin( 20 UsbServiceWin();
25 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
26 ~UsbServiceWin() override; 21 ~UsbServiceWin() override;
27 22
28 private: 23 private:
29 class BlockingThreadHelper; 24 class BlockingTaskHelper;
30 25
31 // device::UsbService implementation 26 // device::UsbService implementation
27 void Shutdown() override;
32 void GetDevices(const GetDevicesCallback& callback) override; 28 void GetDevices(const GetDevicesCallback& callback) override;
33 29
34 // device::DeviceMonitorWin::Observer implementation 30 // device::DeviceMonitorWin::Observer implementation
35 void OnDeviceAdded(const GUID& class_guid, 31 void OnDeviceAdded(const GUID& class_guid,
36 const std::string& device_path) override; 32 const std::string& device_path) override;
37 void OnDeviceRemoved(const GUID& class_guid, 33 void OnDeviceRemoved(const GUID& class_guid,
38 const std::string& device_path) override; 34 const std::string& device_path) override;
39 35
40 // Methods called by BlockingThreadHelper 36 // Methods called by BlockingThreadHelper
41 void HelperStarted(); 37 void HelperStarted();
42 void CreateDeviceObject(const std::string& device_path, 38 void CreateDeviceObject(const std::string& device_path,
43 const std::string& hub_path, 39 const std::string& hub_path,
44 int port_number, 40 int port_number,
45 const std::string& driver_name); 41 const std::string& driver_name);
46 42
47 void DeviceReady(scoped_refptr<UsbDeviceWin> device, bool success); 43 void DeviceReady(scoped_refptr<UsbDeviceWin> device, bool success);
48 44
49 bool enumeration_ready() { 45 bool enumeration_ready() {
50 return helper_started_ && first_enumeration_countdown_ == 0; 46 return helper_started_ && first_enumeration_countdown_ == 0;
51 } 47 }
52 48
53 // Enumeration callbacks are queued until an enumeration completes. 49 // Enumeration callbacks are queued until an enumeration completes.
54 bool helper_started_ = false; 50 bool helper_started_ = false;
55 uint32_t first_enumeration_countdown_ = 0; 51 uint32_t first_enumeration_countdown_ = 0;
56 std::list<GetDevicesCallback> enumeration_callbacks_; 52 std::list<GetDevicesCallback> enumeration_callbacks_;
57 53
58 BlockingThreadHelper* helper_; 54 std::unique_ptr<BlockingTaskHelper> helper_;
59 std::unordered_map<std::string, scoped_refptr<UsbDeviceWin>> devices_by_path_; 55 std::unordered_map<std::string, scoped_refptr<UsbDeviceWin>> devices_by_path_;
60 56
61 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; 57 ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_;
62 58
63 base::WeakPtrFactory<UsbServiceWin> weak_factory_; 59 base::WeakPtrFactory<UsbServiceWin> weak_factory_;
64 60
65 DISALLOW_COPY_AND_ASSIGN(UsbServiceWin); 61 DISALLOW_COPY_AND_ASSIGN(UsbServiceWin);
66 }; 62 };
67 63
68 } // namespace device 64 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698