OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chrome_browser_main_extra_parts_exo.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/browser/ui/ash/ash_util.h" |
| 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "components/exo/display.h" |
| 12 #include "components/exo/wayland/server.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 14 |
| 15 class ChromeBrowserMainExtraPartsExo::WaylandWatcher |
| 16 : public base::MessagePumpLibevent::Watcher { |
| 17 public: |
| 18 explicit WaylandWatcher(exo::wayland::Server* server) : server_(server) { |
| 19 base::MessageLoopForUI::current()->WatchFileDescriptor( |
| 20 server_->GetFileDescriptor(), |
| 21 true, // persistent |
| 22 base::MessagePumpLibevent::WATCH_READ, &controller_, this); |
| 23 } |
| 24 |
| 25 // base::MessagePumpLibevent::Watcher: |
| 26 void OnFileCanReadWithoutBlocking(int fd) override { |
| 27 server_->Dispatch(base::TimeDelta()); |
| 28 server_->Flush(); |
| 29 } |
| 30 void OnFileCanWriteWithoutBlocking(int fd) override { NOTREACHED(); } |
| 31 |
| 32 private: |
| 33 base::MessagePumpLibevent::FileDescriptorWatcher controller_; |
| 34 exo::wayland::Server* const server_; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(WaylandWatcher); |
| 37 }; |
| 38 |
| 39 ChromeBrowserMainExtraPartsExo::ChromeBrowserMainExtraPartsExo() |
| 40 : display_(new exo::Display) {} |
| 41 |
| 42 ChromeBrowserMainExtraPartsExo::~ChromeBrowserMainExtraPartsExo() {} |
| 43 |
| 44 void ChromeBrowserMainExtraPartsExo::PreProfileInit() { |
| 45 if (!chrome::ShouldOpenAshOnStartup()) |
| 46 return; |
| 47 |
| 48 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 49 switches::kEnableWaylandServer)) { |
| 50 wayland_server_ = exo::wayland::Server::Create(display_.get()); |
| 51 wayland_watcher_ = |
| 52 make_scoped_ptr(new WaylandWatcher(wayland_server_.get())); |
| 53 } |
| 54 } |
| 55 |
| 56 void ChromeBrowserMainExtraPartsExo::PostMainMessageLoopRun() { |
| 57 wayland_watcher_.reset(); |
| 58 wayland_server_.reset(); |
| 59 } |
OLD | NEW |