wayland_watcher.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2018 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. #include "components/exo/wayland/wayland_watcher.h"
  5. #include "base/task/current_thread.h"
  6. #include "components/exo/wayland/server.h"
  7. namespace exo {
  8. namespace wayland {
  9. WaylandWatcher::WaylandWatcher(wayland::Server* server)
  10. : controller_(FROM_HERE), server_(server) {
  11. Start();
  12. }
  13. WaylandWatcher::~WaylandWatcher() {
  14. controller_.StopWatchingFileDescriptor();
  15. }
  16. void WaylandWatcher::StartForTesting() {
  17. Start();
  18. }
  19. void WaylandWatcher::StopForTesting() {
  20. controller_.StopWatchingFileDescriptor();
  21. }
  22. void WaylandWatcher::Start() {
  23. base::CurrentUIThread::Get()->WatchFileDescriptor(
  24. server_->GetFileDescriptor(),
  25. true, // persistent
  26. base::MessagePumpForUI::WATCH_READ, &controller_, this);
  27. }
  28. void WaylandWatcher::OnFileCanReadWithoutBlocking(int fd) {
  29. server_->Dispatch(base::TimeDelta());
  30. server_->Flush();
  31. }
  32. void WaylandWatcher::OnFileCanWriteWithoutBlocking(int fd) {
  33. NOTREACHED();
  34. }
  35. } // namespace wayland
  36. } // namespace exo