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..d743aebdf3f0252ab3e539c8211fdd90858f6f82 100644 |
--- a/device/hid/hid_connection_mac.cc |
+++ b/device/hid/hid_connection_mac.cc |
@@ -17,21 +17,27 @@ 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) { |
+ IOHIDDeviceRegisterInputReportCallback( |
Ken Rockot(use gerrit already)
2014/09/13 01:36:17
Can you please comment on why this is done? I do n
Reilly Grant (use Gerrit)
2014/09/13 05:05:05
Registering a NULL callback clears the input repor
|
+ device_.get(), &inbound_buffer_[0], inbound_buffer_.size(), NULL, this); |
+ } |
Flush(); |
} |
@@ -72,6 +78,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 +97,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 +143,7 @@ void HidConnectionMac::WriteReport(IOHIDReportType type, |
if (res == kIOReturnSuccess) { |
callback.Run(true); |
} else { |
+ VLOG(1) << "Failed to set report: " << res; |
callback.Run(false); |
} |
} |