| Index: device/hid/hid_connection_mac.cc
|
| diff --git a/device/hid/hid_connection_mac.cc b/device/hid/hid_connection_mac.cc
|
| index e06994c049d35268fad1d57cd7c1da945d7e2d35..ae1a14261df13ac440cc3aa2188dd2e27bc104d1 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);
|
| }
|
| }
|
|
|