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

Unified Diff: device/hid/hid_service_win.cc

Issue 161823002: Clean up HID backend and API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/hid/hid_service_win.h ('k') | device/hid/hid_utils_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_service_win.cc
diff --git a/device/hid/hid_service_win.cc b/device/hid/hid_service_win.cc
index 973398fe4238fecd2849b384fcf5bcf3a85f5415..27f4499b76a0d28eedbc0af4f1f10b58c7c8ada5 100644
--- a/device/hid/hid_service_win.cc
+++ b/device/hid/hid_service_win.cc
@@ -1,20 +1,15 @@
-// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "device/hid/hid_service_win.h"
#include <cstdlib>
-#include <string>
-#include "base/callback_helpers.h"
-#include "base/lazy_instance.h"
-#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
#include "base/strings/sys_string_conversions.h"
-#include "device/hid/hid_connection.h"
#include "device/hid/hid_connection_win.h"
-#include "device/hid/hid_service.h"
+#include "device/hid/hid_device_info.h"
#include "net/base/io_buffer.h"
#if defined(OS_WIN)
@@ -49,11 +44,12 @@ const char kHIDClass[] = "HIDClass";
} // namespace
HidServiceWin::HidServiceWin() {
- initialized_ = Enumerate();
+ Enumerate();
}
+
HidServiceWin::~HidServiceWin() {}
-bool HidServiceWin::Enumerate() {
+void HidServiceWin::Enumerate() {
BOOL res;
HDEVINFO device_info_set;
SP_DEVINFO_DATA devinfo_data;
@@ -70,15 +66,15 @@ bool HidServiceWin::Enumerate() {
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (device_info_set == INVALID_HANDLE_VALUE)
- return false;
+ return;
for (int device_index = 0;
- SetupDiEnumDeviceInterfaces(device_info_set,
- NULL,
- &GUID_DEVINTERFACE_HID,
- device_index,
- &device_interface_data);
- device_index++) {
+ SetupDiEnumDeviceInterfaces(device_info_set,
+ NULL,
+ &GUID_DEVINTERFACE_HID,
+ device_index,
+ &device_interface_data);
+ ++device_index) {
DWORD required_size = 0;
// Determime the required size of detail struct.
@@ -131,7 +127,7 @@ bool HidServiceWin::Enumerate() {
sizeof(driver_name) - 1,
NULL);
if (res) {
- // Found the drive.
+ // Found the driver.
break;
}
}
@@ -142,11 +138,9 @@ bool HidServiceWin::Enumerate() {
PlatformAddDevice(device_interface_detail_data->DevicePath);
}
-
- return true;
}
-void HidServiceWin::PlatformAddDevice(std::string device_path) {
+void HidServiceWin::PlatformAddDevice(const std::string& device_path) {
HidDeviceInfo device_info;
device_info.device_id = device_path;
@@ -195,6 +189,17 @@ void HidServiceWin::PlatformAddDevice(std::string device_path) {
if (HidP_GetValueCaps(HidP_Input, &value_caps[0], &value_caps_length,
preparsed_data) == HIDP_STATUS_SUCCESS) {
device_info.has_report_id = (value_caps[0].ReportID != 0);
+ // If report IDs are supported, adjust all the expected report sizes
+ // down by one byte. This is because Windows will always provide sizes
+ // which assume the presence of a report ID.
+ if (device_info.has_report_id) {
+ if (device_info.input_report_size > 0)
+ device_info.input_report_size -= 1;
+ if (device_info.output_report_size > 0)
+ device_info.output_report_size -= 1;
+ if (device_info.feature_report_size > 0)
+ device_info.feature_report_size -= 1;
+ }
}
}
HidD_FreePreparsedData(preparsed_data);
@@ -214,11 +219,11 @@ void HidServiceWin::PlatformAddDevice(std::string device_path) {
device_info.product_name = base::SysWideToUTF8(str_property);
}
- HidService::AddDevice(device_info);
+ AddDevice(device_info);
}
-void HidServiceWin::PlatformRemoveDevice(std::string device_path) {
- HidService::RemoveDevice(device_path);
+void HidServiceWin::PlatformRemoveDevice(const std::string& device_path) {
+ RemoveDevice(device_path);
}
void HidServiceWin::GetDevices(std::vector<HidDeviceInfo>* devices) {
@@ -226,10 +231,12 @@ void HidServiceWin::GetDevices(std::vector<HidDeviceInfo>* devices) {
HidService::GetDevices(devices);
}
-scoped_refptr<HidConnection> HidServiceWin::Connect(std::string device_id) {
- if (!ContainsKey(devices_, device_id)) return NULL;
- scoped_refptr<HidConnectionWin> connection(
- new HidConnectionWin(devices_[device_id]));
+scoped_refptr<HidConnection> HidServiceWin::Connect(
+ const HidDeviceId& device_id) {
+ HidDeviceInfo device_info;
+ if (!GetDeviceInfo(device_id, &device_info))
+ return NULL;
+ scoped_refptr<HidConnectionWin> connection(new HidConnectionWin(device_info));
if (!connection->available()) {
LOG_GETLASTERROR(ERROR) << "Failed to open device.";
return NULL;
« no previous file with comments | « device/hid/hid_service_win.h ('k') | device/hid/hid_utils_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698