diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-13 19:27:51 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-13 19:27:51 +0000 |
commit | ab9fe0f8b3127a8cc224322107d2f77fe0a9ef38 (patch) | |
tree | 40a0f93e46235dcb04514e4fbee65c874ddf6b71 | |
parent | 32354b64deff166de178809850f379da837819eb (diff) | |
download | chromium_src-ab9fe0f8b3127a8cc224322107d2f77fe0a9ef38.zip chromium_src-ab9fe0f8b3127a8cc224322107d2f77fe0a9ef38.tar.gz chromium_src-ab9fe0f8b3127a8cc224322107d2f77fe0a9ef38.tar.bz2 |
Revert r114168 "Refactor MessagePumpX to dispatch events inside of the source Dispatch function."
This reverts commit bae6675d851184f2be0ac117c1a847289c1c7bd9.
TBR=piman@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8931009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114245 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/message_loop.cc | 11 | ||||
-rw-r--r-- | base/message_pump_glib.cc | 2 | ||||
-rw-r--r-- | base/message_pump_glib.h | 5 | ||||
-rw-r--r-- | base/message_pump_gtk.cc | 5 | ||||
-rw-r--r-- | base/message_pump_gtk.h | 3 | ||||
-rw-r--r-- | base/message_pump_wayland.cc | 24 | ||||
-rw-r--r-- | base/message_pump_wayland.h | 22 | ||||
-rw-r--r-- | base/message_pump_x.cc | 20 | ||||
-rw-r--r-- | base/message_pump_x.h | 7 |
10 files changed, 85 insertions, 15 deletions
diff --git a/base/base.gypi b/base/base.gypi index 9251dd9..4c126ce 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -739,6 +739,7 @@ 'message_pump_libevent.h', 'message_pump_mac.h', 'message_pump_mac.mm', + 'message_pump_wayland.cc', 'message_pump_wayland.h', 'metrics/field_trial.cc', 'metrics/field_trial.h', diff --git a/base/message_loop.cc b/base/message_loop.cc index c7efe32..ca85d6a 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -147,13 +147,22 @@ MessageLoop::MessageLoop(Type type) #elif defined(OS_MACOSX) #define MESSAGE_PUMP_UI base::MessagePumpMac::Create() #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() +#elif defined(OS_ANDROID) +#define MESSAGE_PUMP_UI new base::MessagePumpForUI() +#define MESSAGE_PUMP_IO new base::MessagePumpLibevent() +#elif defined(USE_WAYLAND) +#define MESSAGE_PUMP_UI new base::MessagePumpWayland() +#define MESSAGE_PUMP_IO new base::MessagePumpLibevent() +#elif defined(USE_AURA) +#define MESSAGE_PUMP_UI new base::MessagePumpX() +#define MESSAGE_PUMP_IO new base::MessagePumpLibevent() #elif defined(OS_NACL) // Currently NaCl doesn't have a UI or an IO MessageLoop. // TODO(abarth): Figure out if we need these. #define MESSAGE_PUMP_UI NULL #define MESSAGE_PUMP_IO NULL #elif defined(OS_POSIX) // POSIX but not MACOSX. -#define MESSAGE_PUMP_UI new base::MessagePumpForUI() +#define MESSAGE_PUMP_UI new base::MessagePumpGtk() #define MESSAGE_PUMP_IO new base::MessagePumpLibevent() #else #error Not implemented diff --git a/base/message_pump_glib.cc b/base/message_pump_glib.cc index 85fee9a..19a0eea 100644 --- a/base/message_pump_glib.cc +++ b/base/message_pump_glib.cc @@ -206,7 +206,7 @@ void MessagePumpGlib::RunWithDispatcher(Delegate* delegate, // Don't block if we think we have more work to do. bool block = !more_work_is_plausible; - more_work_is_plausible = g_main_context_iteration(context_, block); + more_work_is_plausible = RunOnce(context_, block); if (state_->should_quit) break; diff --git a/base/message_pump_glib.h b/base/message_pump_glib.h index f2b6616..872b031 100644 --- a/base/message_pump_glib.h +++ b/base/message_pump_glib.h @@ -41,6 +41,11 @@ class MessagePumpGlib : public MessagePump { virtual void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); + // Run a single iteration of the mainloop. A return value of true indicates + // that an event was handled. |block| indicates if it should wait if no event + // is ready for processing. + virtual bool RunOnce(GMainContext* context, bool block) = 0; + // Internal methods used for processing the pump callbacks. They are // public for simplicity but should not be used directly. HandlePrepare // is called during the prepare step of glib, and returns a timeout that diff --git a/base/message_pump_gtk.cc b/base/message_pump_gtk.cc index 2c526ca..4f4f981 100644 --- a/base/message_pump_gtk.cc +++ b/base/message_pump_gtk.cc @@ -91,6 +91,11 @@ Display* MessagePumpGtk::GetDefaultXDisplay() { return display ? GDK_DISPLAY_XDISPLAY(display) : NULL; } +bool MessagePumpGtk::RunOnce(GMainContext* context, bool block) { + // g_main_context_iteration returns true if events have been dispatched. + return g_main_context_iteration(context, block); +} + void MessagePumpGtk::WillProcessEvent(GdkEvent* event) { FOR_EACH_OBSERVER(MessagePumpObserver, observers(), WillProcessEvent(event)); } diff --git a/base/message_pump_gtk.h b/base/message_pump_gtk.h index ea1630f0..80122ce 100644 --- a/base/message_pump_gtk.h +++ b/base/message_pump_gtk.h @@ -54,6 +54,9 @@ class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib { static Display* GetDefaultXDisplay(); private: + // Overridden from MessagePumpGlib + virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE; + // Invoked from EventDispatcher. Notifies all observers we're about to // process an event. void WillProcessEvent(GdkEvent* event); diff --git a/base/message_pump_wayland.cc b/base/message_pump_wayland.cc new file mode 100644 index 0000000..4d64c62 --- /dev/null +++ b/base/message_pump_wayland.cc @@ -0,0 +1,24 @@ +// Copyright (c) 2011 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_pump_wayland.h" + +#include <glib.h> + +namespace base { + +MessagePumpWayland::MessagePumpWayland() + : MessagePumpGlib(), + context_(g_main_context_default()) { +} + +MessagePumpWayland::~MessagePumpWayland() { +} + +bool MessagePumpWayland::RunOnce(GMainContext* context, bool block) { + // g_main_context_iteration returns true if events have been dispatched. + return g_main_context_iteration(context, block); +} + +} // namespace base diff --git a/base/message_pump_wayland.h b/base/message_pump_wayland.h index 89c9b8f..706914a 100644 --- a/base/message_pump_wayland.h +++ b/base/message_pump_wayland.h @@ -10,6 +10,10 @@ #include "base/message_pump_glib.h" #include "base/message_pump_observer.h" +typedef struct _GMainContext GMainContext; +typedef struct _GPollFD GPollFD; +typedef struct _GSource GSource; + namespace base { namespace wayland { @@ -37,7 +41,23 @@ class MessagePumpDispatcher { virtual ~MessagePumpDispatcher() {} }; -typedef MessagePumpGlib MessagePumpForUI; +class BASE_EXPORT MessagePumpWayland : public MessagePumpGlib { + + public: + MessagePumpWayland(); + virtual ~MessagePumpWayland(); + + // Overridden from MessagePumpGlib + virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE; + private: + + // This is a GLib structure that we can add event sources to. + GMainContext* context_; + + DISALLOW_COPY_AND_ASSIGN(MessagePumpWayland); +}; + +typedef MessagePumpWayland MessagePumpForUI; } // namespace base diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc index 2ef34ef..13adb37 100644 --- a/base/message_pump_x.cc +++ b/base/message_pump_x.cc @@ -25,9 +25,11 @@ gboolean XSourceCheck(GSource* source) { gboolean XSourceDispatch(GSource* source, GSourceFunc unused_func, - gpointer data) { - base::MessagePumpX* pump = static_cast<base::MessagePumpX*>(data); - return pump->DispatchXEvents(); + gpointer unused_data) { + // TODO(sad): When GTK event proecssing is completely removed, the event + // processing and dispatching should be done here (i.e. XNextEvent, + // ProcessXEvent etc.) + return TRUE; } GSourceFuncs XSourceFuncs = { @@ -127,7 +129,6 @@ void MessagePumpX::InitXSource() { x_source_ = g_source_new(&XSourceFuncs, sizeof(GSource)); g_source_add_poll(x_source_, x_poll); g_source_set_can_recurse(x_source_, FALSE); - g_source_set_callback(x_source_, NULL, this, NULL); g_source_attach(x_source_, g_main_context_default()); } @@ -161,21 +162,24 @@ bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher, return should_quit; } -gboolean MessagePumpX::DispatchXEvents() { +bool MessagePumpX::RunOnce(GMainContext* context, bool block) { Display* display = GetDefaultXDisplay(); - DCHECK(display); MessagePumpDispatcher* dispatcher = GetDispatcher() ? GetDispatcher() : g_default_dispatcher; + if (!display) + return g_main_context_iteration(context, block); + // In the general case, we want to handle all pending events before running // the tasks. This is what happens in the message_pump_glib case. while (XPending(display)) { XEvent xev; XNextEvent(display, &xev); if (dispatcher && ProcessXEvent(dispatcher, &xev)) - return TRUE; + return true; } - return TRUE; + + return g_main_context_iteration(context, block); } bool MessagePumpX::WillProcessXEvent(XEvent* xevent) { diff --git a/base/message_pump_x.h b/base/message_pump_x.h index 62597a2..e6bb71c 100644 --- a/base/message_pump_x.h +++ b/base/message_pump_x.h @@ -45,6 +45,9 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { MessagePumpX(); virtual ~MessagePumpX(); + // Overridden from MessagePumpGlib: + virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE; + // Returns default X Display. static Display* GetDefaultXDisplay(); @@ -54,10 +57,6 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { // Sets the default dispatcher to process native events. static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher); - // Internal function. Called by the glib source dispatch function. Processes - // all available X events. - gboolean DispatchXEvents(); - private: // Initializes the glib event source for X. void InitXSource(); |