Use FileDescriptorWatcher in ClipboardX11.
This allows ClipboardX11 to be used from any thread that
instantiates a FileDescriptorWatcher (not just threads that run
a MessageLoopForIO). This will facilitate the migration of
BrowserThreads to base/task_scheduler.
BUG=645114
Review-Url: https://codereview.chromium.org/2382723007
Cr-Commit-Position: refs/heads/master@{#422448}
diff --git a/remoting/host/clipboard_x11.cc b/remoting/host/clipboard_x11.cc
index ec9b93e..cd03acc 100644
--- a/remoting/host/clipboard_x11.cc
+++ b/remoting/host/clipboard_x11.cc
@@ -10,9 +10,9 @@
#undef Status // Xlib.h #defines this, which breaks protobuf headers.
#include "base/bind.h"
+#include "base/files/file_descriptor_watcher_posix.h"
#include "base/logging.h"
#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
#include "remoting/host/linux/x_server_clipboard.h"
#include "remoting/proto/event.pb.h"
#include "remoting/protocol/clipboard_stub.h"
@@ -20,8 +20,7 @@
namespace remoting {
// This code is expected to be called on the desktop thread only.
-class ClipboardX11 : public Clipboard,
- public base::MessageLoopForIO::Watcher {
+class ClipboardX11 : public Clipboard {
public:
ClipboardX11();
~ClipboardX11() override;
@@ -31,10 +30,6 @@
std::unique_ptr<protocol::ClipboardStub> client_clipboard) override;
void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
- // MessageLoopForIO::Watcher interface.
- void OnFileCanReadWithoutBlocking(int fd) override;
- void OnFileCanWriteWithoutBlocking(int fd) override;
-
private:
void OnClipboardChanged(const std::string& mime_type,
const std::string& data);
@@ -50,7 +45,8 @@
Display* display_;
// Watcher used to handle X11 events from |display_|.
- base::MessageLoopForIO::FileDescriptorWatcher x_connection_watcher_;
+ std::unique_ptr<base::FileDescriptorWatcher::Controller>
+ x_connection_watch_controller_;
DISALLOW_COPY_AND_ASSIGN(ClipboardX11);
};
@@ -67,6 +63,7 @@
void ClipboardX11::Start(
std::unique_ptr<protocol::ClipboardStub> client_clipboard) {
// TODO(lambroslambrou): Share the X connection with InputInjector.
+ DCHECK(!display_);
display_ = XOpenDisplay(nullptr);
if (!display_) {
LOG(ERROR) << "Couldn't open X display";
@@ -78,12 +75,9 @@
base::Bind(&ClipboardX11::OnClipboardChanged,
base::Unretained(this)));
- base::MessageLoopForIO::current()->WatchFileDescriptor(
+ x_connection_watch_controller_ = base::FileDescriptorWatcher::WatchReadable(
ConnectionNumber(display_),
- true,
- base::MessageLoopForIO::WATCH_READ,
- &x_connection_watcher_,
- this);
+ base::Bind(&ClipboardX11::PumpXEvents, base::Unretained(this)));
PumpXEvents();
}
@@ -92,13 +86,6 @@
x_server_clipboard_.SetClipboard(event.mime_type(), event.data());
}
-void ClipboardX11::OnFileCanReadWithoutBlocking(int fd) {
- PumpXEvents();
-}
-
-void ClipboardX11::OnFileCanWriteWithoutBlocking(int fd) {
-}
-
void ClipboardX11::OnClipboardChanged(const std::string& mime_type,
const std::string& data) {
protocol::ClipboardEvent event;