summaryrefslogtreecommitdiffstats
path: root/device/usb
diff options
context:
space:
mode:
authorjuncai <juncai@chromium.org>2015-11-20 21:54:27 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-21 05:55:25 +0000
commit0c9eb038cae670b299c303a5e18547ec85e6e3b0 (patch)
treef6fcebffd4e64adbb1ad659eeacc0e4897c6a241 /device/usb
parent1084bdca601104f8eb99fa4ff11cc1397d8dd1af (diff)
downloadchromium_src-0c9eb038cae670b299c303a5e18547ec85e6e3b0.zip
chromium_src-0c9eb038cae670b299c303a5e18547ec85e6e3b0.tar.gz
chromium_src-0c9eb038cae670b299c303a5e18547ec85e6e3b0.tar.bz2
Add code to deal with serial device disconnection
detection on Windows. This patch added code to deal with serial device disconnection detection problem on Windows. It gets the COM port information from the device path and compare the COM port information with the port information that serial io handler holds. If they match, cancel read for that port. BUG=361606 Committed: https://crrev.com/195a0f202c1b89540d4a385d881cd483abe757fa Cr-Commit-Position: refs/heads/master@{#360193} Committed: https://crrev.com/8d09d9564ea10012d55ed634c0c2835efbd8d01f Cr-Commit-Position: refs/heads/master@{#360347} Review URL: https://codereview.chromium.org/1439443002 Cr-Commit-Position: refs/heads/master@{#361009}
Diffstat (limited to 'device/usb')
-rw-r--r--device/usb/usb.gyp1
-rw-r--r--device/usb/usb_service_impl.cc80
2 files changed, 10 insertions, 71 deletions
diff --git a/device/usb/usb.gyp b/device/usb/usb.gyp
index c7bf776..453ba1a 100644
--- a/device/usb/usb.gyp
+++ b/device/usb/usb.gyp
@@ -14,6 +14,7 @@
'../../components/components.gyp:device_event_log_component',
'../../net/net.gyp:net',
'../../third_party/libusb/libusb.gyp:libusb',
+ '../core/core.gyp:device_core',
],
'include_dirs': [
'../..',
diff --git a/device/usb/usb_service_impl.cc b/device/usb/usb_service_impl.cc
index dd5cc90..9770007 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,96 +54,33 @@ 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()) {
+ 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(),
- SPDRP_SERVICE, &reg_data_type,
- &buffer[0], sizeof buffer, NULL)) {
+ std::string buffer;
+ if (!device_info_query.GetDeviceStringProperty(SPDRP_SERVICE, &buffer)) {
USB_PLOG(ERROR) << "Failed to get device service property";
return false;
}
- if (reg_data_type != REG_SZ) {
- USB_LOG(ERROR) << "Unexpected data type for driver service: "
- << reg_data_type;
- return false;
- }
USB_LOG(DEBUG) << "Driver for " << device_path << " is " << buffer << ".";
- if (base::StartsWith(reinterpret_cast<const char*>(buffer), "WinUSB",
- base::CompareCase::INSENSITIVE_ASCII))
+ if (base::StartsWith(buffer, "WinUSB", base::CompareCase::INSENSITIVE_ASCII))
return true;
return false;
}