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

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

Issue 2690383002: Add device path enumeration to the new Windows USB backend. (Closed)
Patch Set: Addressed scheib@'s feedback. Created 3 years, 10 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>
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698