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

Unified Diff: trunk/src/device/hid/hid_connection_linux.cc

Issue 364213005: Revert 281282 "Revert 281133 "chrome.hid: enrich model with repo..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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 | « trunk/src/device/hid/hid_connection_linux.h ('k') | trunk/src/device/hid/hid_connection_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/device/hid/hid_connection_linux.cc
===================================================================
--- trunk/src/device/hid/hid_connection_linux.cc (revision 281299)
+++ trunk/src/device/hid/hid_connection_linux.cc (working copy)
@@ -46,8 +46,6 @@
HidConnectionLinux::HidConnectionLinux(HidDeviceInfo device_info,
std::string dev_node)
: HidConnection(device_info) {
- DCHECK(thread_checker_.CalledOnValidThread());
-
int flags = base::File::FLAG_OPEN |
base::File::FLAG_READ |
base::File::FLAG_WRITE;
@@ -88,49 +86,13 @@
}
HidConnectionLinux::~HidConnectionLinux() {
- DCHECK(thread_checker_.CalledOnValidThread());
Disconnect();
+ Flush();
}
-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;
- }
- VPLOG(1) << "Read failed";
- 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());
+void HidConnectionLinux::PlatformRead(
+ scoped_refptr<net::IOBufferWithSize> buffer,
+ const IOCallback& callback) {
PendingHidRead pending_read;
pending_read.buffer = buffer;
pending_read.callback = callback;
@@ -138,10 +100,10 @@
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);
@@ -156,12 +118,10 @@
}
}
-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;
@@ -180,11 +140,10 @@
}
}
-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(),
@@ -198,17 +157,72 @@
}
}
+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;
+ }
+ VPLOG(1) << "Read failed";
+ 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();
+}
+
+void HidConnectionLinux::Flush() {
+ while (!pending_reads_.empty()) {
+ pending_reads_.front().callback.Run(false, 0);
+ pending_reads_.pop();
+ }
+}
+
+void HidConnectionLinux::ProcessInputReport(
+ scoped_refptr<net::IOBufferWithSize> buffer) {
+ DCHECK(thread_checker().CalledOnValidThread());
+ PendingHidReport report;
+ report.buffer = buffer;
+ pending_reports_.push(report);
+ ProcessReadQueue();
+}
+
void HidConnectionLinux::ProcessReadQueue() {
+ DCHECK(thread_checker().CalledOnValidThread());
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());
+
+ if (read.buffer->size() < report.buffer->size()) {
+ read.callback.Run(false, 0);
+ pending_reads_.pop();
} else {
memcpy(read.buffer->data(), report.buffer->data(), report.buffer->size());
pending_reports_.pop();
- read.callback.Run(true, report.buffer->size());
+
+ if (CompleteRead(report.buffer, read.callback)) {
+ pending_reads_.pop();
+ }
}
}
}
« no previous file with comments | « trunk/src/device/hid/hid_connection_linux.h ('k') | trunk/src/device/hid/hid_connection_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698