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

Side by Side Diff: remoting/host/clipboard_x11.cc

Issue 14314026: remoting: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/client_session_unittest.cc ('k') | remoting/host/config_file_watcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/clipboard.h" 5 #include "remoting/host/clipboard.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "remoting/host/linux/x_server_clipboard.h" 12 #include "remoting/host/linux/x_server_clipboard.h"
13 #include "remoting/proto/event.pb.h" 13 #include "remoting/proto/event.pb.h"
14 #include "remoting/protocol/clipboard_stub.h" 14 #include "remoting/protocol/clipboard_stub.h"
15 15
16 namespace remoting { 16 namespace remoting {
17 17
18 // This code is expected to be called on the desktop thread only. 18 // This code is expected to be called on the desktop thread only.
19 class ClipboardX11 : public Clipboard, 19 class ClipboardX11 : public Clipboard,
20 public MessageLoopForIO::Watcher { 20 public base::MessageLoopForIO::Watcher {
21 public: 21 public:
22 ClipboardX11(); 22 ClipboardX11();
23 virtual ~ClipboardX11(); 23 virtual ~ClipboardX11();
24 24
25 // Clipboard interface. 25 // Clipboard interface.
26 virtual void Start( 26 virtual void Start(
27 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE; 27 scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE;
28 virtual void InjectClipboardEvent( 28 virtual void InjectClipboardEvent(
29 const protocol::ClipboardEvent& event) OVERRIDE; 29 const protocol::ClipboardEvent& event) OVERRIDE;
30 virtual void Stop() OVERRIDE; 30 virtual void Stop() OVERRIDE;
(...skipping 10 matching lines...) Expand all
41 scoped_ptr<protocol::ClipboardStub> client_clipboard_; 41 scoped_ptr<protocol::ClipboardStub> client_clipboard_;
42 42
43 // Underlying X11 clipboard implementation. 43 // Underlying X11 clipboard implementation.
44 XServerClipboard x_server_clipboard_; 44 XServerClipboard x_server_clipboard_;
45 45
46 // Connection to the X server, used by |x_server_clipboard_|. This is created 46 // Connection to the X server, used by |x_server_clipboard_|. This is created
47 // and owned by this class. 47 // and owned by this class.
48 Display* display_; 48 Display* display_;
49 49
50 // Watcher used to handle X11 events from |display_|. 50 // Watcher used to handle X11 events from |display_|.
51 MessageLoopForIO::FileDescriptorWatcher x_connection_watcher_; 51 base::MessageLoopForIO::FileDescriptorWatcher x_connection_watcher_;
52 52
53 DISALLOW_COPY_AND_ASSIGN(ClipboardX11); 53 DISALLOW_COPY_AND_ASSIGN(ClipboardX11);
54 }; 54 };
55 55
56 ClipboardX11::ClipboardX11() 56 ClipboardX11::ClipboardX11()
57 : display_(NULL) { 57 : display_(NULL) {
58 } 58 }
59 59
60 ClipboardX11::~ClipboardX11() { 60 ClipboardX11::~ClipboardX11() {
61 Stop(); 61 Stop();
62 } 62 }
63 63
64 void ClipboardX11::Start( 64 void ClipboardX11::Start(
65 scoped_ptr<protocol::ClipboardStub> client_clipboard) { 65 scoped_ptr<protocol::ClipboardStub> client_clipboard) {
66 // TODO(lambroslambrou): Share the X connection with InputInjector. 66 // TODO(lambroslambrou): Share the X connection with InputInjector.
67 display_ = XOpenDisplay(NULL); 67 display_ = XOpenDisplay(NULL);
68 if (!display_) { 68 if (!display_) {
69 LOG(ERROR) << "Couldn't open X display"; 69 LOG(ERROR) << "Couldn't open X display";
70 return; 70 return;
71 } 71 }
72 client_clipboard_.swap(client_clipboard); 72 client_clipboard_.swap(client_clipboard);
73 73
74 x_server_clipboard_.Init(display_, 74 x_server_clipboard_.Init(display_,
75 base::Bind(&ClipboardX11::OnClipboardChanged, 75 base::Bind(&ClipboardX11::OnClipboardChanged,
76 base::Unretained(this))); 76 base::Unretained(this)));
77 77
78 MessageLoopForIO::current()->WatchFileDescriptor( 78 base::MessageLoopForIO::current()->WatchFileDescriptor(
79 ConnectionNumber(display_), true, MessageLoopForIO::WATCH_READ, 79 ConnectionNumber(display_),
80 &x_connection_watcher_, this); 80 true,
81 base::MessageLoopForIO::WATCH_READ,
82 &x_connection_watcher_,
83 this);
81 PumpXEvents(); 84 PumpXEvents();
82 } 85 }
83 86
84 void ClipboardX11::InjectClipboardEvent( 87 void ClipboardX11::InjectClipboardEvent(
85 const protocol::ClipboardEvent& event) { 88 const protocol::ClipboardEvent& event) {
86 x_server_clipboard_.SetClipboard(event.mime_type(), event.data()); 89 x_server_clipboard_.SetClipboard(event.mime_type(), event.data());
87 } 90 }
88 91
89 void ClipboardX11::Stop() { 92 void ClipboardX11::Stop() {
90 client_clipboard_.reset(); 93 client_clipboard_.reset();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 XNextEvent(display_, &event); 125 XNextEvent(display_, &event);
123 x_server_clipboard_.ProcessXEvent(&event); 126 x_server_clipboard_.ProcessXEvent(&event);
124 } 127 }
125 } 128 }
126 129
127 scoped_ptr<Clipboard> Clipboard::Create() { 130 scoped_ptr<Clipboard> Clipboard::Create() {
128 return scoped_ptr<Clipboard>(new ClipboardX11()); 131 return scoped_ptr<Clipboard>(new ClipboardX11());
129 } 132 }
130 133
131 } // namespace remoting 134 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/client_session_unittest.cc ('k') | remoting/host/config_file_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698