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

Unified Diff: device/hid/hid_service_win.cc

Issue 399313008: Remove HID devices not found during enumeration on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a protected const accessor instead of making devices_ protected. Created 6 years, 5 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.cc ('k') | no next file » | 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 9f27cfff26996c6954af097e81c3168300757fbf..c3de09ab8f99b85323a477d670cfeda133d9588f 100644
--- a/device/hid/hid_service_win.cc
+++ b/device/hid/hid_service_win.cc
@@ -66,78 +66,96 @@ void HidServiceWin::Enumerate() {
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
- if (device_info_set == INVALID_HANDLE_VALUE)
- return;
+ std::set<std::string> connected_devices;
- for (int device_index = 0;
- 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.
- SetupDiGetDeviceInterfaceDetailA(device_info_set,
- &device_interface_data,
+ if (device_info_set != INVALID_HANDLE_VALUE) {
+ for (int device_index = 0;
+ SetupDiEnumDeviceInterfaces(device_info_set,
NULL,
- 0,
- &required_size,
- NULL);
-
- scoped_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA_A, base::FreeDeleter>
- device_interface_detail_data(
- static_cast<SP_DEVICE_INTERFACE_DETAIL_DATA_A*>(
- malloc(required_size)));
- device_interface_detail_data->cbSize =
- sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
-
- // Get the detailed data for this device.
- res = SetupDiGetDeviceInterfaceDetailA(device_info_set,
- &device_interface_data,
- device_interface_detail_data.get(),
- required_size,
- NULL,
- NULL);
- if (!res)
- continue;
-
- // Enumerate device info. Looking for Setup Class "HIDClass".
- for (DWORD i = 0;
- SetupDiEnumDeviceInfo(device_info_set, i, &devinfo_data);
- i++) {
- char class_name[256] = {0};
- res = SetupDiGetDeviceRegistryPropertyA(device_info_set,
- &devinfo_data,
- SPDRP_CLASS,
- NULL,
- (PBYTE) class_name,
- sizeof(class_name) - 1,
- NULL);
+ &GUID_DEVINTERFACE_HID,
+ device_index,
+ &device_interface_data);
+ ++device_index) {
+ DWORD required_size = 0;
+
+ // Determime the required size of detail struct.
+ SetupDiGetDeviceInterfaceDetailA(device_info_set,
+ &device_interface_data,
+ NULL,
+ 0,
+ &required_size,
+ NULL);
+
+ scoped_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA_A, base::FreeDeleter>
+ device_interface_detail_data(
+ static_cast<SP_DEVICE_INTERFACE_DETAIL_DATA_A*>(
+ malloc(required_size)));
+ device_interface_detail_data->cbSize =
+ sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
+
+ // Get the detailed data for this device.
+ res = SetupDiGetDeviceInterfaceDetailA(device_info_set,
+ &device_interface_data,
+ device_interface_detail_data.get(),
+ required_size,
+ NULL,
+ NULL);
if (!res)
- break;
- if (memcmp(class_name, kHIDClass, sizeof(kHIDClass)) == 0) {
- char driver_name[256] = {0};
- // Get bounded driver.
+ continue;
+
+ // Enumerate device info. Looking for Setup Class "HIDClass".
+ for (DWORD i = 0;
+ SetupDiEnumDeviceInfo(device_info_set, i, &devinfo_data);
+ i++) {
+ char class_name[256] = {0};
res = SetupDiGetDeviceRegistryPropertyA(device_info_set,
&devinfo_data,
- SPDRP_DRIVER,
+ SPDRP_CLASS,
NULL,
- (PBYTE) driver_name,
- sizeof(driver_name) - 1,
+ (PBYTE) class_name,
+ sizeof(class_name) - 1,
NULL);
- if (res) {
- // Found the driver.
+ if (!res)
break;
+ if (memcmp(class_name, kHIDClass, sizeof(kHIDClass)) == 0) {
+ char driver_name[256] = {0};
+ // Get bounded driver.
+ res = SetupDiGetDeviceRegistryPropertyA(device_info_set,
+ &devinfo_data,
+ SPDRP_DRIVER,
+ NULL,
+ (PBYTE) driver_name,
+ sizeof(driver_name) - 1,
+ NULL);
+ if (res) {
+ // Found the driver.
+ break;
+ }
}
}
+
+ if (!res)
+ continue;
+
+ PlatformAddDevice(device_interface_detail_data->DevicePath);
+ connected_devices.insert(device_interface_detail_data->DevicePath);
}
+ }
- if (!res)
- continue;
+ // Find disconnected devices.
+ const DeviceMap& devices = GetDevicesNoEnumerate();
+ std::vector<std::string> disconnected_devices;
+ for (DeviceMap::const_iterator it = devices.begin();
+ it != devices.end();
+ ++it) {
+ if (!ContainsKey(connected_devices, it->first)) {
+ disconnected_devices.push_back(it->first);
+ }
+ }
- PlatformAddDevice(device_interface_detail_data->DevicePath);
+ // Remove disconnected devices.
+ for (size_t i = 0; i < disconnected_devices.size(); ++i) {
+ PlatformRemoveDevice(disconnected_devices[i]);
}
}
« no previous file with comments | « device/hid/hid_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698