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

Side by Side Diff: chrome/browser/chrome_browser_main_extra_parts_exo.cc

Issue 1499253002: Revert of chrome: Add support for use_glib=true to wayland server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « build/config/ui.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/chrome_browser_main_extra_parts_exo.h" 5 #include "chrome/browser/chrome_browser_main_extra_parts_exo.h"
6 6
7 #if defined(USE_GLIB)
8 #include <glib.h>
9 #endif
10
11 #include "base/command_line.h" 7 #include "base/command_line.h"
12 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
13 #include "chrome/browser/ui/ash/ash_util.h" 9 #include "chrome/browser/ui/ash/ash_util.h"
14 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
15 #include "components/exo/display.h" 11 #include "components/exo/display.h"
16 #include "components/exo/wayland/server.h" 12 #include "components/exo/wayland/server.h"
17 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
18 14
19 #if defined(USE_GLIB)
20 namespace {
21
22 gboolean WaylandSourcePrepare(GSource* source, gint* timeout_ms) {
23 *timeout_ms = -1;
24 return FALSE;
25 }
26
27 gboolean WaylandSourceCheck(GSource* source) {
28 return TRUE;
29 }
30
31 gboolean WaylandSourceDispatch(GSource* source,
32 GSourceFunc unused_func,
33 gpointer data) {
34 exo::wayland::Server* server = static_cast<exo::wayland::Server*>(data);
35 server->Dispatch(base::TimeDelta());
36 server->Flush();
37 return TRUE;
38 }
39
40 GSourceFuncs g_wayland_source_funcs = {WaylandSourcePrepare, WaylandSourceCheck,
41 WaylandSourceDispatch, nullptr};
42
43 } // namespace
44
45 class ChromeBrowserMainExtraPartsExo::WaylandWatcher {
46 public:
47 explicit WaylandWatcher(exo::wayland::Server* server)
48 : wayland_poll_(new GPollFD),
49 wayland_source_(
50 g_source_new(&g_wayland_source_funcs, sizeof(GSource))) {
51 wayland_poll_->fd = server->GetFileDescriptor();
52 wayland_poll_->events = G_IO_IN;
53 wayland_poll_->revents = 0;
54 g_source_add_poll(wayland_source_, wayland_poll_.get());
55 g_source_set_can_recurse(wayland_source_, TRUE);
56 g_source_set_callback(wayland_source_, nullptr, server, nullptr);
57 g_source_attach(wayland_source_, g_main_context_default());
58 }
59 ~WaylandWatcher() {
60 g_source_destroy(wayland_source_);
61 g_source_unref(wayland_source_);
62 }
63
64 private:
65 // The poll attached to |wayland_source_|.
66 scoped_ptr<GPollFD> wayland_poll_;
67
68 // The GLib event source for wayland events.
69 GSource* wayland_source_;
70
71 DISALLOW_COPY_AND_ASSIGN(WaylandWatcher);
72 };
73 #else
74 class ChromeBrowserMainExtraPartsExo::WaylandWatcher 15 class ChromeBrowserMainExtraPartsExo::WaylandWatcher
75 : public base::MessagePumpLibevent::Watcher { 16 : public base::MessagePumpLibevent::Watcher {
76 public: 17 public:
77 explicit WaylandWatcher(exo::wayland::Server* server) : server_(server) { 18 explicit WaylandWatcher(exo::wayland::Server* server) : server_(server) {
78 base::MessageLoopForUI::current()->WatchFileDescriptor( 19 base::MessageLoopForUI::current()->WatchFileDescriptor(
79 server_->GetFileDescriptor(), 20 server_->GetFileDescriptor(),
80 true, // persistent 21 true, // persistent
81 base::MessagePumpLibevent::WATCH_READ, &controller_, this); 22 base::MessagePumpLibevent::WATCH_READ, &controller_, this);
82 } 23 }
83 24
84 // base::MessagePumpLibevent::Watcher: 25 // base::MessagePumpLibevent::Watcher:
85 void OnFileCanReadWithoutBlocking(int fd) override { 26 void OnFileCanReadWithoutBlocking(int fd) override {
86 server_->Dispatch(base::TimeDelta()); 27 server_->Dispatch(base::TimeDelta());
87 server_->Flush(); 28 server_->Flush();
88 } 29 }
89 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } 30 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); }
90 31
91 private: 32 private:
92 base::MessagePumpLibevent::FileDescriptorWatcher controller_; 33 base::MessagePumpLibevent::FileDescriptorWatcher controller_;
93 exo::wayland::Server* const server_; 34 exo::wayland::Server* const server_;
94 35
95 DISALLOW_COPY_AND_ASSIGN(WaylandWatcher); 36 DISALLOW_COPY_AND_ASSIGN(WaylandWatcher);
96 }; 37 };
97 #endif
98 38
99 ChromeBrowserMainExtraPartsExo::ChromeBrowserMainExtraPartsExo() 39 ChromeBrowserMainExtraPartsExo::ChromeBrowserMainExtraPartsExo()
100 : display_(new exo::Display) {} 40 : display_(new exo::Display) {}
101 41
102 ChromeBrowserMainExtraPartsExo::~ChromeBrowserMainExtraPartsExo() {} 42 ChromeBrowserMainExtraPartsExo::~ChromeBrowserMainExtraPartsExo() {}
103 43
104 void ChromeBrowserMainExtraPartsExo::PreProfileInit() { 44 void ChromeBrowserMainExtraPartsExo::PreProfileInit() {
105 if (!chrome::ShouldOpenAshOnStartup()) 45 if (!chrome::ShouldOpenAshOnStartup())
106 return; 46 return;
107 47
108 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
109 switches::kEnableWaylandServer)) { 49 switches::kEnableWaylandServer)) {
110 wayland_server_ = exo::wayland::Server::Create(display_.get()); 50 wayland_server_ = exo::wayland::Server::Create(display_.get());
111 wayland_watcher_ = 51 wayland_watcher_ =
112 make_scoped_ptr(new WaylandWatcher(wayland_server_.get())); 52 make_scoped_ptr(new WaylandWatcher(wayland_server_.get()));
113 } 53 }
114 } 54 }
115 55
116 void ChromeBrowserMainExtraPartsExo::PostMainMessageLoopRun() { 56 void ChromeBrowserMainExtraPartsExo::PostMainMessageLoopRun() {
117 wayland_watcher_.reset(); 57 wayland_watcher_.reset();
118 wayland_server_.reset(); 58 wayland_server_.reset();
119 } 59 }
OLDNEW
« no previous file with comments | « build/config/ui.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698