| 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 <winioctl.h> | 11 #include <winioctl.h> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "components/device_event_log/device_event_log.h" |
| 21 #include "device/hid/hid_connection_win.h" | 22 #include "device/hid/hid_connection_win.h" |
| 22 #include "device/hid/hid_device_info.h" | 23 #include "device/hid/hid_device_info.h" |
| 23 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
| 24 | 25 |
| 25 // Setup API is required to enumerate HID devices. | 26 // Setup API is required to enumerate HID devices. |
| 26 #pragma comment(lib, "setupapi.lib") | 27 #pragma comment(lib, "setupapi.lib") |
| 27 #pragma comment(lib, "hid.lib") | 28 #pragma comment(lib, "hid.lib") |
| 28 | 29 |
| 29 namespace device { | 30 namespace device { |
| 30 | 31 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 const auto& map_entry = devices().find(device_id); | 59 const auto& map_entry = devices().find(device_id); |
| 59 if (map_entry == devices().end()) { | 60 if (map_entry == devices().end()) { |
| 60 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 61 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
| 61 return; | 62 return; |
| 62 } | 63 } |
| 63 scoped_refptr<HidDeviceInfo> device_info = map_entry->second; | 64 scoped_refptr<HidDeviceInfo> device_info = map_entry->second; |
| 64 | 65 |
| 65 base::win::ScopedHandle file(OpenDevice(device_info->device_id())); | 66 base::win::ScopedHandle file(OpenDevice(device_info->device_id())); |
| 66 if (!file.IsValid()) { | 67 if (!file.IsValid()) { |
| 67 PLOG(ERROR) << "Failed to open device"; | 68 HID_PLOG(EVENT) << "Failed to open device"; |
| 68 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 69 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
| 69 return; | 70 return; |
| 70 } | 71 } |
| 71 | 72 |
| 72 task_runner_->PostTask( | 73 task_runner_->PostTask( |
| 73 FROM_HERE, | 74 FROM_HERE, |
| 74 base::Bind(callback, new HidConnectionWin(device_info, file.Pass()))); | 75 base::Bind(callback, new HidConnectionWin(device_info, file.Pass()))); |
| 75 } | 76 } |
| 76 | 77 |
| 77 HidServiceWin::~HidServiceWin() { | 78 HidServiceWin::~HidServiceWin() { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 180 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 180 const std::string& device_path) { | 181 const std::string& device_path) { |
| 181 base::win::ScopedHandle device_handle(OpenDevice(device_path)); | 182 base::win::ScopedHandle device_handle(OpenDevice(device_path)); |
| 182 if (!device_handle.IsValid()) { | 183 if (!device_handle.IsValid()) { |
| 183 return; | 184 return; |
| 184 } | 185 } |
| 185 | 186 |
| 186 HIDD_ATTRIBUTES attrib = {0}; | 187 HIDD_ATTRIBUTES attrib = {0}; |
| 187 attrib.Size = sizeof(HIDD_ATTRIBUTES); | 188 attrib.Size = sizeof(HIDD_ATTRIBUTES); |
| 188 if (!HidD_GetAttributes(device_handle.Get(), &attrib)) { | 189 if (!HidD_GetAttributes(device_handle.Get(), &attrib)) { |
| 189 VLOG(1) << "Failed to get device attributes."; | 190 HID_LOG(EVENT) << "Failed to get device attributes."; |
| 190 return; | 191 return; |
| 191 } | 192 } |
| 192 | 193 |
| 193 PHIDP_PREPARSED_DATA preparsed_data = nullptr; | 194 PHIDP_PREPARSED_DATA preparsed_data = nullptr; |
| 194 if (!HidD_GetPreparsedData(device_handle.Get(), &preparsed_data) || | 195 if (!HidD_GetPreparsedData(device_handle.Get(), &preparsed_data) || |
| 195 !preparsed_data) { | 196 !preparsed_data) { |
| 196 VLOG(1) << "Failed to get device data."; | 197 HID_LOG(EVENT) << "Failed to get device data."; |
| 197 return; | 198 return; |
| 198 } | 199 } |
| 199 | 200 |
| 200 HIDP_CAPS capabilities = {0}; | 201 HIDP_CAPS capabilities = {0}; |
| 201 if (HidP_GetCaps(preparsed_data, &capabilities) != HIDP_STATUS_SUCCESS) { | 202 if (HidP_GetCaps(preparsed_data, &capabilities) != HIDP_STATUS_SUCCESS) { |
| 202 VLOG(1) << "Failed to get device capabilities."; | 203 HID_LOG(EVENT) << "Failed to get device capabilities."; |
| 203 HidD_FreePreparsedData(preparsed_data); | 204 HidD_FreePreparsedData(preparsed_data); |
| 204 return; | 205 return; |
| 205 } | 206 } |
| 206 | 207 |
| 207 // Whether or not the device includes report IDs in its reports the size | 208 // Whether or not the device includes report IDs in its reports the size |
| 208 // of the report ID is included in the value provided by Windows. This | 209 // of the report ID is included in the value provided by Windows. This |
| 209 // appears contrary to the MSDN documentation. | 210 // appears contrary to the MSDN documentation. |
| 210 size_t max_input_report_size = 0; | 211 size_t max_input_report_size = 0; |
| 211 size_t max_output_report_size = 0; | 212 size_t max_output_report_size = 0; |
| 212 size_t max_feature_report_size = 0; | 213 size_t max_feature_report_size = 0; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 FILE_FLAG_OVERLAPPED, NULL)); | 298 FILE_FLAG_OVERLAPPED, NULL)); |
| 298 if (!file.IsValid() && | 299 if (!file.IsValid() && |
| 299 GetLastError() == base::File::FILE_ERROR_ACCESS_DENIED) { | 300 GetLastError() == base::File::FILE_ERROR_ACCESS_DENIED) { |
| 300 file.Set(CreateFileA(device_path.c_str(), GENERIC_READ, FILE_SHARE_READ, | 301 file.Set(CreateFileA(device_path.c_str(), GENERIC_READ, FILE_SHARE_READ, |
| 301 NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)); | 302 NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)); |
| 302 } | 303 } |
| 303 return file.Pass(); | 304 return file.Pass(); |
| 304 } | 305 } |
| 305 | 306 |
| 306 } // namespace device | 307 } // namespace device |
| OLD | NEW |