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..cd8cd20cf1fbfc74e6c226f11fb51d5f5201bebc 100644 |
--- a/device/usb/usb_service_impl.cc |
+++ b/device/usb/usb_service_impl.cc |
@@ -27,6 +27,8 @@ |
#include <usbiodef.h> |
#include "base/strings/string_util.h" |
+#include "device/core/scoped_device_info_list.h" |
+#include "device/core/scoped_device_info_object.h" |
#endif // OS_WIN |
#if defined(USE_UDEV) |
@@ -53,82 +55,32 @@ 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()) { |
+ base::win::ScopedDeviceInfoList dev_info_list( |
+ SetupDiCreateDeviceInfoList(NULL, NULL)); |
+ if (!dev_info_list.IsValid()) { |
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, |
+ if (!SetupDiOpenDeviceInterfaceA(dev_info_list.Get(), device_path.c_str(), 0, |
NULL)) { |
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())) { |
+ base::win::ScopedDeviceInfo dev_info; |
+ if (!SetupDiEnumDeviceInfo(dev_info_list.Get(), 0, dev_info.get())) { |
USB_PLOG(ERROR) << "Failed to get device info for " << device_path; |
return false; |
} |
- dev_info.set_valid(dev_info_list.get()); |
+ 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(dev_info_list.Get(), dev_info.get(), |
SPDRP_SERVICE, ®_data_type, |
&buffer[0], sizeof buffer, NULL)) { |
USB_PLOG(ERROR) << "Failed to get device service property"; |