Index: chrome/browser/extensions/event_router.h |
diff --git a/chrome/browser/extensions/event_router.h b/chrome/browser/extensions/event_router.h |
index cbfb1b80abaa432e118121b2660ffba3b6f55416..bcd59d44cdbaba698d7318534f4dcfdc9022978f 100644 |
--- a/chrome/browser/extensions/event_router.h |
+++ b/chrome/browser/extensions/event_router.h |
@@ -47,6 +47,16 @@ class EventRouter : public content::NotificationObserver, |
USER_GESTURE_NOT_ENABLED = 2, |
}; |
+ // Observers register interest in events with a particular name and are |
+ // notified when a listener is added or removed for that |event_name|. |
+ class Observer { |
+ public: |
+ // Called when a listener is added. |
+ virtual void OnListenerAdded(const std::string& event_name) {} |
+ // Called when a listener is removed. |
+ virtual void OnListenerRemoved(const std::string& event_name) {} |
+ }; |
+ |
// Sends an event via ipc_sender to the given extension. Can be called on any |
// thread. |
static void DispatchEvent(IPC::Sender* ipc_sender, |
@@ -73,6 +83,12 @@ class EventRouter : public content::NotificationObserver, |
EventListenerMap& listeners() { return listeners_; } |
+ // Registers an observer, interested in listeners that receive the event |
+ // |event_name|, to be notified when such a listener is added or removed. |
+ // There can currently be only one observer for each distinct |event_name|. |
+ void RegisterObserver(Observer* observer, |
+ const std::string& event_name); |
+ |
// Add or remove the extension as having a lazy background page that listens |
// to the event. The difference from the above methods is that these will be |
// remembered even after the process goes away. We use this list to decide |
@@ -253,6 +269,9 @@ class EventRouter : public content::NotificationObserver, |
EventListenerMap listeners_; |
+ typedef std::map<std::string, Observer*> ObserverMap; |
+ ObserverMap observers_; |
+ |
// True if we should dispatch the event signalling that Chrome was updated |
// upon loading an extension. |
bool dispatch_chrome_updated_event_; |