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..bb69b1bba8295542cfd27c3fded76b4706d93624 100644 |
--- a/chrome/browser/extensions/event_router.h |
+++ b/chrome/browser/extensions/event_router.h |
@@ -22,7 +22,6 @@ |
#include "ipc/ipc_sender.h" |
class GURL; |
-class ExtensionDevToolsManager; |
class Profile; |
namespace content { |
@@ -47,6 +46,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, |
@@ -57,9 +66,12 @@ class EventRouter : public content::NotificationObserver, |
UserGestureState user_gesture, |
const EventFilteringInfo& info); |
- EventRouter(Profile* profile, ExtensionPrefs* extension_prefs); |
+ explicit EventRouter(Profile* profile); |
virtual ~EventRouter(); |
+ // Completes initialization once ExtensionPrefs are available. |
+ void InitWithPrefs(ExtensionPrefs* extension_prefs); |
+ |
// Add or remove the process/extension pair as a listener for |event_name|. |
// Note that multiple extensions can share a process due to process |
// collapsing. Also, a single extension can have 2 processes if it is a split |
@@ -73,6 +85,15 @@ class EventRouter : public content::NotificationObserver, |
EventListenerMap& listeners() { return listeners_; } |
+ // Registers an observer, interested in listeners that receive the event |
Aaron Boodman
2012/11/07 23:51:28
Nit: comment a little unclear. How about just "Reg
Yoyo Zhou
2012/11/08 00:18:16
Done.
|
+ // |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); |
+ |
+ // Unregisters an observer from all events. |
+ void UnregisterObserver(Observer* observer); |
+ |
// 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 |
@@ -249,10 +270,11 @@ class EventRouter : public content::NotificationObserver, |
content::NotificationRegistrar registrar_; |
- scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; |
- |
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_; |