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

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

Issue 161823002: Clean up HID backend and API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for reals Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <cstdlib> 7 #include <cstdlib>
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 if (!res) 140 if (!res)
141 continue; 141 continue;
142 142
143 PlatformAddDevice(device_interface_detail_data->DevicePath); 143 PlatformAddDevice(device_interface_detail_data->DevicePath);
144 } 144 }
145 145
146 return true; 146 return true;
147 } 147 }
148 148
149 void HidServiceWin::PlatformAddDevice(std::string device_path) { 149 void HidServiceWin::PlatformAddDevice(const std::string& device_path) {
150 HidDeviceInfo device_info; 150 HidDeviceInfo device_info;
151 device_info.device_id = device_path; 151 device_info.device_id = device_path;
152 152
153 // Try to open the device. 153 // Try to open the device.
154 base::win::ScopedHandle device_handle( 154 base::win::ScopedHandle device_handle(
155 CreateFileA(device_path.c_str(), 155 CreateFileA(device_path.c_str(),
156 0, 156 0,
157 FILE_SHARE_READ | FILE_SHARE_WRITE, 157 FILE_SHARE_READ | FILE_SHARE_WRITE,
158 NULL, 158 NULL,
159 OPEN_EXISTING, 159 OPEN_EXISTING,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 if (HidD_GetProductString(device_handle.Get(), 211 if (HidD_GetProductString(device_handle.Get(),
212 str_property, 212 str_property,
213 sizeof(str_property))) { 213 sizeof(str_property))) {
214 device_info.product_name = base::SysWideToUTF8(str_property); 214 device_info.product_name = base::SysWideToUTF8(str_property);
215 } 215 }
216 216
217 HidService::AddDevice(device_info); 217 HidService::AddDevice(device_info);
218 } 218 }
219 219
220 void HidServiceWin::PlatformRemoveDevice(std::string device_path) { 220 void HidServiceWin::PlatformRemoveDevice(const std::string& device_path) {
221 HidService::RemoveDevice(device_path); 221 HidService::RemoveDevice(device_path);
222 } 222 }
223 223
224 void HidServiceWin::GetDevices(std::vector<HidDeviceInfo>* devices) { 224 void HidServiceWin::GetDevices(std::vector<HidDeviceInfo>* devices) {
225 Enumerate(); 225 Enumerate();
226 HidService::GetDevices(devices); 226 HidService::GetDevices(devices);
227 } 227 }
228 228
229 scoped_refptr<HidConnection> HidServiceWin::Connect(std::string device_id) { 229 scoped_refptr<HidConnection> HidServiceWin::Connect(
230 const std::string& device_id) {
230 if (!ContainsKey(devices_, device_id)) return NULL; 231 if (!ContainsKey(devices_, device_id)) return NULL;
231 scoped_refptr<HidConnectionWin> connection( 232 scoped_refptr<HidConnectionWin> connection(
232 new HidConnectionWin(devices_[device_id])); 233 new HidConnectionWin(devices_[device_id]));
233 if (!connection->available()) { 234 if (!connection->available()) {
234 LOG_GETLASTERROR(ERROR) << "Failed to open device."; 235 LOG_GETLASTERROR(ERROR) << "Failed to open device.";
235 return NULL; 236 return NULL;
236 } 237 }
237 return connection; 238 return connection;
238 } 239 }
239 240
240 } // namespace device 241 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698