OLD | NEW |
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 << HexErrorCode(result); | 122 << HexErrorCode(result); |
123 return; | 123 return; |
124 } | 124 } |
125 | 125 |
126 // Drain devices_added_iterator_ to arm the notification. | 126 // Drain devices_added_iterator_ to arm the notification. |
127 devices_removed_iterator_.reset(iterator); | 127 devices_removed_iterator_.reset(iterator); |
128 RemoveDevices(); | 128 RemoveDevices(); |
129 FirstEnumerationComplete(); | 129 FirstEnumerationComplete(); |
130 } | 130 } |
131 | 131 |
| 132 HidServiceMac::~HidServiceMac() {} |
| 133 |
132 void HidServiceMac::Connect(const HidDeviceId& device_id, | 134 void HidServiceMac::Connect(const HidDeviceId& device_id, |
133 const ConnectCallback& callback) { | 135 const ConnectCallback& callback) { |
134 DCHECK(thread_checker_.CalledOnValidThread()); | 136 DCHECK(thread_checker_.CalledOnValidThread()); |
135 | 137 |
136 const auto& map_entry = devices().find(device_id); | 138 const auto& map_entry = devices().find(device_id); |
137 if (map_entry == devices().end()) { | 139 if (map_entry == devices().end()) { |
138 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 140 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
139 return; | 141 return; |
140 } | 142 } |
141 scoped_refptr<HidDeviceInfo> device_info = map_entry->second; | 143 scoped_refptr<HidDeviceInfo> device_info = map_entry->second; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); | 175 task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr)); |
174 return; | 176 return; |
175 } | 177 } |
176 | 178 |
177 task_runner_->PostTask( | 179 task_runner_->PostTask( |
178 FROM_HERE, base::Bind(callback, make_scoped_refptr(new HidConnectionMac( | 180 FROM_HERE, base::Bind(callback, make_scoped_refptr(new HidConnectionMac( |
179 hid_device.release(), device_info, | 181 hid_device.release(), device_info, |
180 file_task_runner_)))); | 182 file_task_runner_)))); |
181 } | 183 } |
182 | 184 |
183 HidServiceMac::~HidServiceMac() { | |
184 } | |
185 | |
186 // static | 185 // static |
187 void HidServiceMac::FirstMatchCallback(void* context, io_iterator_t iterator) { | 186 void HidServiceMac::FirstMatchCallback(void* context, io_iterator_t iterator) { |
188 DCHECK_EQ(CFRunLoopGetMain(), CFRunLoopGetCurrent()); | 187 DCHECK_EQ(CFRunLoopGetMain(), CFRunLoopGetCurrent()); |
189 HidServiceMac* service = static_cast<HidServiceMac*>(context); | 188 HidServiceMac* service = static_cast<HidServiceMac*>(context); |
190 DCHECK_EQ(service->devices_added_iterator_, iterator); | 189 DCHECK_EQ(service->devices_added_iterator_, iterator); |
191 service->AddDevices(); | 190 service->AddDevices(); |
192 } | 191 } |
193 | 192 |
194 // static | 193 // static |
195 void HidServiceMac::TerminatedCallback(void* context, io_iterator_t iterator) { | 194 void HidServiceMac::TerminatedCallback(void* context, io_iterator_t iterator) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return new HidDeviceInfo( | 261 return new HidDeviceInfo( |
263 entry_id, GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)), | 262 entry_id, GetHidIntProperty(hid_device, CFSTR(kIOHIDVendorIDKey)), |
264 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)), | 263 GetHidIntProperty(hid_device, CFSTR(kIOHIDProductIDKey)), |
265 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)), | 264 GetHidStringProperty(hid_device, CFSTR(kIOHIDProductKey)), |
266 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)), | 265 GetHidStringProperty(hid_device, CFSTR(kIOHIDSerialNumberKey)), |
267 kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335 | 266 kHIDBusTypeUSB, // TODO(reillyg): Detect Bluetooth. crbug.com/443335 |
268 report_descriptor); | 267 report_descriptor); |
269 } | 268 } |
270 | 269 |
271 } // namespace device | 270 } // namespace device |
OLD | NEW |