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

Unified Diff: device/usb/usb_service_impl.cc

Issue 1439443002: Reland: Add code to deal with serial device disconnection detection on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address grt@'s comments Created 5 years, 1 month 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
Index: device/usb/usb_service_impl.cc
diff --git a/device/usb/usb_service_impl.cc b/device/usb/usb_service_impl.cc
index dd5cc9054d1adbd5977b0049efec672239a004c7..e141a8461ad58d8c34dbc6a0ca8f8c6877d90e09 100644
--- a/device/usb/usb_service_impl.cc
+++ b/device/usb/usb_service_impl.cc
@@ -27,6 +27,7 @@
#include <usbiodef.h>
#include "base/strings/string_util.h"
+#include "device/core/device_info_query_win.h"
#endif // OS_WIN
#if defined(USE_UDEV)
@@ -53,82 +54,29 @@ const int kControlTransferTimeout = 60000; // 1 minute
#if defined(OS_WIN)
-// Wrapper around a HDEVINFO that automatically destroys it.
-class ScopedDeviceInfoList {
- public:
- explicit ScopedDeviceInfoList(HDEVINFO handle) : handle_(handle) {}
-
- ~ScopedDeviceInfoList() {
- if (valid()) {
- SetupDiDestroyDeviceInfoList(handle_);
- }
- }
-
- bool valid() { return handle_ != INVALID_HANDLE_VALUE; }
-
- HDEVINFO get() { return handle_; }
-
- private:
- HDEVINFO handle_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedDeviceInfoList);
-};
-
-// Wrapper around an SP_DEVINFO_DATA that initializes it properly and
-// automatically deletes it.
-class ScopedDeviceInfo {
- public:
- ScopedDeviceInfo() {
- memset(&dev_info_data_, 0, sizeof(dev_info_data_));
- dev_info_data_.cbSize = sizeof(dev_info_data_);
- }
-
- ~ScopedDeviceInfo() {
- if (dev_info_set_ != INVALID_HANDLE_VALUE) {
- SetupDiDeleteDeviceInfo(dev_info_set_, &dev_info_data_);
- }
- }
-
- // Once the SP_DEVINFO_DATA has been populated it must be freed using the
- // HDEVINFO it was created from.
- void set_valid(HDEVINFO dev_info_set) {
- DCHECK(dev_info_set_ == INVALID_HANDLE_VALUE);
- DCHECK(dev_info_set != INVALID_HANDLE_VALUE);
- dev_info_set_ = dev_info_set;
- }
-
- PSP_DEVINFO_DATA get() { return &dev_info_data_; }
-
- private:
- HDEVINFO dev_info_set_ = INVALID_HANDLE_VALUE;
- SP_DEVINFO_DATA dev_info_data_;
-};
-
bool IsWinUsbInterface(const std::string& device_path) {
- ScopedDeviceInfoList dev_info_list(SetupDiCreateDeviceInfoList(NULL, NULL));
- if (!dev_info_list.valid()) {
+ device::DeviceInfoQueryWin device_info_query;
+ if (!device_info_query.device_info_list_valid()) {
USB_PLOG(ERROR) << "Failed to create a device information set";
return false;
}
- // This will add the device to |dev_info_list| so we can query driver info.
- if (!SetupDiOpenDeviceInterfaceA(dev_info_list.get(), device_path.c_str(), 0,
- NULL)) {
+ // This will add the device so we can query driver info.
+ if (!device_info_query.AddDevice(device_path.c_str())) {
USB_PLOG(ERROR) << "Failed to get device interface data for "
<< device_path;
return false;
}
- ScopedDeviceInfo dev_info;
- if (!SetupDiEnumDeviceInfo(dev_info_list.get(), 0, dev_info.get())) {
+ if (!device_info_query.GetDeviceInfo()) {
USB_PLOG(ERROR) << "Failed to get device info for " << device_path;
return false;
}
- dev_info.set_valid(dev_info_list.get());
DWORD reg_data_type;
BYTE buffer[256];
- if (!SetupDiGetDeviceRegistryPropertyA(dev_info_list.get(), dev_info.get(),
+ if (!SetupDiGetDeviceRegistryPropertyA(device_info_query.device_info_list(),
+ device_info_query.device_info_data(),
SPDRP_SERVICE, &reg_data_type,
&buffer[0], sizeof buffer, NULL)) {
USB_PLOG(ERROR) << "Failed to get device service property";
« device/serial/serial_io_handler_win.cc ('K') | « device/serial/serial_io_handler_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698