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

Side by Side Diff: device/core/scoped_device_info_object.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: moved scoped device files to device core directory 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_CORE_SCOPED_DEVICE_INFO_OBJECT_H_
6 #define DEVICE_CORE_SCOPED_DEVICE_INFO_OBJECT_H_
7
8 #include <windows.h>
9 #include <setupapi.h>
10
11 namespace base {
grt (UTC plus 2) 2015/11/13 19:40:05 this shouldn't be in base::win any longer.
juncai 2015/11/14 01:51:24 Done.
12 namespace win {
13
14 // Wrapper around an SP_DEVINFO_DATA that initializes it properly and
15 // automatically deletes it.
16 class ScopedDeviceInfo {
17 public:
18 ScopedDeviceInfo() {
19 memset(&dev_info_data_, 0, sizeof(dev_info_data_));
20 dev_info_data_.cbSize = sizeof(dev_info_data_);
21 }
22
23 ~ScopedDeviceInfo() {
24 if (dev_info_set_ != INVALID_HANDLE_VALUE) {
25 SetupDiDeleteDeviceInfo(dev_info_set_, &dev_info_data_);
26 }
27 }
28
29 // Once the SP_DEVINFO_DATA has been populated it must be freed using the
30 // HDEVINFO it was created from.
31 void set_valid(HDEVINFO dev_info_set) {
32 DCHECK(dev_info_set_ == INVALID_HANDLE_VALUE);
33 DCHECK(dev_info_set != INVALID_HANDLE_VALUE);
34 dev_info_set_ = dev_info_set;
35 }
36
37 PSP_DEVINFO_DATA get() { return &dev_info_data_; }
38
39 private:
40 HDEVINFO dev_info_set_ = INVALID_HANDLE_VALUE;
41 SP_DEVINFO_DATA dev_info_data_;
42 };
43
44 } // namespace win
45 } // namespace base
46
47 #endif // DEVICE_CORE_SCOPED_DEVICE_INFO_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698