ozone: Remove the libevent message-pump.

The ozone message-pump is no longer needed. So remove that, and use the default
message-pump based on libevent instead. Also, add a convenience method for
adding a watcher on a file-descriptor to the message-pump from the message-loop.

BUG=354062
R=rjkroege@chromium.org, sky@chromium.org
TBR=darin@chromium.org

Review URL: https://codereview.chromium.org/231643005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263022 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: ef1a61b3ca42b158068c27e722630d881eb5fa1e
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index 2315fd1..d4315c1 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -219,6 +219,9 @@
 // ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and
 // doesn't require extra support for watching file descriptors.
 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpDefault())
+#elif defined(USE_OZONE)
+#define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpLibevent())
+#define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpLibevent())
 #elif defined(OS_POSIX)  // POSIX but not MACOSX.
 #define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpForUI())
 #define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpLibevent())
@@ -666,7 +669,7 @@
 }
 #endif
 
-#if !defined(OS_NACL) && (defined(TOOLKIT_GTK) || defined(USE_OZONE) || \
+#if !defined(OS_NACL) && (defined(TOOLKIT_GTK) || \
                           defined(OS_WIN) || defined(USE_X11))
 void MessageLoopForUI::AddObserver(Observer* observer) {
   pump_ui()->AddObserver(observer);
@@ -677,6 +680,22 @@
 }
 #endif  //  !defined(OS_MACOSX) && !defined(OS_NACL) && !defined(OS_ANDROID)
 
+#if defined(USE_OZONE)
+bool MessageLoopForUI::WatchFileDescriptor(
+    int fd,
+    bool persistent,
+    MessagePumpLibevent::Mode mode,
+    MessagePumpLibevent::FileDescriptorWatcher *controller,
+    MessagePumpLibevent::Watcher *delegate) {
+  return pump_libevent()->WatchFileDescriptor(
+      fd,
+      persistent,
+      mode,
+      controller,
+      delegate);
+}
+#endif
+
 //------------------------------------------------------------------------------
 // MessageLoopForIO
 
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
index e52963f..7222df7 100644
--- a/base/message_loop/message_loop.h
+++ b/base/message_loop/message_loop.h
@@ -36,8 +36,6 @@
 
 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL)
 #include "base/message_loop/message_pump_x11.h"
-#elif defined(USE_OZONE) && !defined(OS_NACL)
-#include "base/message_loop/message_pump_ozone.h"
 #elif !defined(OS_ANDROID_HOST)
 #define USE_GTK_MESSAGE_PUMP
 #include "base/message_loop/message_pump_gtk.h"
@@ -579,7 +577,7 @@
   void Start();
 #endif
 
-#if !defined(OS_NACL) && (defined(TOOLKIT_GTK) || defined(USE_OZONE) || \
+#if !defined(OS_NACL) && (defined(TOOLKIT_GTK) || \
                           defined(OS_WIN) || defined(USE_X11))
   // Please see message_pump_win/message_pump_glib for definitions of these
   // methods.
@@ -587,13 +585,20 @@
   void RemoveObserver(Observer* observer);
 #endif
 
+#if defined(USE_OZONE)
+  // Please see MessagePumpLibevent for definition.
+  bool WatchFileDescriptor(
+      int fd,
+      bool persistent,
+      MessagePumpLibevent::Mode mode,
+      MessagePumpLibevent::FileDescriptorWatcher* controller,
+      MessagePumpLibevent::Watcher* delegate);
+#endif
+
  protected:
 #if defined(USE_X11)
   friend class MessagePumpX11;
 #endif
-#if defined(USE_OZONE) && !defined(OS_NACL)
-  friend class MessagePumpOzone;
-#endif
 
 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
   // TODO(rvargas): Make this platform independent.
diff --git a/base/message_loop/message_pump_ozone.cc b/base/message_loop/message_pump_ozone.cc
deleted file mode 100644
index b262291..0000000
--- a/base/message_loop/message_pump_ozone.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/message_loop/message_pump_ozone.h"
-
-#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-
-namespace base {
-
-MessagePumpOzone::MessagePumpOzone()
-    : MessagePumpLibevent() {
-}
-
-MessagePumpOzone::~MessagePumpOzone() {
-}
-
-void MessagePumpOzone::AddObserver(MessagePumpObserver* /* observer */) {
-  NOTIMPLEMENTED();
-}
-
-void MessagePumpOzone::RemoveObserver(MessagePumpObserver* /* observer */) {
-  NOTIMPLEMENTED();
-}
-
-// static
-MessagePumpOzone* MessagePumpOzone::Current() {
-  MessageLoopForUI* loop = MessageLoopForUI::current();
-  return static_cast<MessagePumpOzone*>(loop->pump_ui());
-}
-
-void MessagePumpOzone::AddDispatcherForRootWindow(
-    MessagePumpDispatcher* dispatcher) {
-  // Only one root window is supported.
-  DCHECK(dispatcher_.size() == 0);
-  dispatcher_.insert(dispatcher_.begin(),dispatcher);
-}
-
-void MessagePumpOzone::RemoveDispatcherForRootWindow(
-      MessagePumpDispatcher* dispatcher) {
-  DCHECK(dispatcher_.size() == 1);
-  dispatcher_.pop_back();
-}
-
-uint32_t MessagePumpOzone::Dispatch(const NativeEvent& dev) {
-  if (dispatcher_.size() > 0)
-    return dispatcher_[0]->Dispatch(dev);
-  return POST_DISPATCH_NONE;
-}
-
-// This code assumes that the caller tracks the lifetime of the |dispatcher|.
-void MessagePumpOzone::RunWithDispatcher(
-    Delegate* delegate, MessagePumpDispatcher* dispatcher) {
-  dispatcher_.push_back(dispatcher);
-  Run(delegate);
-  dispatcher_.pop_back();
-}
-
-}  // namespace base
diff --git a/base/message_loop/message_pump_ozone.h b/base/message_loop/message_pump_ozone.h
deleted file mode 100644
index 30db9df..0000000
--- a/base/message_loop/message_pump_ozone.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_OZONE_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_OZONE_H_
-
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
-#include "base/message_loop/message_pump_dispatcher.h"
-#include "base/message_loop/message_pump_libevent.h"
-#include "base/message_loop/message_pump_observer.h"
-#include "base/observer_list.h"
-
-namespace base {
-
-// This class implements a message-pump for processing events from input devices
-// Refer to MessagePump for further documentation.
-class BASE_EXPORT MessagePumpOzone : public MessagePumpLibevent,
-                                     public MessagePumpDispatcher {
- public:
-  MessagePumpOzone();
-  virtual ~MessagePumpOzone();
-
-  // Returns the UI message pump.
-  static MessagePumpOzone* Current();
-
-  // Add/Remove the root window dispatcher.
-  void AddDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
-  void RemoveDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
-
-  void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher);
-
-  // Add / remove an Observer, which will start receiving notifications
-  // immediately.
-  void AddObserver(MessagePumpObserver* observer);
-  void RemoveObserver(MessagePumpObserver* observer);
-
-  // Overridden from MessagePumpDispatcher.
-  virtual uint32_t Dispatch(const NativeEvent& event) OVERRIDE;
-
- private:
-  std::vector<MessagePumpDispatcher*> dispatcher_;
-
-  DISALLOW_COPY_AND_ASSIGN(MessagePumpOzone);
-};
-
-typedef MessagePumpOzone MessagePumpForUI;
-
-}  // namespace base
-
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_OZONE_H_