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