diff options
author | reillyg <reillyg@chromium.org> | 2014-09-12 23:15:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-13 06:18:44 +0000 |
commit | 7b245aba250436867e5fd4dff77c08b9c5dc1a9d (patch) | |
tree | 40453f723181c18848ac05b449ae614061f9ad64 /device/hid/hid_connection_mac.cc | |
parent | 2191196d13b2896f5ba7bc1c6a3371cb86a7e8eb (diff) | |
download | chromium_src-7b245aba250436867e5fd4dff77c08b9c5dc1a9d.zip chromium_src-7b245aba250436867e5fd4dff77c08b9c5dc1a9d.tar.gz chromium_src-7b245aba250436867e5fd4dff77c08b9c5dc1a9d.tar.bz2 |
Do not open or close IOHIDManager's IOHIDDeviceRefs.
The IOHIDManager object manages the IOHIDDevice instances that it
creates. Calling IOHIDDeviceOpen on such an instance is a no-op and
calling IOHIDDeviceClose prevents the IOHIDManager from tracking the
lifetime of the device. The solution is to never open nor close these
devices.
BUG=413976
Review URL: https://codereview.chromium.org/568873003
Cr-Commit-Position: refs/heads/master@{#294735}
Diffstat (limited to 'device/hid/hid_connection_mac.cc')
-rw-r--r-- | device/hid/hid_connection_mac.cc | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/device/hid/hid_connection_mac.cc b/device/hid/hid_connection_mac.cc index e06994c..ae1a142 100644 --- a/device/hid/hid_connection_mac.cc +++ b/device/hid/hid_connection_mac.cc @@ -17,21 +17,28 @@ HidConnectionMac::HidConnectionMac(HidDeviceInfo device_info) message_loop_ = base::MessageLoopProxy::current(); DCHECK(device_.get()); + size_t expected_report_size = device_info.max_input_report_size; if (device_info.has_report_id) { expected_report_size++; } - inbound_buffer_.reset(new uint8_t[expected_report_size]); - IOHIDDeviceRegisterInputReportCallback(device_.get(), - inbound_buffer_.get(), - expected_report_size, - &HidConnectionMac::InputReportCallback, - this); - IOHIDDeviceOpen(device_, kIOHIDOptionsTypeNone); + inbound_buffer_.resize(expected_report_size); + if (inbound_buffer_.size() > 0) { + IOHIDDeviceRegisterInputReportCallback( + device_.get(), + &inbound_buffer_[0], + inbound_buffer_.size(), + &HidConnectionMac::InputReportCallback, + this); + } } HidConnectionMac::~HidConnectionMac() { - IOHIDDeviceClose(device_, kIOHIDOptionsTypeNone); + if (inbound_buffer_.size() > 0) { + // Unregister the input report callback before this object is freed. + IOHIDDeviceRegisterInputReportCallback( + device_.get(), &inbound_buffer_[0], inbound_buffer_.size(), NULL, this); + } Flush(); } @@ -72,6 +79,7 @@ void HidConnectionMac::PlatformGetFeatureReport(uint8_t report_id, if (result == kIOReturnSuccess) { callback.Run(true, buffer, report_size); } else { + VLOG(1) << "Failed to get feature report: " << result; callback.Run(false, NULL, 0); } } @@ -90,6 +98,11 @@ void HidConnectionMac::InputReportCallback(void* context, uint32_t report_id, uint8_t* report_bytes, CFIndex report_length) { + if (result != kIOReturnSuccess) { + VLOG(1) << "Failed to read input report: " << result; + return; + } + HidConnectionMac* connection = static_cast<HidConnectionMac*>(context); scoped_refptr<net::IOBufferWithSize> buffer; if (connection->device_info().has_report_id) { @@ -131,6 +144,7 @@ void HidConnectionMac::WriteReport(IOHIDReportType type, if (res == kIOReturnSuccess) { callback.Run(true); } else { + VLOG(1) << "Failed to set report: " << res; callback.Run(false); } } |