OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/extensions/event_listener_map.h" | 19 #include "chrome/browser/extensions/event_listener_map.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 #include "extensions/common/event_filtering_info.h" | 22 #include "extensions/common/event_filtering_info.h" |
23 #include "ipc/ipc_sender.h" | 23 #include "ipc/ipc_sender.h" |
24 | 24 |
25 class GURL; | 25 class GURL; |
26 class PrefService; | 26 class PrefService; |
27 class Profile; | |
28 | 27 |
29 namespace content { | 28 namespace content { |
30 class BrowserContext; | 29 class BrowserContext; |
31 class RenderProcessHost; | 30 class RenderProcessHost; |
32 } | 31 } |
33 | 32 |
34 namespace extensions { | 33 namespace extensions { |
35 class ActivityLog; | 34 class ActivityLog; |
36 class Extension; | 35 class Extension; |
37 class ExtensionHost; | 36 class ExtensionHost; |
(...skipping 23 matching lines...) Expand all Loading... |
61 public: | 60 public: |
62 // Called when a listener is added. | 61 // Called when a listener is added. |
63 virtual void OnListenerAdded(const EventListenerInfo& details) {} | 62 virtual void OnListenerAdded(const EventListenerInfo& details) {} |
64 // Called when a listener is removed. | 63 // Called when a listener is removed. |
65 virtual void OnListenerRemoved(const EventListenerInfo& details) {} | 64 virtual void OnListenerRemoved(const EventListenerInfo& details) {} |
66 }; | 65 }; |
67 | 66 |
68 // Sends an event via ipc_sender to the given extension. Can be called on any | 67 // Sends an event via ipc_sender to the given extension. Can be called on any |
69 // thread. | 68 // thread. |
70 static void DispatchEvent(IPC::Sender* ipc_sender, | 69 static void DispatchEvent(IPC::Sender* ipc_sender, |
71 void* profile_id, | 70 void* browser_context_id, |
72 const std::string& extension_id, | 71 const std::string& extension_id, |
73 const std::string& event_name, | 72 const std::string& event_name, |
74 scoped_ptr<base::ListValue> event_args, | 73 scoped_ptr<base::ListValue> event_args, |
75 UserGestureState user_gesture, | 74 UserGestureState user_gesture, |
76 const EventFilteringInfo& info); | 75 const EventFilteringInfo& info); |
77 | 76 |
78 // An EventRouter is shared between |browser_context| and its associated | 77 // An EventRouter is shared between |browser_context| and its associated |
79 // incognito context. |extension_prefs| may be NULL in tests. | 78 // incognito context. |extension_prefs| may be NULL in tests. |
80 EventRouter(content::BrowserContext* browser_context, | 79 EventRouter(content::BrowserContext* browser_context, |
81 ExtensionPrefs* extension_prefs); | 80 ExtensionPrefs* extension_prefs); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // to that event. | 166 // to that event. |
168 typedef std::map<std::string, std::set<ListenerProcess> > ListenerMap; | 167 typedef std::map<std::string, std::set<ListenerProcess> > ListenerMap; |
169 | 168 |
170 // An identifier for an event dispatch that is used to prevent double dispatch | 169 // An identifier for an event dispatch that is used to prevent double dispatch |
171 // due to race conditions between the direct and lazy dispatch paths. | 170 // due to race conditions between the direct and lazy dispatch paths. |
172 typedef std::pair<const content::BrowserContext*, std::string> | 171 typedef std::pair<const content::BrowserContext*, std::string> |
173 EventDispatchIdentifier; | 172 EventDispatchIdentifier; |
174 | 173 |
175 // Records an event notification in the extension activity log. Can be | 174 // Records an event notification in the extension activity log. Can be |
176 // called from any thread. | 175 // called from any thread. |
177 static void LogExtensionEventMessage(void* profile_id, | 176 static void LogExtensionEventMessage(void* browser_context_id, |
178 const std::string& extension_id, | 177 const std::string& extension_id, |
179 const std::string& event_name, | 178 const std::string& event_name, |
180 scoped_ptr<base::ListValue> event_args); | 179 scoped_ptr<base::ListValue> event_args); |
181 | 180 |
182 // TODO(gdk): Document this. | 181 // TODO(gdk): Document this. |
183 static void DispatchExtensionMessage( | 182 static void DispatchExtensionMessage( |
184 IPC::Sender* ipc_sender, | 183 IPC::Sender* ipc_sender, |
185 void* profile_id, | 184 void* browser_context_id, |
186 const std::string& extension_id, | 185 const std::string& extension_id, |
187 const std::string& event_name, | 186 const std::string& event_name, |
188 base::ListValue* event_args, | 187 base::ListValue* event_args, |
189 UserGestureState user_gesture, | 188 UserGestureState user_gesture, |
190 const extensions::EventFilteringInfo& info); | 189 const extensions::EventFilteringInfo& info); |
191 | 190 |
192 virtual void Observe(int type, | 191 virtual void Observe(int type, |
193 const content::NotificationSource& source, | 192 const content::NotificationSource& source, |
194 const content::NotificationDetails& details) OVERRIDE; | 193 const content::NotificationDetails& details) OVERRIDE; |
195 | 194 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 const base::DictionaryValue* GetFilteredEvents( | 249 const base::DictionaryValue* GetFilteredEvents( |
251 const std::string& extension_id); | 250 const std::string& extension_id); |
252 | 251 |
253 // Track of the number of dispatched events that have not yet sent an | 252 // Track of the number of dispatched events that have not yet sent an |
254 // ACK from the renderer. | 253 // ACK from the renderer. |
255 void IncrementInFlightEvents(content::BrowserContext* context, | 254 void IncrementInFlightEvents(content::BrowserContext* context, |
256 const Extension* extension); | 255 const Extension* extension); |
257 | 256 |
258 // static | 257 // static |
259 static void IncrementInFlightEventsOnUI( | 258 static void IncrementInFlightEventsOnUI( |
260 void* profile_id, | 259 void* browser_context_id, |
261 const std::string& extension_id); | 260 const std::string& extension_id); |
262 | 261 |
263 void DispatchPendingEvent(const linked_ptr<Event>& event, | 262 void DispatchPendingEvent(const linked_ptr<Event>& event, |
264 ExtensionHost* host); | 263 ExtensionHost* host); |
265 | 264 |
266 // Implementation of EventListenerMap::Delegate. | 265 // Implementation of EventListenerMap::Delegate. |
267 virtual void OnListenerAdded(const EventListener* listener) OVERRIDE; | 266 virtual void OnListenerAdded(const EventListener* listener) OVERRIDE; |
268 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; | 267 virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE; |
269 | 268 |
270 content::BrowserContext* browser_context_; | 269 content::BrowserContext* browser_context_; |
271 | 270 |
272 // The ExtensionPrefs associated with |profile_|. May be NULL in tests. | 271 // The ExtensionPrefs associated with |browser_context_|. May be NULL in |
| 272 // tests. |
273 ExtensionPrefs* extension_prefs_; | 273 ExtensionPrefs* extension_prefs_; |
274 | 274 |
275 content::NotificationRegistrar registrar_; | 275 content::NotificationRegistrar registrar_; |
276 | 276 |
277 EventListenerMap listeners_; | 277 EventListenerMap listeners_; |
278 | 278 |
279 typedef base::hash_map<std::string, Observer*> ObserverMap; | 279 typedef base::hash_map<std::string, Observer*> ObserverMap; |
280 ObserverMap observers_; | 280 ObserverMap observers_; |
281 | 281 |
282 // True if we should dispatch the chrome.runtime.onInstalled event with | |
283 // reason "chrome_update" upon loading each extension. | |
284 // TODO(jamescook): Move this to RuntimeEventRouter. | |
285 bool dispatch_chrome_updated_event_; | |
286 | |
287 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 282 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
288 }; | 283 }; |
289 | 284 |
290 struct Event { | 285 struct Event { |
291 typedef base::Callback<void(content::BrowserContext*, | 286 typedef base::Callback<void(content::BrowserContext*, |
292 const Extension*, | 287 const Extension*, |
293 base::ListValue*)> WillDispatchCallback; | 288 base::ListValue*)> WillDispatchCallback; |
294 | 289 |
295 // The event to dispatch. | 290 // The event to dispatch. |
296 std::string event_name; | 291 std::string event_name; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 EventListenerInfo(const std::string& event_name, | 340 EventListenerInfo(const std::string& event_name, |
346 const std::string& extension_id); | 341 const std::string& extension_id); |
347 | 342 |
348 const std::string event_name; | 343 const std::string event_name; |
349 const std::string extension_id; | 344 const std::string extension_id; |
350 }; | 345 }; |
351 | 346 |
352 } // namespace extensions | 347 } // namespace extensions |
353 | 348 |
354 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ | 349 #endif // CHROME_BROWSER_EXTENSIONS_EVENT_ROUTER_H_ |
OLD | NEW |