Commit bae6675d authored by piman@chromium.org's avatar piman@chromium.org

Refactor MessagePumpX to dispatch events inside of the source Dispatch function.

Also clean up MessagePumpGlib.

BUG=None
TEST=None


Review URL: http://codereview.chromium.org/8872055

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114168 0039d316-1c4b-4281-b951-d872f2087c98
parent 68612780
...@@ -739,7 +739,6 @@ ...@@ -739,7 +739,6 @@
'message_pump_libevent.h', 'message_pump_libevent.h',
'message_pump_mac.h', 'message_pump_mac.h',
'message_pump_mac.mm', 'message_pump_mac.mm',
'message_pump_wayland.cc',
'message_pump_wayland.h', 'message_pump_wayland.h',
'metrics/field_trial.cc', 'metrics/field_trial.cc',
'metrics/field_trial.h', 'metrics/field_trial.h',
......
...@@ -147,22 +147,13 @@ MessageLoop::MessageLoop(Type type) ...@@ -147,22 +147,13 @@ MessageLoop::MessageLoop(Type type)
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
#define MESSAGE_PUMP_UI base::MessagePumpMac::Create() #define MESSAGE_PUMP_UI base::MessagePumpMac::Create()
#define MESSAGE_PUMP_IO new base::MessagePumpLibevent() #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) #elif defined(OS_NACL)
// Currently NaCl doesn't have a UI or an IO MessageLoop. // Currently NaCl doesn't have a UI or an IO MessageLoop.
// TODO(abarth): Figure out if we need these. // TODO(abarth): Figure out if we need these.
#define MESSAGE_PUMP_UI NULL #define MESSAGE_PUMP_UI NULL
#define MESSAGE_PUMP_IO NULL #define MESSAGE_PUMP_IO NULL
#elif defined(OS_POSIX) // POSIX but not MACOSX. #elif defined(OS_POSIX) // POSIX but not MACOSX.
#define MESSAGE_PUMP_UI new base::MessagePumpGtk() #define MESSAGE_PUMP_UI new base::MessagePumpForUI()
#define MESSAGE_PUMP_IO new base::MessagePumpLibevent() #define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
#else #else
#error Not implemented #error Not implemented
......
...@@ -206,7 +206,7 @@ void MessagePumpGlib::RunWithDispatcher(Delegate* delegate, ...@@ -206,7 +206,7 @@ void MessagePumpGlib::RunWithDispatcher(Delegate* delegate,
// Don't block if we think we have more work to do. // Don't block if we think we have more work to do.
bool block = !more_work_is_plausible; bool block = !more_work_is_plausible;
more_work_is_plausible = RunOnce(context_, block); more_work_is_plausible = g_main_context_iteration(context_, block);
if (state_->should_quit) if (state_->should_quit)
break; break;
......
...@@ -41,11 +41,6 @@ class MessagePumpGlib : public MessagePump { ...@@ -41,11 +41,6 @@ class MessagePumpGlib : public MessagePump {
virtual void RunWithDispatcher(Delegate* delegate, virtual void RunWithDispatcher(Delegate* delegate,
MessagePumpDispatcher* dispatcher); 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 // Internal methods used for processing the pump callbacks. They are
// public for simplicity but should not be used directly. HandlePrepare // public for simplicity but should not be used directly. HandlePrepare
// is called during the prepare step of glib, and returns a timeout that // is called during the prepare step of glib, and returns a timeout that
......
...@@ -91,11 +91,6 @@ Display* MessagePumpGtk::GetDefaultXDisplay() { ...@@ -91,11 +91,6 @@ Display* MessagePumpGtk::GetDefaultXDisplay() {
return display ? GDK_DISPLAY_XDISPLAY(display) : NULL; 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) { void MessagePumpGtk::WillProcessEvent(GdkEvent* event) {
FOR_EACH_OBSERVER(MessagePumpObserver, observers(), WillProcessEvent(event)); FOR_EACH_OBSERVER(MessagePumpObserver, observers(), WillProcessEvent(event));
} }
......
...@@ -54,9 +54,6 @@ class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib { ...@@ -54,9 +54,6 @@ class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
static Display* GetDefaultXDisplay(); static Display* GetDefaultXDisplay();
private: private:
// Overridden from MessagePumpGlib
virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;
// Invoked from EventDispatcher. Notifies all observers we're about to // Invoked from EventDispatcher. Notifies all observers we're about to
// process an event. // process an event.
void WillProcessEvent(GdkEvent* event); void WillProcessEvent(GdkEvent* event);
......
// 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
...@@ -10,10 +10,6 @@ ...@@ -10,10 +10,6 @@
#include "base/message_pump_glib.h" #include "base/message_pump_glib.h"
#include "base/message_pump_observer.h" #include "base/message_pump_observer.h"
typedef struct _GMainContext GMainContext;
typedef struct _GPollFD GPollFD;
typedef struct _GSource GSource;
namespace base { namespace base {
namespace wayland { namespace wayland {
...@@ -41,23 +37,7 @@ class MessagePumpDispatcher { ...@@ -41,23 +37,7 @@ class MessagePumpDispatcher {
virtual ~MessagePumpDispatcher() {} virtual ~MessagePumpDispatcher() {}
}; };
class BASE_EXPORT MessagePumpWayland : public MessagePumpGlib { typedef MessagePumpGlib MessagePumpForUI;
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 } // namespace base
......
...@@ -25,11 +25,9 @@ gboolean XSourceCheck(GSource* source) { ...@@ -25,11 +25,9 @@ gboolean XSourceCheck(GSource* source) {
gboolean XSourceDispatch(GSource* source, gboolean XSourceDispatch(GSource* source,
GSourceFunc unused_func, GSourceFunc unused_func,
gpointer unused_data) { gpointer data) {
// TODO(sad): When GTK event proecssing is completely removed, the event base::MessagePumpX* pump = static_cast<base::MessagePumpX*>(data);
// processing and dispatching should be done here (i.e. XNextEvent, return pump->DispatchXEvents();
// ProcessXEvent etc.)
return TRUE;
} }
GSourceFuncs XSourceFuncs = { GSourceFuncs XSourceFuncs = {
...@@ -129,6 +127,7 @@ void MessagePumpX::InitXSource() { ...@@ -129,6 +127,7 @@ void MessagePumpX::InitXSource() {
x_source_ = g_source_new(&XSourceFuncs, sizeof(GSource)); x_source_ = g_source_new(&XSourceFuncs, sizeof(GSource));
g_source_add_poll(x_source_, x_poll); g_source_add_poll(x_source_, x_poll);
g_source_set_can_recurse(x_source_, FALSE); 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()); g_source_attach(x_source_, g_main_context_default());
} }
...@@ -162,24 +161,21 @@ bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher, ...@@ -162,24 +161,21 @@ bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher,
return should_quit; return should_quit;
} }
bool MessagePumpX::RunOnce(GMainContext* context, bool block) { gboolean MessagePumpX::DispatchXEvents() {
Display* display = GetDefaultXDisplay(); Display* display = GetDefaultXDisplay();
DCHECK(display);
MessagePumpDispatcher* dispatcher = MessagePumpDispatcher* dispatcher =
GetDispatcher() ? GetDispatcher() : g_default_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 // 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. // the tasks. This is what happens in the message_pump_glib case.
while (XPending(display)) { while (XPending(display)) {
XEvent xev; XEvent xev;
XNextEvent(display, &xev); XNextEvent(display, &xev);
if (dispatcher && ProcessXEvent(dispatcher, &xev)) if (dispatcher && ProcessXEvent(dispatcher, &xev))
return true; return TRUE;
} }
return TRUE;
return g_main_context_iteration(context, block);
} }
bool MessagePumpX::WillProcessXEvent(XEvent* xevent) { bool MessagePumpX::WillProcessXEvent(XEvent* xevent) {
......
...@@ -45,9 +45,6 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { ...@@ -45,9 +45,6 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib {
MessagePumpX(); MessagePumpX();
virtual ~MessagePumpX(); virtual ~MessagePumpX();
// Overridden from MessagePumpGlib:
virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;
// Returns default X Display. // Returns default X Display.
static Display* GetDefaultXDisplay(); static Display* GetDefaultXDisplay();
...@@ -57,6 +54,10 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { ...@@ -57,6 +54,10 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib {
// Sets the default dispatcher to process native events. // Sets the default dispatcher to process native events.
static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher); static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher);
// Internal function. Called by the glib source dispatch function. Processes
// all available X events.
gboolean DispatchXEvents();
private: private:
// Initializes the glib event source for X. // Initializes the glib event source for X.
void InitXSource(); void InitXSource();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment