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