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

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

Issue 225513005: chrome.hid : enrich device info with Top-Level collections usages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: renaming 'parent_item' Created 6 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
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/IOHIDManager.h> 8 #include <IOKit/hid/IOHIDManager.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Note that our ownership of hid_device is implied if calling this method. 136 // Note that our ownership of hid_device is implied if calling this method.
137 // It is balanced in PlatformRemoveDevice. 137 // It is balanced in PlatformRemoveDevice.
138 DCHECK(thread_checker_.CalledOnValidThread()); 138 DCHECK(thread_checker_.CalledOnValidThread());
139 139
140 HidDeviceInfo device_info; 140 HidDeviceInfo device_info;
141 device_info.device_id = hid_device; 141 device_info.device_id = hid_device;
142 device_info.vendor_id = 142 device_info.vendor_id =
143 GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)); 143 GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey));
144 device_info.product_id = 144 device_info.product_id =
145 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)); 145 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey));
146 device_info.usage =
147 GetHidIntProperty(hid_device, CFSTR(kIOHIDPrimaryUsageKey));
148 device_info.usage_page =
149 GetHidIntProperty(hid_device, CFSTR(kIOHIDPrimaryUsagePageKey));
150 device_info.input_report_size = 146 device_info.input_report_size =
151 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxInputReportSizeKey)); 147 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxInputReportSizeKey));
152 device_info.output_report_size = 148 device_info.output_report_size =
153 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxOutputReportSizeKey)); 149 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxOutputReportSizeKey));
154 device_info.feature_report_size = 150 device_info.feature_report_size =
155 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxFeatureReportSizeKey)); 151 GetHidIntProperty(hid_device, CFSTR(kIOHIDMaxFeatureReportSizeKey));
152 CFTypeRef deviceUsagePairsRaw =
153 IOHIDDeviceGetProperty(hid_device, CFSTR(kIOHIDDeviceUsagePairsKey));
154 CFArrayRef deviceUsagePairs =
155 base::mac::CFCast<CFArrayRef>(deviceUsagePairsRaw);
156 CFIndex deviceUsagePairsCount = CFArrayGetCount(deviceUsagePairs);
157 for (CFIndex i = 0; i < deviceUsagePairsCount; i++) {
158 HidUsageAndPage usage_and_page;
159 CFDictionaryRef deviceUsagePair = base::mac::CFCast<CFDictionaryRef>(
160 CFArrayGetValueAtIndex(deviceUsagePairs, i));
161 CFNumberRef usage_page_raw = base::mac::CFCast<CFNumberRef>(
162 CFDictionaryGetValue(deviceUsagePair, CFSTR(kIOHIDDeviceUsagePageKey)));
163 CFNumberGetValue(
164 usage_page_raw, kCFNumberSInt32Type, &usage_and_page.usage_page);
165 CFNumberRef usage_raw = base::mac::CFCast<CFNumberRef>(
166 CFDictionaryGetValue(deviceUsagePair, CFSTR(kIOHIDDeviceUsageKey)));
167 CFNumberGetValue(usage_raw, kCFNumberSInt32Type, &usage_and_page.usage);
168 device_info.usages.push_back(usage_and_page);
169 }
156 device_info.product_name = 170 device_info.product_name =
157 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)); 171 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey));
158 device_info.serial_number = 172 device_info.serial_number =
159 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)); 173 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey));
160 AddDevice(device_info); 174 AddDevice(device_info);
161 } 175 }
162 176
163 void HidServiceMac::PlatformRemoveDevice(IOHIDDeviceRef hid_device) { 177 void HidServiceMac::PlatformRemoveDevice(IOHIDDeviceRef hid_device) {
164 DCHECK(thread_checker_.CalledOnValidThread()); 178 DCHECK(thread_checker_.CalledOnValidThread());
165 RemoveDevice(hid_device); 179 RemoveDevice(hid_device);
166 CFRelease(hid_device); 180 CFRelease(hid_device);
167 } 181 }
168 182
169 scoped_refptr<HidConnection> HidServiceMac::Connect( 183 scoped_refptr<HidConnection> HidServiceMac::Connect(
170 const HidDeviceId& device_id) { 184 const HidDeviceId& device_id) {
171 DCHECK(thread_checker_.CalledOnValidThread()); 185 DCHECK(thread_checker_.CalledOnValidThread());
172 HidDeviceInfo device_info; 186 HidDeviceInfo device_info;
173 if (!GetDeviceInfo(device_id, &device_info)) 187 if (!GetDeviceInfo(device_id, &device_info))
174 return NULL; 188 return NULL;
175 return scoped_refptr<HidConnection>(new HidConnectionMac(device_info)); 189 return scoped_refptr<HidConnection>(new HidConnectionMac(device_info));
176 } 190 }
177 191
178 } // namespace device 192 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698