Commit 3a3d2720 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Address comments left on r581994

Somehow these changes didn't make into the last patchset uploaded for
r581994 and so I have recreated them here.

Change-Id: I54cf951d46ad12c23433996dee790ce25047c8a5
Reviewed-on: https://chromium-review.googlesource.com/1187020Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585614}
parent a9277ba0
...@@ -63,23 +63,6 @@ bool HasProtectedCollection( ...@@ -63,23 +63,6 @@ bool HasProtectedCollection(
} // namespace } // namespace
struct HidConnection::PendingHidReport {
PendingHidReport() = default;
PendingHidReport(const PendingHidReport& other) = default;
~PendingHidReport() = default;
scoped_refptr<base::RefCountedBytes> buffer;
size_t size;
};
struct HidConnection::PendingHidRead {
PendingHidRead() = default;
PendingHidRead(PendingHidRead&& other) = default;
~PendingHidRead() = default;
HidConnection::ReadCallback callback;
};
HidConnection::HidConnection(scoped_refptr<HidDeviceInfo> device_info) HidConnection::HidConnection(scoped_refptr<HidDeviceInfo> device_info)
: device_info_(device_info), closed_(false) { : device_info_(device_info), closed_(false) {
has_protected_collection_ = has_protected_collection_ =
...@@ -107,9 +90,7 @@ void HidConnection::Read(ReadCallback callback) { ...@@ -107,9 +90,7 @@ void HidConnection::Read(ReadCallback callback) {
return; return;
} }
PendingHidRead pending_read; pending_reads_.emplace(std::move(callback));
pending_read.callback = std::move(callback);
pending_reads_.push(std::move(pending_read));
ProcessReadQueue(); ProcessReadQueue();
} }
...@@ -210,10 +191,7 @@ void HidConnection::ProcessInputReport( ...@@ -210,10 +191,7 @@ void HidConnection::ProcessInputReport(
if (IsReportIdProtected(report_id)) if (IsReportIdProtected(report_id))
return; return;
PendingHidReport report; pending_reports_.emplace(buffer, size);
report.buffer = buffer;
report.size = size;
pending_reports_.push(report);
ProcessReadQueue(); ProcessReadQueue();
} }
...@@ -224,12 +202,15 @@ void HidConnection::ProcessReadQueue() { ...@@ -224,12 +202,15 @@ void HidConnection::ProcessReadQueue() {
// during the loop. // during the loop.
scoped_refptr<HidConnection> self(this); scoped_refptr<HidConnection> self(this);
while (pending_reads_.size() && pending_reports_.size()) { while (pending_reads_.size() && pending_reports_.size()) {
PendingHidRead read = std::move(pending_reads_.front()); ReadCallback callback = std::move(pending_reads_.front());
PendingHidReport report = std::move(pending_reports_.front());
scoped_refptr<base::RefCountedBytes> buffer;
size_t size;
std::tie(buffer, size) = std::move(pending_reports_.front());
pending_reads_.pop(); pending_reads_.pop();
pending_reports_.pop(); pending_reports_.pop();
std::move(read.callback).Run(true, std::move(report.buffer), report.size); std::move(callback).Run(true, std::move(buffer), size);
} }
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <tuple>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/containers/queue.h" #include "base/containers/queue.h"
...@@ -83,16 +84,14 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> { ...@@ -83,16 +84,14 @@ class HidConnection : public base::RefCountedThreadSafe<HidConnection> {
void ProcessReadQueue(); void ProcessReadQueue();
private: private:
struct PendingHidReport;
struct PendingHidRead;
scoped_refptr<HidDeviceInfo> device_info_; scoped_refptr<HidDeviceInfo> device_info_;
bool has_protected_collection_; bool has_protected_collection_;
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
bool closed_; bool closed_;
base::queue<PendingHidReport> pending_reports_; base::queue<std::tuple<scoped_refptr<base::RefCountedBytes>, size_t>>
base::queue<PendingHidRead> pending_reads_; pending_reports_;
base::queue<ReadCallback> pending_reads_;
DISALLOW_COPY_AND_ASSIGN(HidConnection); DISALLOW_COPY_AND_ASSIGN(HidConnection);
}; };
......
...@@ -44,6 +44,7 @@ class PendingHidTransfer : public base::win::ObjectWatcher::Delegate { ...@@ -44,6 +44,7 @@ class PendingHidTransfer : public base::win::ObjectWatcher::Delegate {
// Implements base::win::ObjectWatcher::Delegate. // Implements base::win::ObjectWatcher::Delegate.
void OnObjectSignaled(HANDLE object) override; void OnObjectSignaled(HANDLE object) override;
private:
// The buffer isn't used by this object but it's important that a reference // The buffer isn't used by this object but it's important that a reference
// to it is held until the transfer completes. // to it is held until the transfer completes.
scoped_refptr<base::RefCountedBytes> buffer_; scoped_refptr<base::RefCountedBytes> buffer_;
...@@ -52,7 +53,6 @@ class PendingHidTransfer : public base::win::ObjectWatcher::Delegate { ...@@ -52,7 +53,6 @@ class PendingHidTransfer : public base::win::ObjectWatcher::Delegate {
base::win::ScopedHandle event_; base::win::ScopedHandle event_;
base::win::ObjectWatcher watcher_; base::win::ObjectWatcher watcher_;
private:
DISALLOW_COPY_AND_ASSIGN(PendingHidTransfer); DISALLOW_COPY_AND_ASSIGN(PendingHidTransfer);
}; };
...@@ -241,7 +241,6 @@ void HidConnectionWin::OnWriteComplete(WriteCallback callback, ...@@ -241,7 +241,6 @@ void HidConnectionWin::OnWriteComplete(WriteCallback callback,
DWORD bytes_transferred; DWORD bytes_transferred;
if (signaled && GetOverlappedResult(file_.Get(), transfer->GetOverlapped(), if (signaled && GetOverlappedResult(file_.Get(), transfer->GetOverlapped(),
&bytes_transferred, FALSE)) { &bytes_transferred, FALSE)) {
DCHECK_LE(bytes_transferred, transfer->buffer_->size());
std::move(callback).Run(true); std::move(callback).Run(true);
} else { } else {
HID_PLOG(EVENT) << "HID write failed"; HID_PLOG(EVENT) << "HID write failed";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment