OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/hid/hid_service_win.h" | 5 #include "device/hid/hid_service_win.h" |
6 | 6 |
7 #define INITGUID | 7 #define INITGUID |
8 | 8 |
9 #include <dbt.h> | 9 #include <dbt.h> |
10 #include <setupapi.h> | 10 #include <setupapi.h> |
11 #include <stddef.h> | 11 #include <stddef.h> |
12 #include <winioctl.h> | 12 #include <winioctl.h> |
13 | 13 |
| 14 #include <utility> |
| 15 |
14 #include "base/bind.h" | 16 #include "base/bind.h" |
15 #include "base/files/file.h" | 17 #include "base/files/file.h" |
16 #include "base/location.h" | 18 #include "base/location.h" |
17 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
19 #include "base/strings/sys_string_conversions.h" | 21 #include "base/strings/sys_string_conversions.h" |
20 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
21 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
22 #include "components/device_event_log/device_event_log.h" | 24 #include "components/device_event_log/device_event_log.h" |
23 #include "device/hid/hid_connection_win.h" | 25 #include "device/hid/hid_connection_win.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 63 |
62 base::win::ScopedHandle file(OpenDevice(device_info->device_id())); | 64 base::win::ScopedHandle file(OpenDevice(device_info->device_id())); |
63 if (!file.IsValid()) { | 65 if (!file.IsValid()) { |
64 HID_PLOG(EVENT) << "Failed to open device"; | 66 HID_PLOG(EVENT) << "Failed to open device"; |
65 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 67 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
66 return; | 68 return; |
67 } | 69 } |
68 | 70 |
69 task_runner_->PostTask( | 71 task_runner_->PostTask( |
70 FROM_HERE, | 72 FROM_HERE, |
71 base::Bind(callback, new HidConnectionWin(device_info, file.Pass()))); | 73 base::Bind(callback, new HidConnectionWin(device_info, std::move(file)))); |
72 } | 74 } |
73 | 75 |
74 // static | 76 // static |
75 void HidServiceWin::EnumerateOnFileThread( | 77 void HidServiceWin::EnumerateOnFileThread( |
76 base::WeakPtr<HidServiceWin> service, | 78 base::WeakPtr<HidServiceWin> service, |
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
78 HDEVINFO device_info_set = | 80 HDEVINFO device_info_set = |
79 SetupDiGetClassDevs(&GUID_DEVINTERFACE_HID, NULL, NULL, | 81 SetupDiGetClassDevs(&GUID_DEVINTERFACE_HID, NULL, NULL, |
80 DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); | 82 DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); |
81 | 83 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 base::win::ScopedHandle HidServiceWin::OpenDevice( | 290 base::win::ScopedHandle HidServiceWin::OpenDevice( |
289 const std::string& device_path) { | 291 const std::string& device_path) { |
290 base::win::ScopedHandle file( | 292 base::win::ScopedHandle file( |
291 CreateFileA(device_path.c_str(), GENERIC_WRITE | GENERIC_READ, | 293 CreateFileA(device_path.c_str(), GENERIC_WRITE | GENERIC_READ, |
292 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, | 294 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, |
293 FILE_FLAG_OVERLAPPED, NULL)); | 295 FILE_FLAG_OVERLAPPED, NULL)); |
294 if (!file.IsValid() && GetLastError() == ERROR_ACCESS_DENIED) { | 296 if (!file.IsValid() && GetLastError() == ERROR_ACCESS_DENIED) { |
295 file.Set(CreateFileA(device_path.c_str(), GENERIC_READ, FILE_SHARE_READ, | 297 file.Set(CreateFileA(device_path.c_str(), GENERIC_READ, FILE_SHARE_READ, |
296 NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)); | 298 NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)); |
297 } | 299 } |
298 return file.Pass(); | 300 return file; |
299 } | 301 } |
300 | 302 |
301 } // namespace device | 303 } // namespace device |
OLD | NEW |