Index: base/win/scoped_device_info_object.h |
diff --git a/base/win/scoped_device_info_object.h b/base/win/scoped_device_info_object.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..95d6f9c1c430360a73008ebf3d7adb7e6923e140 |
--- /dev/null |
+++ b/base/win/scoped_device_info_object.h |
@@ -0,0 +1,47 @@ |
+// 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 BASE_WIN_SCOPED_DEVICE_INFO_OBJECT_H_ |
+#define BASE_WIN_SCOPED_DEVICE_INFO_OBJECT_H_ |
+ |
+#include <windows.h> |
+#include <setupapi.h> |
+ |
+namespace base { |
+namespace win { |
+ |
+// 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); |
Lei Zhang
2015/11/13 01:38:25
DCHECK_EQ / DCHECK_NE
|
+ 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_; |
+}; |
Lei Zhang
2015/11/13 01:38:25
DISALLOW_COPY_AND_ASSIGN?
|
+ |
+} // namespace win |
+} // namespace base |
+ |
+#endif // BASE_WIN_SCOPED_DEVICE_INFO_OBJECT_H_ |