diff options
author | reillyg <reillyg@chromium.org> | 2015-02-18 16:53:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-19 00:53:50 +0000 |
commit | 8c5a2c5f3c9efbc0c5810e8269d788210175a6af (patch) | |
tree | 3e88dcba018766a322446bf32c68be8cebf51d4f /device/hid/hid_service_win.h | |
parent | 34855a14235a5a533d8d98d1ba53175f54703b98 (diff) | |
download | chromium_src-8c5a2c5f3c9efbc0c5810e8269d788210175a6af.zip chromium_src-8c5a2c5f3c9efbc0c5810e8269d788210175a6af.tar.gz chromium_src-8c5a2c5f3c9efbc0c5810e8269d788210175a6af.tar.bz2 |
Enumerate HID devices asynchronously on Windows.
Avoid possibly long blocking times in the Windows SetupDi function
calls made to enumerate devices by offloading to the FILE thread.
Now that we can be sure that a stray request to the device won't
block the UI additional calls to get the device's product and serial
number strings can be made.
BUG=457899
Review URL: https://codereview.chromium.org/936603003
Cr-Commit-Position: refs/heads/master@{#316939}
Diffstat (limited to 'device/hid/hid_service_win.h')
-rw-r--r-- | device/hid/hid_service_win.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/device/hid/hid_service_win.h b/device/hid/hid_service_win.h index 902d431..1704ac7 100644 --- a/device/hid/hid_service_win.h +++ b/device/hid/hid_service_win.h @@ -14,6 +14,7 @@ extern "C" { } #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/scoped_observer.h" #include "base/win/scoped_handle.h" #include "device/core/device_monitor_win.h" @@ -30,7 +31,7 @@ namespace device { class HidServiceWin : public HidService, public DeviceMonitorWin::Observer { public: - HidServiceWin(); + HidServiceWin(scoped_refptr<base::SingleThreadTaskRunner> file_task_runner); virtual void Connect(const HidDeviceId& device_id, const ConnectCallback& callback) override; @@ -38,7 +39,9 @@ class HidServiceWin : public HidService, public DeviceMonitorWin::Observer { private: virtual ~HidServiceWin(); - void DoInitialEnumeration(); + static void EnumerateOnFileThread( + base::WeakPtr<HidServiceWin> service, + scoped_refptr<base::SingleThreadTaskRunner> task_runner); static void CollectInfoFromButtonCaps(PHIDP_PREPARSED_DATA preparsed_data, HIDP_REPORT_TYPE report_type, USHORT button_caps_length, @@ -47,16 +50,22 @@ class HidServiceWin : public HidService, public DeviceMonitorWin::Observer { HIDP_REPORT_TYPE report_type, USHORT value_caps_length, HidCollectionInfo* collection_info); + static void AddDeviceOnFileThread( + base::WeakPtr<HidServiceWin> service, + scoped_refptr<base::SingleThreadTaskRunner> task_runner, + const std::string& device_path); // DeviceMonitorWin::Observer implementation: void OnDeviceAdded(const std::string& device_path) override; void OnDeviceRemoved(const std::string& device_path) override; // Tries to open the device read-write and falls back to read-only. - base::win::ScopedHandle OpenDevice(const std::string& device_path); + static base::win::ScopedHandle OpenDevice(const std::string& device_path); scoped_refptr<base::SingleThreadTaskRunner> task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; ScopedObserver<DeviceMonitorWin, DeviceMonitorWin::Observer> device_observer_; + base::WeakPtrFactory<HidServiceWin> weak_factory_; DISALLOW_COPY_AND_ASSIGN(HidServiceWin); }; |