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

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

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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
« no previous file with comments | « remoting/host/clipboard_win.cc ('k') | remoting/host/config_file_watcher.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
9 #include "base/memory/ptr_util.h"
8 #undef Status // Xlib.h #defines this, which breaks protobuf headers. 10 #undef Status // Xlib.h #defines this, which breaks protobuf headers.
9 11
10 #include "base/bind.h" 12 #include "base/bind.h"
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
14 #include "remoting/host/linux/x_server_clipboard.h" 16 #include "remoting/host/linux/x_server_clipboard.h"
15 #include "remoting/proto/event.pb.h" 17 #include "remoting/proto/event.pb.h"
16 #include "remoting/protocol/clipboard_stub.h" 18 #include "remoting/protocol/clipboard_stub.h"
17 19
18 namespace remoting { 20 namespace remoting {
19 21
20 // This code is expected to be called on the desktop thread only. 22 // This code is expected to be called on the desktop thread only.
21 class ClipboardX11 : public Clipboard, 23 class ClipboardX11 : public Clipboard,
22 public base::MessageLoopForIO::Watcher { 24 public base::MessageLoopForIO::Watcher {
23 public: 25 public:
24 ClipboardX11(); 26 ClipboardX11();
25 ~ClipboardX11() override; 27 ~ClipboardX11() override;
26 28
27 // Clipboard interface. 29 // Clipboard interface.
28 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard) override; 30 void Start(
31 std::unique_ptr<protocol::ClipboardStub> client_clipboard) override;
29 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; 32 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
30 33
31 // MessageLoopForIO::Watcher interface. 34 // MessageLoopForIO::Watcher interface.
32 void OnFileCanReadWithoutBlocking(int fd) override; 35 void OnFileCanReadWithoutBlocking(int fd) override;
33 void OnFileCanWriteWithoutBlocking(int fd) override; 36 void OnFileCanWriteWithoutBlocking(int fd) override;
34 37
35 private: 38 private:
36 void OnClipboardChanged(const std::string& mime_type, 39 void OnClipboardChanged(const std::string& mime_type,
37 const std::string& data); 40 const std::string& data);
38 void PumpXEvents(); 41 void PumpXEvents();
39 42
40 scoped_ptr<protocol::ClipboardStub> client_clipboard_; 43 std::unique_ptr<protocol::ClipboardStub> client_clipboard_;
41 44
42 // Underlying X11 clipboard implementation. 45 // Underlying X11 clipboard implementation.
43 XServerClipboard x_server_clipboard_; 46 XServerClipboard x_server_clipboard_;
44 47
45 // Connection to the X server, used by |x_server_clipboard_|. This is created 48 // Connection to the X server, used by |x_server_clipboard_|. This is created
46 // and owned by this class. 49 // and owned by this class.
47 Display* display_; 50 Display* display_;
48 51
49 // Watcher used to handle X11 events from |display_|. 52 // Watcher used to handle X11 events from |display_|.
50 base::MessageLoopForIO::FileDescriptorWatcher x_connection_watcher_; 53 base::MessageLoopForIO::FileDescriptorWatcher x_connection_watcher_;
51 54
52 DISALLOW_COPY_AND_ASSIGN(ClipboardX11); 55 DISALLOW_COPY_AND_ASSIGN(ClipboardX11);
53 }; 56 };
54 57
55 ClipboardX11::ClipboardX11() 58 ClipboardX11::ClipboardX11()
56 : display_(nullptr) { 59 : display_(nullptr) {
57 } 60 }
58 61
59 ClipboardX11::~ClipboardX11() { 62 ClipboardX11::~ClipboardX11() {
60 if (display_) 63 if (display_)
61 XCloseDisplay(display_); 64 XCloseDisplay(display_);
62 } 65 }
63 66
64 void ClipboardX11::Start( 67 void ClipboardX11::Start(
65 scoped_ptr<protocol::ClipboardStub> client_clipboard) { 68 std::unique_ptr<protocol::ClipboardStub> client_clipboard) {
66 // TODO(lambroslambrou): Share the X connection with InputInjector. 69 // TODO(lambroslambrou): Share the X connection with InputInjector.
67 display_ = XOpenDisplay(nullptr); 70 display_ = XOpenDisplay(nullptr);
68 if (!display_) { 71 if (!display_) {
69 LOG(ERROR) << "Couldn't open X display"; 72 LOG(ERROR) << "Couldn't open X display";
70 return; 73 return;
71 } 74 }
72 client_clipboard_.swap(client_clipboard); 75 client_clipboard_.swap(client_clipboard);
73 76
74 x_server_clipboard_.Init(display_, 77 x_server_clipboard_.Init(display_,
75 base::Bind(&ClipboardX11::OnClipboardChanged, 78 base::Bind(&ClipboardX11::OnClipboardChanged,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 void ClipboardX11::PumpXEvents() { 113 void ClipboardX11::PumpXEvents() {
111 DCHECK(display_); 114 DCHECK(display_);
112 115
113 while (XPending(display_)) { 116 while (XPending(display_)) {
114 XEvent event; 117 XEvent event;
115 XNextEvent(display_, &event); 118 XNextEvent(display_, &event);
116 x_server_clipboard_.ProcessXEvent(&event); 119 x_server_clipboard_.ProcessXEvent(&event);
117 } 120 }
118 } 121 }
119 122
120 scoped_ptr<Clipboard> Clipboard::Create() { 123 std::unique_ptr<Clipboard> Clipboard::Create() {
121 return make_scoped_ptr(new ClipboardX11()); 124 return base::WrapUnique(new ClipboardX11());
122 } 125 }
123 126
124 } // namespace remoting 127 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/clipboard_win.cc ('k') | remoting/host/config_file_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698