Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1180)

Unified Diff: chrome/browser/extensions/event_router.h

Issue 11359081: Lazy initialization for ProcessesEventRouter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,
Aaron Boodman 2012/11/07 04:08:20 Do we not need an UnregisterObserver? And if so, I
Yoyo Zhou 2012/11/07 22:53:36 After thinking about this, I do think UnregisterOb
+ 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_;

Powered by Google App Engine
This is Rietveld 408576698