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

Unified Diff: device/core/device_info_query_win.h

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
« no previous file with comments | « device/core/core.gyp ('k') | device/serial/serial_io_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/core/device_info_query_win.h
diff --git a/device/core/device_info_query_win.h b/device/core/device_info_query_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..55b9363244d3ddb6a1c3f8789212c0f84fd22240
--- /dev/null
+++ b/device/core/device_info_query_win.h
@@ -0,0 +1,81 @@
+// Copyright 2015 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.
+
+#ifndef DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_
+#define DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_
+
+#include <windows.h>
+#include <setupapi.h>
+
+#include <string.h>
+
+#include <string>
+
+#include "base/macros.h"
+#include "base/strings/string_util.h"
+
+namespace device {
+
+// Wrapper around a HDEVINFO and SP_DEVINFO_DATA that automatically destroys
+// them.
+class DeviceInfoQueryWin {
+ public:
+ DeviceInfoQueryWin()
+ : device_info_list_(SetupDiCreateDeviceInfoList(nullptr, nullptr)) {
+ memset(&device_info_data_, 0, sizeof(device_info_data_));
+ }
+
+ ~DeviceInfoQueryWin() {
+ if (device_info_list_ != INVALID_HANDLE_VALUE) {
grt (UTC plus 2) 2015/11/16 21:41:56 nit: if (device_info_list_valid()) {
juncai 2015/11/16 23:37:51 Done.
+ if (device_info_data_.cbSize != 0)
+ SetupDiDeleteDeviceInfo(device_info_list_, &device_info_data_);
+ SetupDiDestroyDeviceInfoList(device_info_list_);
+ }
+ }
+
+ bool AddDevice(const char* device_path) {
+ return SetupDiOpenDeviceInterfaceA(device_info_list_, device_path, 0,
+ nullptr) != FALSE;
+ }
+
+ bool GetDeviceInfo() {
+ DCHECK_EQ(0U, device_info_data_.cbSize);
+ device_info_data_.cbSize = sizeof(device_info_data_);
+ if (!SetupDiEnumDeviceInfo(device_info_list_, 0, &device_info_data_)) {
+ device_info_data_.cbSize = 0;
+ return false;
+ }
+ return true;
+ }
+
+ bool GetDeviceStringProperty(DWORD property,
+ PDWORD property_reg_data_type,
grt (UTC plus 2) 2015/11/16 21:41:56 the callers of this only care about REG_SZ. why no
juncai 2015/11/16 23:37:51 Done.
+ std::string* property_buffer) {
+ size_t property_buffer_length = 512;
grt (UTC plus 2) 2015/11/16 21:41:56 nit: const
juncai 2015/11/16 23:37:51 Done.
+ return SetupDiGetDeviceRegistryPropertyA(
+ device_info_list_, &device_info_data_, property,
+ property_reg_data_type,
+ reinterpret_cast<PBYTE>(base::WriteInto(
+ property_buffer, property_buffer_length + 1)),
grt (UTC plus 2) 2015/11/16 21:41:56 why add 1?
juncai 2015/11/16 23:37:51 Done.
+ property_buffer_length, nullptr) != FALSE;
grt (UTC plus 2) 2015/11/16 21:41:56 the string in |property_buffer| isn't sized proper
juncai 2015/11/16 23:37:51 Done.
+ }
+
+ bool device_info_list_valid() {
+ return device_info_list_ != INVALID_HANDLE_VALUE;
+ }
+
+ HDEVINFO device_info_list() { return device_info_list_; }
+
+ PSP_DEVINFO_DATA device_info_data() { return &device_info_data_; }
+
+ private:
+ HDEVINFO device_info_list_ = INVALID_HANDLE_VALUE;
+ SP_DEVINFO_DATA device_info_data_;
grt (UTC plus 2) 2015/11/16 21:41:56 nit: document the invariant that device_info_data_
juncai 2015/11/16 23:37:51 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(DeviceInfoQueryWin);
+};
+
+} // namespace device
+
+#endif // DEVICE_CORE_DEVICE_INFO_QUERY_WIN_H_
« no previous file with comments | « device/core/core.gyp ('k') | device/serial/serial_io_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698