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

Unified Diff: device/hid/hid_connection_mac.cc

Issue 2804313005: Make HidConnection::Read reentrancy safe (Closed)
Patch Set: Rebased. Created 3 years, 8 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_linux.cc ('k') | device/hid/hid_connection_win.cc » ('j') | 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 7e46b204926d779ecba0cfdc8691ebb70847bf0d..c13fc2b0d8c90c54fc3f347e7fb4fce4321f8bfe 100644
--- a/device/hid/hid_connection_mac.cc
+++ b/device/hid/hid_connection_mac.cc
@@ -152,6 +152,12 @@ void HidConnectionMac::InputReportCallback(void* context,
void HidConnectionMac::ProcessInputReport(
scoped_refptr<net::IOBufferWithSize> buffer) {
DCHECK(thread_checker().CalledOnValidThread());
+ DCHECK_GE(buffer->size(), 1);
+
+ uint8_t report_id = buffer->data()[0];
+ if (IsReportIdProtected(report_id))
+ return;
+
PendingHidReport report;
report.buffer = buffer;
report.size = buffer->size();
@@ -161,14 +167,17 @@ void HidConnectionMac::ProcessInputReport(
void HidConnectionMac::ProcessReadQueue() {
DCHECK(thread_checker().CalledOnValidThread());
+
+ // Hold a reference to |this| to prevent a callback from freeing this object
+ // during the loop.
+ scoped_refptr<HidConnectionMac> self(this);
while (pending_reads_.size() && pending_reports_.size()) {
PendingHidRead read = pending_reads_.front();
PendingHidReport report = pending_reports_.front();
+ pending_reads_.pop();
pending_reports_.pop();
- if (CompleteRead(report.buffer, report.size, read.callback)) {
- pending_reads_.pop();
- }
+ read.callback.Run(true, report.buffer, report.size);
}
}
« no previous file with comments | « device/hid/hid_connection_linux.cc ('k') | device/hid/hid_connection_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698