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 @@
'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',
......
......@@ -147,22 +147,13 @@ 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::MessagePumpGtk()
#define MESSAGE_PUMP_UI new base::MessagePumpForUI()
#define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
#else
#error Not implemented
......
......@@ -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 = RunOnce(context_, block);
more_work_is_plausible = g_main_context_iteration(context_, block);
if (state_->should_quit)
break;
......
......@@ -41,11 +41,6 @@ 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
......
......@@ -91,11 +91,6 @@ 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));
}
......
......@@ -54,9 +54,6 @@ 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);
......
// 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 @@
#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 {
......@@ -41,23 +37,7 @@ class MessagePumpDispatcher {
virtual ~MessagePumpDispatcher() {}
};
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;
typedef MessagePumpGlib MessagePumpForUI;
} // namespace base
......
......@@ -25,11 +25,9 @@ gboolean XSourceCheck(GSource* source) {
gboolean XSourceDispatch(GSource* source,
GSourceFunc unused_func,
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;
gpointer data) {
base::MessagePumpX* pump = static_cast<base::MessagePumpX*>(data);
return pump->DispatchXEvents();
}
GSourceFuncs XSourceFuncs = {
......@@ -129,6 +127,7 @@ 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());
}
......@@ -162,24 +161,21 @@ bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher,
return should_quit;
}
bool MessagePumpX::RunOnce(GMainContext* context, bool block) {
gboolean MessagePumpX::DispatchXEvents() {
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 g_main_context_iteration(context, block);
return TRUE;
}
bool MessagePumpX::WillProcessXEvent(XEvent* xevent) {
......
......@@ -45,9 +45,6 @@ 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();
......@@ -57,6 +54,10 @@ 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();
......
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