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

Unified Diff: device/hid/hid_connection_linux.cc

Issue 2394343003: Use FileDescriptorWatcher in HidConnectionLinux::FileThreadHelper. (Closed)
Patch Set: fix build error Created 4 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/hid/hid_connection_linux.cc
diff --git a/device/hid/hid_connection_linux.cc b/device/hid/hid_connection_linux.cc
index 54a3624d7a396c20cc290ab3a604b34d662dd2f0..5172b0b39ea6a366c22af751e3d48ebf5b933734 100644
--- a/device/hid/hid_connection_linux.cc
+++ b/device/hid/hid_connection_linux.cc
@@ -13,10 +13,10 @@
#include <utility>
#include "base/bind.h"
+#include "base/files/file_descriptor_watcher_posix.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
-#include "base/message_loop/message_pump_libevent.h"
#include "base/posix/eintr_wrapper.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -34,8 +34,7 @@
namespace device {
class HidConnectionLinux::FileThreadHelper
- : public base::MessagePumpLibevent::Watcher,
- public base::MessageLoop::DestructionObserver {
+ : public base::MessageLoop::DestructionObserver {
public:
FileThreadHelper(base::PlatformFile platform_file,
scoped_refptr<HidDeviceInfo> device_info,
@@ -60,21 +59,18 @@ class HidConnectionLinux::FileThreadHelper
base::ThreadRestrictions::AssertIOAllowed();
self->thread_checker_.DetachFromThread();
- if (!base::MessageLoopForIO::current()->WatchFileDescriptor(
- self->platform_file_, true, base::MessageLoopForIO::WATCH_READ,
- &self->file_watcher_, self.get())) {
- HID_LOG(ERROR) << "Failed to start watching device file.";
- }
+ self->file_watcher_ = base::FileDescriptorWatcher::WatchReadable(
+ self->platform_file_,
+ base::Bind(&FileThreadHelper::OnFileCanReadWithoutBlocking,
+ base::Unretained(self.get())));
// |self| is now owned by the current message loop.
base::MessageLoop::current()->AddDestructionObserver(self.release());
}
private:
- // base::MessagePumpLibevent::Watcher implementation.
- void OnFileCanReadWithoutBlocking(int fd) override {
+ void OnFileCanReadWithoutBlocking() {
DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK_EQ(fd, platform_file_);
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(report_buffer_size_));
char* data = buffer->data();
@@ -95,7 +91,7 @@ class HidConnectionLinux::FileThreadHelper
// TODO(reillyg): Investigate starting and stopping the file descriptor
// watcher in response to pending read requests so that per-request
// errors can be returned to the client.
- file_watcher_.StopWatchingFileDescriptor();
+ file_watcher_.reset();
}
return;
}
@@ -109,10 +105,6 @@ class HidConnectionLinux::FileThreadHelper
connection_, buffer, bytes_read));
}
- void OnFileCanWriteWithoutBlocking(int fd) override {
- NOTREACHED(); // Only listening for reads.
- }
-
// base::MessageLoop::DestructionObserver:
void WillDestroyCurrentMessageLoop() override {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -125,7 +117,7 @@ class HidConnectionLinux::FileThreadHelper
bool has_report_id_;
base::WeakPtr<HidConnectionLinux> connection_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
- base::MessagePumpLibevent::FileDescriptorWatcher file_watcher_;
+ std::unique_ptr<base::FileDescriptorWatcher::Controller> file_watcher_;
DISALLOW_COPY_AND_ASSIGN(FileThreadHelper);
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698