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

Unified Diff: device/hid/hid_connection_mac.cc

Issue 223793002: Handle HID report ID correctly on Mac OS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_connection_mac.cc
diff --git a/device/hid/hid_connection_mac.cc b/device/hid/hid_connection_mac.cc
index 63b7998131ce2c00a322efb8aca5aaf469f3b0e0..ce17df4cc9b395db475acc97e3bb097d4220eb4c 100644
--- a/device/hid/hid_connection_mac.cc
+++ b/device/hid/hid_connection_mac.cc
@@ -105,18 +105,11 @@ void HidConnectionMac::InputReportCallback(void* context,
uint8_t* report_bytes,
CFIndex report_length) {
HidConnectionMac* connection = static_cast<HidConnectionMac*>(context);
- // If a report ID was received, inject it into a copy of the received
- // report. This is consistent with how input reports are received on
- // other platforms.
+ // report_id is already contained in report_bytes
scoped_refptr<net::IOBufferWithSize> buffer;
- if (report_id != 0) {
- buffer = new net::IOBufferWithSize(report_length + 1);
- buffer->data()[0] = static_cast<uint8_t>(report_id);
- memcpy(buffer->data() + 1, report_bytes, report_length);
- } else {
- buffer = new net::IOBufferWithSize(report_length);
- memcpy(buffer->data(), report_bytes, report_length);
- }
+ buffer = new net::IOBufferWithSize(report_length);
+ memcpy(buffer->data(), report_bytes, report_length);
+
connection->message_loop_->PostTask(
FROM_HERE,
base::Bind(
@@ -158,16 +151,25 @@ void HidConnectionMac::WriteReport(IOHIDReportType type,
callback.Run(false, 0);
return;
}
+ scoped_refptr<net::IOBufferWithSize> output_buffer;
+ if (report_id != 0) {
+ output_buffer = new net::IOBufferWithSize(buffer->size() + 1);
+ output_buffer->data()[0] = static_cast<uint8_t>(report_id);
+ memcpy(output_buffer->data() + 1, buffer->data(), buffer->size());
+ } else {
+ output_buffer = new net::IOBufferWithSize(buffer->size());
+ memcpy(output_buffer->data(), buffer->data(), buffer->size());
+ }
IOReturn res =
IOHIDDeviceSetReport(device_.get(),
type,
report_id,
- reinterpret_cast<uint8_t*>(buffer->data()),
- buffer->size());
+ reinterpret_cast<uint8_t*>(output_buffer->data()),
+ output_buffer->size());
if (res != kIOReturnSuccess) {
callback.Run(false, 0);
} else {
- callback.Run(true, buffer->size());
+ callback.Run(true, output_buffer->size());
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698