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

Unified Diff: device/hid/hid_connection_mac.cc

Issue 568873003: Do not open or close IOHIDManager's IOHIDDeviceRefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment explaining the NULL callback. Created 6 years, 3 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 | « device/hid/hid_connection_mac.h ('k') | 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 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);
}
}
« no previous file with comments | « device/hid/hid_connection_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698