Commit 827d38ae authored by sadrul@chromium.org's avatar sadrul@chromium.org

gtk: Some code cleanup for the message-pump.

GTK message-pump defines its own observer, but it has the same name as the
message-pump observers used in other platforms. So rename the GTK version
to MessagePumpGdkObserver.

Also, GTK version of message-pump dispatcher is never used, so get rid of
that.

BUG=145600
R=piman@chromium.org, thakis@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221846 0039d316-1c4b-4281-b951-d872f2087c98
parent 926bfe36
......@@ -425,7 +425,8 @@ void MessageLoop::RunInternal() {
StartHistogrammer();
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
!defined(USE_GTK_MESSAGE_PUMP)
if (run_loop_->dispatcher_ && type() == TYPE_UI) {
static_cast<MessagePumpForUI*>(pump_.get())->
RunWithDispatcher(this, run_loop_->dispatcher_);
......
......@@ -40,6 +40,7 @@
#elif defined(USE_OZONE) && !defined(OS_NACL)
#include "base/message_loop/message_pump_ozone.h"
#else
#define USE_GTK_MESSAGE_PUMP
#include "base/message_loop/message_pump_gtk.h"
#endif
......@@ -49,6 +50,8 @@
namespace base {
class HistogramBase;
class MessagePumpDispatcher;
class MessagePumpObserver;
class RunLoop;
class ThreadTaskRunnerHandle;
#if defined(OS_ANDROID)
......@@ -90,7 +93,9 @@ class WaitableEvent;
class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
public:
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
#if defined(USE_GTK_MESSAGE_PUMP)
typedef MessagePumpGdkObserver Observer;
#elif !defined(OS_MACOSX) && !defined(OS_ANDROID)
typedef MessagePumpDispatcher Dispatcher;
typedef MessagePumpObserver Observer;
#endif
......
......@@ -184,6 +184,14 @@ void MessagePumpAuraX11::RemoveDispatcherForRootWindow(
root_window_dispatchers_.RemoveObserver(dispatcher);
}
void MessagePumpAuraX11::AddObserver(MessagePumpObserver* observer) {
observers_.AddObserver(observer);
}
void MessagePumpAuraX11::RemoveObserver(MessagePumpObserver* observer) {
observers_.RemoveObserver(observer);
}
bool MessagePumpAuraX11::DispatchXEvents() {
Display* display = GetDefaultXDisplay();
DCHECK(display);
......
......@@ -58,6 +58,13 @@ class BASE_EXPORT MessagePumpAuraX11 : public MessagePumpGlib,
void AddDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
void RemoveDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
// Adds an Observer, which will start receiving notifications immediately.
void AddObserver(MessagePumpObserver* observer);
// Removes an Observer. It is safe to call this method while an Observer is
// receiving a notification callback.
void RemoveObserver(MessagePumpObserver* observer);
// Internal function. Called by the glib source dispatch function. Processes
// all available X events.
bool DispatchXEvents();
......@@ -92,6 +99,8 @@ class BASE_EXPORT MessagePumpAuraX11 : public MessagePumpGlib,
// Returns the Dispatcher based on the event's target window.
MessagePumpDispatcher* GetDispatcherForXEvent(const NativeEvent& xev) const;
ObserverList<MessagePumpObserver>& observers() { return observers_; }
// Overridden from MessagePumpDispatcher:
virtual bool Dispatch(const NativeEvent& event) OVERRIDE;
......@@ -108,6 +117,9 @@ class BASE_EXPORT MessagePumpAuraX11 : public MessagePumpGlib,
// additions.
ObserverList<MessagePumpDispatcher> root_window_dispatchers_;
// List of observers.
ObserverList<MessagePumpObserver> observers_;
unsigned long x_root_window_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpAuraX11);
......
......@@ -290,14 +290,6 @@ void MessagePumpGlib::HandleDispatch() {
state_->delegate->DoDelayedWork(&delayed_work_time_);
}
void MessagePumpGlib::AddObserver(MessagePumpObserver* observer) {
observers_.AddObserver(observer);
}
void MessagePumpGlib::RemoveObserver(MessagePumpObserver* observer) {
observers_.RemoveObserver(observer);
}
void MessagePumpGlib::Run(Delegate* delegate) {
RunWithDispatcher(delegate, NULL);
}
......
......@@ -51,13 +51,6 @@ class BASE_EXPORT MessagePumpGlib : public MessagePump {
bool HandleCheck();
void HandleDispatch();
// Adds an Observer, which will start receiving notifications immediately.
void AddObserver(MessagePumpObserver* observer);
// Removes an Observer. It is safe to call this method while an Observer is
// receiving a notification callback.
void RemoveObserver(MessagePumpObserver* observer);
// Overridden from MessagePump:
virtual void Run(Delegate* delegate) OVERRIDE;
virtual void Quit() OVERRIDE;
......@@ -68,8 +61,6 @@ class BASE_EXPORT MessagePumpGlib : public MessagePump {
// Returns the dispatcher for the current run state (|state_->dispatcher|).
MessagePumpDispatcher* GetDispatcher();
ObserverList<MessagePumpObserver>& observers() { return observers_; }
private:
// We may make recursive calls to Run, so we save state that needs to be
// separate between them in this structure type.
......@@ -98,9 +89,6 @@ class BASE_EXPORT MessagePumpGlib : public MessagePump {
// Use a scoped_ptr to avoid needing the definition of GPollFD in the header.
scoped_ptr<GPollFD> wakeup_gpollfd_;
// List of observers.
ObserverList<MessagePumpObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpGlib);
};
......
......@@ -75,13 +75,7 @@ void MessagePumpGtk::DispatchEvents(GdkEvent* event) {
"type", EventToTypeString(event));
WillProcessEvent(event);
MessagePumpDispatcher* dispatcher = GetDispatcher();
if (!dispatcher)
gtk_main_do_event(event);
else if (!dispatcher->Dispatch(event))
Quit();
DidProcessEvent(event);
}
......@@ -97,12 +91,24 @@ Display* MessagePumpGtk::GetDefaultXDisplay() {
return GDK_DISPLAY_XDISPLAY(display);
}
void MessagePumpGtk::AddObserver(MessagePumpGdkObserver* observer) {
observers_.AddObserver(observer);
}
void MessagePumpGtk::RemoveObserver(MessagePumpGdkObserver* observer) {
observers_.RemoveObserver(observer);
}
void MessagePumpGtk::WillProcessEvent(GdkEvent* event) {
FOR_EACH_OBSERVER(MessagePumpObserver, observers(), WillProcessEvent(event));
FOR_EACH_OBSERVER(MessagePumpGdkObserver,
observers_,
WillProcessEvent(event));
}
void MessagePumpGtk::DidProcessEvent(GdkEvent* event) {
FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(event));
FOR_EACH_OBSERVER(MessagePumpGdkObserver,
observers_,
DidProcessEvent(event));
}
// static
......
......@@ -13,7 +13,7 @@ typedef struct _XDisplay Display;
namespace base {
// The documentation for this class is in message_pump_glib.h
class MessagePumpObserver {
class MessagePumpGdkObserver {
public:
// This method is called before processing a message.
virtual void WillProcessEvent(GdkEvent* event) = 0;
......@@ -22,21 +22,7 @@ class MessagePumpObserver {
virtual void DidProcessEvent(GdkEvent* event) = 0;
protected:
virtual ~MessagePumpObserver() {}
};
// The documentation for this class is in message_pump_glib.h
//
// The nested loop is exited by either posting a quit, or returning false
// from Dispatch.
class MessagePumpDispatcher {
public:
// Dispatches the event. If true is returned processing continues as
// normal. If false is returned, the nested loop exits immediately.
virtual bool Dispatch(GdkEvent* event) = 0;
protected:
virtual ~MessagePumpDispatcher() {}
virtual ~MessagePumpGdkObserver() {}
};
// This class implements a message-pump for dispatching GTK events.
......@@ -52,6 +38,13 @@ class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
// Returns default X Display.
static Display* GetDefaultXDisplay();
// Adds an Observer, which will start receiving notifications immediately.
void AddObserver(MessagePumpGdkObserver* observer);
// Removes an Observer. It is safe to call this method while an Observer is
// receiving a notification callback.
void RemoveObserver(MessagePumpGdkObserver* observer);
private:
// Invoked from EventDispatcher. Notifies all observers we're about to
// process an event.
......@@ -64,6 +57,9 @@ class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
// Callback prior to gdk dispatching an event.
static void EventDispatcher(GdkEvent* event, void* data);
// List of observers.
ObserverList<MessagePumpGdkObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk);
};
......
......@@ -17,12 +17,14 @@ RunLoop::RunLoop()
quit_called_(false),
running_(false),
quit_when_idle_received_(false) {
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
!defined(USE_GTK_MESSAGE_PUMP)
dispatcher_ = NULL;
#endif
}
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
!defined(USE_GTK_MESSAGE_PUMP)
RunLoop::RunLoop(MessageLoop::Dispatcher* dispatcher)
: loop_(MessageLoop::current()),
weak_factory_(this),
......
......@@ -27,12 +27,14 @@ class MessagePumpUIApplication;
class BASE_EXPORT RunLoop {
public:
RunLoop();
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
!defined(USE_GTK_MESSAGE_PUMP)
explicit RunLoop(MessageLoop::Dispatcher* dispatcher);
#endif
~RunLoop();
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
!defined(USE_GTK_MESSAGE_PUMP)
void set_dispatcher(MessageLoop::Dispatcher* dispatcher) {
dispatcher_ = dispatcher;
}
......@@ -98,7 +100,8 @@ class BASE_EXPORT RunLoop {
// Parent RunLoop or NULL if this is the top-most RunLoop.
RunLoop* previous_run_loop_;
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
#if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
!defined(USE_GTK_MESSAGE_PUMP)
MessageLoop::Dispatcher* dispatcher_;
#endif
......
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