Index: device/hid/hid_connection_linux.cc |
diff --git a/device/hid/hid_connection_linux.cc b/device/hid/hid_connection_linux.cc |
index b6f90a90f9f2b646907a6c0fd9d97f9ce2ea4e80..fc185f064f9f5263ba5005ae6072af92f6a58255 100644 |
--- a/device/hid/hid_connection_linux.cc |
+++ b/device/hid/hid_connection_linux.cc |
@@ -45,9 +45,7 @@ scoped_refptr<net::IOBufferWithSize> CopyBufferWithReportId( |
HidConnectionLinux::HidConnectionLinux(HidDeviceInfo device_info, |
std::string dev_node) |
- : HidConnection(device_info) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- |
+ : HidConnection2(device_info) { |
int flags = base::File::FLAG_OPEN | |
base::File::FLAG_READ | |
base::File::FLAG_WRITE; |
@@ -87,59 +85,13 @@ HidConnectionLinux::HidConnectionLinux(HidDeviceInfo device_info, |
} |
HidConnectionLinux::~HidConnectionLinux() { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
Disconnect(); |
} |
-void HidConnectionLinux::OnFileCanReadWithoutBlocking(int fd) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- DCHECK_EQ(fd, device_file_.GetPlatformFile()); |
- |
- uint8 buffer[1024] = {0}; |
- int bytes_read = |
- HANDLE_EINTR(read(device_file_.GetPlatformFile(), buffer, 1024)); |
- if (bytes_read < 0) { |
- if (errno == EAGAIN) { |
- return; |
- } |
- Disconnect(); |
- return; |
- } |
- |
- PendingHidReport report; |
- report.buffer = new net::IOBufferWithSize(bytes_read); |
- memcpy(report.buffer->data(), buffer, bytes_read); |
- pending_reports_.push(report); |
- ProcessReadQueue(); |
-} |
- |
-void HidConnectionLinux::OnFileCanWriteWithoutBlocking(int fd) {} |
- |
-void HidConnectionLinux::Disconnect() { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- device_file_watcher_.StopWatchingFileDescriptor(); |
- device_file_.Close(); |
- while (!pending_reads_.empty()) { |
- PendingHidRead pending_read = pending_reads_.front(); |
- pending_reads_.pop(); |
- pending_read.callback.Run(false, 0); |
- } |
-} |
- |
-void HidConnectionLinux::Read(scoped_refptr<net::IOBufferWithSize> buffer, |
- const IOCallback& callback) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- PendingHidRead pending_read; |
- pending_read.buffer = buffer; |
- pending_read.callback = callback; |
- pending_reads_.push(pending_read); |
- ProcessReadQueue(); |
-} |
- |
-void HidConnectionLinux::Write(uint8_t report_id, |
- scoped_refptr<net::IOBufferWithSize> buffer, |
- const IOCallback& callback) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
+void HidConnectionLinux::PlatformWrite( |
+ uint8_t report_id, |
+ scoped_refptr<net::IOBufferWithSize> buffer, |
+ const IOCallback& callback) { |
// If report ID is non-zero, insert it into a new copy of the buffer. |
if (report_id != 0) |
buffer = CopyBufferWithReportId(buffer, report_id); |
@@ -153,12 +105,10 @@ void HidConnectionLinux::Write(uint8_t report_id, |
} |
} |
-void HidConnectionLinux::GetFeatureReport( |
+void HidConnectionLinux::PlatformGetFeatureReport( |
uint8_t report_id, |
scoped_refptr<net::IOBufferWithSize> buffer, |
const IOCallback& callback) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- |
if (buffer->size() == 0) { |
callback.Run(false, 0); |
return; |
@@ -175,11 +125,10 @@ void HidConnectionLinux::GetFeatureReport( |
callback.Run(true, result); |
} |
-void HidConnectionLinux::SendFeatureReport( |
+void HidConnectionLinux::PlatformSendFeatureReport( |
uint8_t report_id, |
scoped_refptr<net::IOBufferWithSize> buffer, |
const IOCallback& callback) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
if (report_id != 0) |
buffer = CopyBufferWithReportId(buffer, report_id); |
int result = ioctl(device_file_.GetPlatformFile(), |
@@ -191,19 +140,37 @@ void HidConnectionLinux::SendFeatureReport( |
callback.Run(true, result); |
} |
-void HidConnectionLinux::ProcessReadQueue() { |
- while (pending_reads_.size() && pending_reports_.size()) { |
- PendingHidRead read = pending_reads_.front(); |
- pending_reads_.pop(); |
- PendingHidReport report = pending_reports_.front(); |
- if (report.buffer->size() > read.buffer->size()) { |
- read.callback.Run(false, report.buffer->size()); |
- } else { |
- memcpy(read.buffer->data(), report.buffer->data(), report.buffer->size()); |
- pending_reports_.pop(); |
- read.callback.Run(true, report.buffer->size()); |
+void HidConnectionLinux::OnFileCanReadWithoutBlocking(int fd) { |
+ DCHECK(thread_checker().CalledOnValidThread()); |
+ DCHECK_EQ(fd, device_file_.GetPlatformFile()); |
+ |
+ uint8 raw_buffer[1024] = {0}; |
+ int bytes_read = |
+ HANDLE_EINTR(read(device_file_.GetPlatformFile(), raw_buffer, 1024)); |
+ if (bytes_read < 0) { |
+ if (errno == EAGAIN) { |
+ return; |
} |
+ Disconnect(); |
+ return; |
} |
+ |
+ scoped_refptr<net::IOBufferWithSize> buffer = |
+ new net::IOBufferWithSize(bytes_read); |
+ memcpy(buffer->data(), raw_buffer, bytes_read); |
+ |
+ ProcessInputReport(buffer); |
+} |
+ |
+void HidConnectionLinux::OnFileCanWriteWithoutBlocking(int fd) { |
+} |
+ |
+void HidConnectionLinux::Disconnect() { |
+ DCHECK(thread_checker().CalledOnValidThread()); |
+ device_file_watcher_.StopWatchingFileDescriptor(); |
+ device_file_.Close(); |
+ |
+ Flush(); |
} |
} // namespace device |