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

Side by Side Diff: device/hid/hid_service_win.cc

Issue 1874313002: Convert device to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months 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
« no previous file with comments | « device/hid/hid_service_win.h ('k') | device/hid/input_service_linux.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/hid/hid_service_win.h" 5 #include "device/hid/hid_service_win.h"
6 6
7 #include <memory>
8
7 #define INITGUID 9 #define INITGUID
8 10
9 #include <dbt.h> 11 #include <dbt.h>
10 #include <setupapi.h> 12 #include <setupapi.h>
11 #include <stddef.h> 13 #include <stddef.h>
12 #include <winioctl.h> 14 #include <winioctl.h>
13 15
14 #include <utility> 16 #include <utility>
15 17
16 #include "base/bind.h" 18 #include "base/bind.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 &GUID_DEVINTERFACE_HID, 91 &GUID_DEVINTERFACE_HID,
90 device_index, 92 device_index,
91 &device_interface_data); 93 &device_interface_data);
92 ++device_index) { 94 ++device_index) {
93 DWORD required_size = 0; 95 DWORD required_size = 0;
94 96
95 // Determime the required size of detail struct. 97 // Determime the required size of detail struct.
96 SetupDiGetDeviceInterfaceDetail(device_info_set, &device_interface_data, 98 SetupDiGetDeviceInterfaceDetail(device_info_set, &device_interface_data,
97 NULL, 0, &required_size, NULL); 99 NULL, 0, &required_size, NULL);
98 100
99 scoped_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA, base::FreeDeleter> 101 std::unique_ptr<SP_DEVICE_INTERFACE_DETAIL_DATA, base::FreeDeleter>
100 device_interface_detail_data( 102 device_interface_detail_data(
101 static_cast<SP_DEVICE_INTERFACE_DETAIL_DATA*>(malloc(required_size))); 103 static_cast<SP_DEVICE_INTERFACE_DETAIL_DATA*>(malloc(required_size)));
102 device_interface_detail_data->cbSize = 104 device_interface_detail_data->cbSize =
103 sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); 105 sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
104 106
105 // Get the detailed data for this device. 107 // Get the detailed data for this device.
106 BOOL res = SetupDiGetDeviceInterfaceDetail( 108 BOOL res = SetupDiGetDeviceInterfaceDetail(
107 device_info_set, &device_interface_data, 109 device_info_set, &device_interface_data,
108 device_interface_detail_data.get(), required_size, NULL, NULL); 110 device_interface_detail_data.get(), required_size, NULL, NULL);
109 if (!res) { 111 if (!res) {
(...skipping 12 matching lines...) Expand all
122 FROM_HERE, base::Bind(&HidServiceWin::FirstEnumerationComplete, service)); 124 FROM_HERE, base::Bind(&HidServiceWin::FirstEnumerationComplete, service));
123 } 125 }
124 126
125 // static 127 // static
126 void HidServiceWin::CollectInfoFromButtonCaps( 128 void HidServiceWin::CollectInfoFromButtonCaps(
127 PHIDP_PREPARSED_DATA preparsed_data, 129 PHIDP_PREPARSED_DATA preparsed_data,
128 HIDP_REPORT_TYPE report_type, 130 HIDP_REPORT_TYPE report_type,
129 USHORT button_caps_length, 131 USHORT button_caps_length,
130 HidCollectionInfo* collection_info) { 132 HidCollectionInfo* collection_info) {
131 if (button_caps_length > 0) { 133 if (button_caps_length > 0) {
132 scoped_ptr<HIDP_BUTTON_CAPS[]> button_caps( 134 std::unique_ptr<HIDP_BUTTON_CAPS[]> button_caps(
133 new HIDP_BUTTON_CAPS[button_caps_length]); 135 new HIDP_BUTTON_CAPS[button_caps_length]);
134 if (HidP_GetButtonCaps(report_type, 136 if (HidP_GetButtonCaps(report_type,
135 &button_caps[0], 137 &button_caps[0],
136 &button_caps_length, 138 &button_caps_length,
137 preparsed_data) == HIDP_STATUS_SUCCESS) { 139 preparsed_data) == HIDP_STATUS_SUCCESS) {
138 for (size_t i = 0; i < button_caps_length; i++) { 140 for (size_t i = 0; i < button_caps_length; i++) {
139 int report_id = button_caps[i].ReportID; 141 int report_id = button_caps[i].ReportID;
140 if (report_id != 0) { 142 if (report_id != 0) {
141 collection_info->report_ids.insert(report_id); 143 collection_info->report_ids.insert(report_id);
142 } 144 }
143 } 145 }
144 } 146 }
145 } 147 }
146 } 148 }
147 149
148 // static 150 // static
149 void HidServiceWin::CollectInfoFromValueCaps( 151 void HidServiceWin::CollectInfoFromValueCaps(
150 PHIDP_PREPARSED_DATA preparsed_data, 152 PHIDP_PREPARSED_DATA preparsed_data,
151 HIDP_REPORT_TYPE report_type, 153 HIDP_REPORT_TYPE report_type,
152 USHORT value_caps_length, 154 USHORT value_caps_length,
153 HidCollectionInfo* collection_info) { 155 HidCollectionInfo* collection_info) {
154 if (value_caps_length > 0) { 156 if (value_caps_length > 0) {
155 scoped_ptr<HIDP_VALUE_CAPS[]> value_caps( 157 std::unique_ptr<HIDP_VALUE_CAPS[]> value_caps(
156 new HIDP_VALUE_CAPS[value_caps_length]); 158 new HIDP_VALUE_CAPS[value_caps_length]);
157 if (HidP_GetValueCaps( 159 if (HidP_GetValueCaps(
158 report_type, &value_caps[0], &value_caps_length, preparsed_data) == 160 report_type, &value_caps[0], &value_caps_length, preparsed_data) ==
159 HIDP_STATUS_SUCCESS) { 161 HIDP_STATUS_SUCCESS) {
160 for (size_t i = 0; i < value_caps_length; i++) { 162 for (size_t i = 0; i < value_caps_length; i++) {
161 int report_id = value_caps[i].ReportID; 163 int report_id = value_caps[i].ReportID;
162 if (report_id != 0) { 164 if (report_id != 0) {
163 collection_info->report_ids.insert(report_id); 165 collection_info->report_ids.insert(report_id);
164 } 166 }
165 } 167 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 294 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
293 FILE_FLAG_OVERLAPPED, NULL)); 295 FILE_FLAG_OVERLAPPED, NULL));
294 if (!file.IsValid() && GetLastError() == ERROR_ACCESS_DENIED) { 296 if (!file.IsValid() && GetLastError() == ERROR_ACCESS_DENIED) {
295 file.Set(CreateFileA(device_path.c_str(), GENERIC_READ, FILE_SHARE_READ, 297 file.Set(CreateFileA(device_path.c_str(), GENERIC_READ, FILE_SHARE_READ,
296 NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)); 298 NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL));
297 } 299 }
298 return file; 300 return file;
299 } 301 }
300 302
301 } // namespace device 303 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_service_win.h ('k') | device/hid/input_service_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698