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

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

Issue 660573007: Open HID connections asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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_mac.h ('k') | device/hid/hid_service_win.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_mac.h" 5 #include "device/hid/hid_service_mac.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #include <IOKit/hid/IOHIDDevice.h> 8 #include <IOKit/hid/IOHIDDevice.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 RemoveDevice(service_path); 252 RemoveDevice(service_path);
253 } 253 }
254 254
255 // Release reference retained by AddDevices above. 255 // Release reference retained by AddDevices above.
256 IOObjectRelease(device); 256 IOObjectRelease(device);
257 // Release the reference retained by IOIteratorNext. 257 // Release the reference retained by IOIteratorNext.
258 IOObjectRelease(device); 258 IOObjectRelease(device);
259 } 259 }
260 } 260 }
261 261
262 scoped_refptr<HidConnection> HidServiceMac::Connect( 262 void HidServiceMac::Connect(const HidDeviceId& device_id,
263 const HidDeviceId& device_id) { 263 const ConnectCallback& callback) {
264 DCHECK(thread_checker_.CalledOnValidThread()); 264 DCHECK(thread_checker_.CalledOnValidThread());
265 265
266 const auto& map_entry = devices().find(device_id); 266 const auto& map_entry = devices().find(device_id);
267 if (map_entry == devices().end()) { 267 if (map_entry == devices().end()) {
268 return NULL; 268 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
269 return;
269 } 270 }
270 const HidDeviceInfo& device_info = map_entry->second; 271 const HidDeviceInfo& device_info = map_entry->second;
271 272
272 io_string_t service_path; 273 io_string_t service_path;
273 strncpy(service_path, device_id.c_str(), sizeof service_path); 274 strncpy(service_path, device_id.c_str(), sizeof service_path);
274 base::mac::ScopedIOObject<io_service_t> service( 275 base::mac::ScopedIOObject<io_service_t> service(
275 IORegistryEntryFromPath(kIOMasterPortDefault, service_path)); 276 IORegistryEntryFromPath(kIOMasterPortDefault, service_path));
276 if (!service.get()) { 277 if (!service.get()) {
277 VLOG(1) << "IOService not found for path: " << device_id; 278 VLOG(1) << "IOService not found for path: " << device_id;
278 return NULL; 279 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
280 return;
279 } 281 }
280 282
281 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device( 283 base::ScopedCFTypeRef<IOHIDDeviceRef> hid_device(
282 IOHIDDeviceCreate(kCFAllocatorDefault, service)); 284 IOHIDDeviceCreate(kCFAllocatorDefault, service));
283 IOReturn result = IOHIDDeviceOpen(hid_device, kIOHIDOptionsTypeNone); 285 IOReturn result = IOHIDDeviceOpen(hid_device, kIOHIDOptionsTypeNone);
284 if (result != kIOReturnSuccess) { 286 if (result != kIOReturnSuccess) {
285 VLOG(1) << "Failed to open device: " 287 VLOG(1) << "Failed to open device: "
286 << base::StringPrintf("0x%04x", result); 288 << base::StringPrintf("0x%04x", result);
287 return NULL; 289 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
290 return;
288 } 291 }
289 292
290 return make_scoped_refptr(new HidConnectionMac( 293 task_runner_->PostTask(
291 hid_device.release(), device_info, file_task_runner_)); 294 FROM_HERE,
295 base::Bind(callback,
296 make_scoped_refptr(new HidConnectionMac(
297 hid_device.release(), device_info, file_task_runner_))));
292 } 298 }
293 299
294 } // namespace device 300 } // namespace device
OLDNEW
« no previous file with comments | « device/hid/hid_service_mac.h ('k') | device/hid/hid_service_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698