Adds an observer callback to Linux's MessagePumpForUI.

BUG=none
TEST=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16204 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/message_pump_glib.h b/base/message_pump_glib.h
index d25ae86a..c8a2e0d 100644
--- a/base/message_pump_glib.h
+++ b/base/message_pump_glib.h
@@ -5,9 +5,11 @@
 #ifndef BASE_MESSAGE_PUMP_GLIB_H_
 #define BASE_MESSAGE_PUMP_GLIB_H_
 
+#include <gtk/gtk.h>
 #include <glib.h>
 
 #include "base/message_pump.h"
+#include "base/observer_list.h"
 #include "base/time.h"
 
 namespace base {
@@ -16,6 +18,16 @@
 // OS_LINUX platforms using GLib.
 class MessagePumpForUI : public MessagePump {
  public:
+  // Observer is notified prior to a GdkEvent event being dispatched. As
+  // Observers are notified of every change, they have to be FAST!
+  class Observer {
+   public:
+    virtual ~Observer() {}
+
+    // This method is called before processing a message.
+    virtual void WillProcessEvent(GdkEvent* event) = 0;
+  };
+
   MessagePumpForUI();
   ~MessagePumpForUI();
 
@@ -32,6 +44,13 @@
   int HandlePrepare();
   void HandleDispatch();
 
+  // Add an Observer, which will start receiving notifications immediately.
+  void AddObserver(Observer* observer);
+
+  // Remove an Observer.  It is safe to call this method while an Observer is
+  // receiving a notification callback.
+  void RemoveObserver(Observer* observer);
+
  private:
   // We may make recursive calls to Run, so we save state that needs to be
   // separate between them in this structure type.
@@ -49,6 +68,13 @@
     bool more_work_is_plausible;
   };
 
+  // Invoked from EventDispatcher. Notifies all observers we're about to
+  // process an event.
+  void WillProcessEvent(GdkEvent* event);
+
+  // Callback prior to gdk dispatching an event.
+  static void EventDispatcher(GdkEvent* event, gpointer data);
+
   RunState* state_;
 
   // This is a GLib structure that we can add event sources to.  We use the
@@ -71,6 +97,9 @@
   int wakeup_pipe_write_;
   GPollFD wakeup_gpollfd_;
 
+  // List of observers.
+  ObserverList<Observer> observers_;
+
   DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
 };