summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-14 16:34:31 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-14 16:34:31 +0000
commit2f814d30264d0ebcb5f452d3b0c785b72e240ead (patch)
tree085c3e50bc38c0eb6a81765f2483ee92c8fc67c8 /base
parent33e1c37730f7d404b61f8bed2eb768f9902b1b64 (diff)
downloadchromium_src-2f814d30264d0ebcb5f452d3b0c785b72e240ead.zip
chromium_src-2f814d30264d0ebcb5f452d3b0c785b72e240ead.tar.gz
chromium_src-2f814d30264d0ebcb5f452d3b0c785b72e240ead.tar.bz2
Refactor MessagePumpX to dispatch events inside of the source Dispatch function.
Also clean up MessagePumpGlib. BUG=None TEST=None Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=114168 Review URL: http://codereview.chromium.org/8872055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114439 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi1
-rw-r--r--base/message_loop.cc11
-rw-r--r--base/message_pump_glib.cc2
-rw-r--r--base/message_pump_glib.h5
-rw-r--r--base/message_pump_gtk.cc5
-rw-r--r--base/message_pump_gtk.h3
-rw-r--r--base/message_pump_wayland.cc24
-rw-r--r--base/message_pump_wayland.h22
-rw-r--r--base/message_pump_x.cc22
-rw-r--r--base/message_pump_x.h7
10 files changed, 16 insertions, 86 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 4c126ce..9251dd9 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -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',
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 38ede80..f272a83 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -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
diff --git a/base/message_pump_glib.cc b/base/message_pump_glib.cc
index 19a0eea..85fee9a 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 = RunOnce(context_, block);
+ more_work_is_plausible = g_main_context_iteration(context_, block);
if (state_->should_quit)
break;
diff --git a/base/message_pump_glib.h b/base/message_pump_glib.h
index 872b031..f2b6616 100644
--- a/base/message_pump_glib.h
+++ b/base/message_pump_glib.h
@@ -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
diff --git a/base/message_pump_gtk.cc b/base/message_pump_gtk.cc
index 4f4f981..2c526ca 100644
--- a/base/message_pump_gtk.cc
+++ b/base/message_pump_gtk.cc
@@ -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));
}
diff --git a/base/message_pump_gtk.h b/base/message_pump_gtk.h
index 80122ce..ea1630f0 100644
--- a/base/message_pump_gtk.h
+++ b/base/message_pump_gtk.h
@@ -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);
diff --git a/base/message_pump_wayland.cc b/base/message_pump_wayland.cc
deleted file mode 100644
index 4d64c62..0000000
--- a/base/message_pump_wayland.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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 706914a..89c9b8f 100644
--- a/base/message_pump_wayland.h
+++ b/base/message_pump_wayland.h
@@ -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
diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc
index 13adb37..5230c7e 100644
--- a/base/message_pump_x.cc
+++ b/base/message_pump_x.cc
@@ -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 = {
@@ -128,7 +126,8 @@ 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_can_recurse(x_source_, TRUE);
+ 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) {
diff --git a/base/message_pump_x.h b/base/message_pump_x.h
index e6bb71c..62597a2 100644
--- a/base/message_pump_x.h
+++ b/base/message_pump_x.h
@@ -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();