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

Unified Diff: remoting/host/clipboard_linux.cc

Issue 10909133: Implement clipboard for Chromoting Linux hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use desktop thread for clipboard Created 8 years, 3 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
Index: remoting/host/clipboard_linux.cc
diff --git a/remoting/host/clipboard_linux.cc b/remoting/host/clipboard_linux.cc
index 6a1729167fccf9aeea4617c719d28d037e3290a2..f69641b57a70901416e80d12503d112020df3331 100644
--- a/remoting/host/clipboard_linux.cc
+++ b/remoting/host/clipboard_linux.cc
@@ -4,15 +4,23 @@
#include "remoting/host/clipboard.h"
+#include <X11/Xlib.h>
+
+#include "base/bind.h"
#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/message_pump_libevent.h"
Sergey Ulanov 2012/09/14 19:35:01 don't need this include. See my comment below.
Lambros 2012/09/14 21:35:13 Done.
+#include "remoting/host/x_server_clipboard.h"
+#include "remoting/proto/event.pb.h"
+#include "remoting/protocol/clipboard_stub.h"
namespace remoting {
-class ClipboardLinux : public Clipboard {
+class ClipboardLinux : public Clipboard, base::MessagePumpLibevent::Watcher {
Sergey Ulanov 2012/09/14 19:35:01 It's better to use MessageLoopForIO::Watcher here.
Sergey Ulanov 2012/09/14 19:35:01 Add comment to exmplain that we expect this code t
Lambros 2012/09/14 21:35:13 Done.
Lambros 2012/09/14 21:35:13 Done.
public:
ClipboardLinux();
+ virtual ~ClipboardLinux();
- // Must be called on the UI thread.
virtual void Start(
Sergey Ulanov 2012/09/14 19:35:01 // Clipboard interface.
Lambros 2012/09/14 21:35:13 Done.
scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE;
virtual void InjectClipboardEvent(
@@ -20,21 +28,91 @@ class ClipboardLinux : public Clipboard {
virtual void Stop() OVERRIDE;
private:
+ void OnClipboardChanged(const std::string& mime_type,
+ const std::string& data);
+ void PumpEvents();
+
+ // base::MessagePumpLibevent::Watcher interface
Sergey Ulanov 2012/09/14 19:35:01 nit: period at the end of the comment. MessageLoop
Lambros 2012/09/14 21:35:13 Done.
+ virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
Sergey Ulanov 2012/09/14 19:35:01 Per style guide interface implementation must alwa
Lambros 2012/09/14 21:35:13 Done.
Lambros 2012/09/14 21:35:13 Done (and moved the implementations so they match
+ virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
+
+ scoped_ptr<protocol::ClipboardStub> client_clipboard_;
+
+ XServerClipboard x_server_clipboard_;
+ Display* display_;
+
+ base::MessagePumpLibevent::FileDescriptorWatcher x_connection_watcher_;
+
DISALLOW_COPY_AND_ASSIGN(ClipboardLinux);
};
+ClipboardLinux::ClipboardLinux() : display_(NULL) {
Sergey Ulanov 2012/09/14 19:35:01 nit: better to place initializer on a separate lin
Lambros 2012/09/14 21:35:13 Done.
+}
+
+ClipboardLinux::~ClipboardLinux() {
+ Stop();
+}
+
void ClipboardLinux::Start(
scoped_ptr<protocol::ClipboardStub> client_clipboard) {
- NOTIMPLEMENTED();
+ display_ = XOpenDisplay(NULL);
Sergey Ulanov 2012/09/14 19:35:01 Please add TODO to share X connection with the eve
Lambros 2012/09/14 21:35:13 Done.
+ if (!display_) {
+ LOG(ERROR) << "Couldn't open X display";
+ return;
+ }
+ client_clipboard_.swap(client_clipboard);
+
+ x_server_clipboard_.Init(display_,
+ base::Bind(&ClipboardLinux::OnClipboardChanged,
+ base::Unretained(this)));
+
+ MessageLoopForIO::current()->WatchFileDescriptor(
+ ConnectionNumber(display_), true, MessageLoopForIO::WATCH_READ,
+ &x_connection_watcher_, this);
+ PumpEvents();
}
void ClipboardLinux::InjectClipboardEvent(
const protocol::ClipboardEvent& event) {
- NOTIMPLEMENTED();
+ x_server_clipboard_.SetClipboard(event.mime_type(), event.data());
}
void ClipboardLinux::Stop() {
- NOTIMPLEMENTED();
+ client_clipboard_.reset();
+ x_connection_watcher_.StopWatchingFileDescriptor();
+
+ if (display_) {
+ XCloseDisplay(display_);
+ display_ = NULL;
+ }
+}
+
+void ClipboardLinux::OnClipboardChanged(const std::string& mime_type,
+ const std::string& data) {
+ protocol::ClipboardEvent event;
+ event.set_mime_type(mime_type);
+ event.set_data(data);
+
+ if (client_clipboard_.get()) {
+ client_clipboard_->InjectClipboardEvent(event);
+ }
+}
+
+void ClipboardLinux::PumpEvents() {
+ DCHECK(display_);
+
+ while (XPending(display_)) {
+ XEvent event;
+ XNextEvent(display_, &event);
+ x_server_clipboard_.ProcessXEvent(&event);
+ }
+}
+
+void ClipboardLinux::OnFileCanReadWithoutBlocking(int fd) {
+ PumpEvents();
+}
+
+void ClipboardLinux::OnFileCanWriteWithoutBlocking(int fd) {
}
scoped_ptr<Clipboard> Clipboard::Create() {

Powered by Google App Engine
This is Rietveld 408576698