Chromium Code Reviews| Index: extensions/browser/event_router.h |
| diff --git a/extensions/browser/event_router.h b/extensions/browser/event_router.h |
| index 48bc266980cce4ce121f64a3402d8afbc5926e8a..d59395294eddc536d21a69557ff3427633e8bd17 100644 |
| --- a/extensions/browser/event_router.h |
| +++ b/extensions/browser/event_router.h |
| @@ -24,6 +24,7 @@ |
| #include "extensions/browser/event_listener_map.h" |
| #include "extensions/browser/extension_event_histogram_value.h" |
| #include "extensions/browser/extension_registry_observer.h" |
| +#include "extensions/common/constants.h" |
| #include "extensions/common/event_filtering_info.h" |
| #include "ipc/ipc_sender.h" |
| #include "url/gurl.h" |
| @@ -60,7 +61,10 @@ class EventRouter : public KeyedService, |
| // The pref key for the list of event names for which an extension has |
| // registered from its lazy background page. |
| - static const char kRegisteredEvents[]; |
| + static const char kRegisteredLazyEvents[]; |
| + // The pref key for the list of event names for which an extension has |
| + // registered from its service worker. |
| + static const char kRegisteredServiceWorkerEvents[]; |
| // Observers register interest in events with a particular name and are |
| // notified when a listener is added or removed. Observers are matched by |
| @@ -108,10 +112,18 @@ class EventRouter : public KeyedService, |
| // mode extension. |
| void AddEventListener(const std::string& event_name, |
| content::RenderProcessHost* process, |
| - const std::string& extension_id); |
| + const ExtensionId& extension_id); |
| + void AddServiceWorkerEventListener(const std::string& event_name, |
| + content::RenderProcessHost* process, |
| + const ExtensionId& extension_id, |
| + int worker_thread_id); |
| void RemoveEventListener(const std::string& event_name, |
| content::RenderProcessHost* process, |
| - const std::string& extension_id); |
| + const ExtensionId& extension_id); |
| + void RemoveServiceWorkerEventListener(const std::string& event_name, |
| + content::RenderProcessHost* process, |
| + const ExtensionId& extension_id, |
| + int worker_thread_id); |
| // Add or remove a URL as an event listener for |event_name|. |
| void AddEventListenerForURL(const std::string& event_name, |
| @@ -137,9 +149,17 @@ class EventRouter : public KeyedService, |
| // remembered even after the process goes away. We use this list to decide |
| // which extension pages to load when dispatching an event. |
| void AddLazyEventListener(const std::string& event_name, |
| - const std::string& extension_id); |
| + const ExtensionId& extension_id); |
| void RemoveLazyEventListener(const std::string& event_name, |
| - const std::string& extension_id); |
| + const ExtensionId& extension_id); |
| + // Similar to Add/RemoveLazyEventListener, but applies to extension service |
| + // workers. |
| + void AddLazyServiceWorkerEventListener(const std::string& event_name, |
| + const ExtensionId& extension_id, |
| + int worker_thread_id); |
| + void RemoveLazyServiceWorkerEventListener(const std::string& event_name, |
| + const ExtensionId& extension_id, |
| + int worker_thread_id); |
| // If |add_lazy_listener| is true also add the lazy version of this listener. |
| void AddFilteredEventListener(const std::string& event_name, |
| @@ -183,13 +203,11 @@ class EventRouter : public KeyedService, |
| // Returns whether or not the given extension has any registered events. |
| bool HasRegisteredEvents(const ExtensionId& extension_id) const { |
| - return !GetRegisteredEvents(extension_id).empty(); |
| + return !GetRegisteredEvents(extension_id, kRegisteredLazyEvents).empty(); |
| } |
| // Clears registered events for testing purposes. |
| - void ClearRegisteredEventsForTest(const ExtensionId& extension_id) { |
| - SetRegisteredEvents(extension_id, std::set<std::string>()); |
| - } |
| + void ClearRegisteredEventsForTest(const ExtensionId& extension_id); |
| // Reports UMA for an event dispatched to |extension| with histogram value |
| // |histogram_value|. Must be called on the UI thread. |
| @@ -206,12 +224,13 @@ class EventRouter : public KeyedService, |
| // An identifier for an event dispatch that is used to prevent double dispatch |
| // due to race conditions between the direct and lazy dispatch paths. |
| - typedef std::pair<const content::BrowserContext*, std::string> |
| + typedef std::tuple<const content::BrowserContext*, std::string, int> |
| EventDispatchIdentifier; |
| // TODO(gdk): Document this. |
| static void DispatchExtensionMessage( |
| IPC::Sender* ipc_sender, |
| + int worker_thread_id, |
| void* browser_context_id, |
| const std::string& extension_id, |
| int event_id, |
| @@ -222,10 +241,11 @@ class EventRouter : public KeyedService, |
| // Returns or sets the list of events for which the given extension has |
| // registered. |
| - std::set<std::string> GetRegisteredEvents( |
| - const std::string& extension_id) const; |
| + std::set<std::string> GetRegisteredEvents(const std::string& extension_id, |
| + const char* pref_key) const; |
|
Devlin
2017/05/24 17:58:25
nit: can we pass an enum rather than a const char
lazyboy
2017/05/25 01:33:43
Done.
|
| void SetRegisteredEvents(const std::string& extension_id, |
| - const std::set<std::string>& events); |
| + const std::set<std::string>& events, |
| + const char* pref_key); |
| void Observe(int type, |
| const content::NotificationSource& source, |
| @@ -237,6 +257,13 @@ class EventRouter : public KeyedService, |
| const Extension* extension, |
| UnloadedExtensionReason reason) override; |
| + void AddLazyEventListenerImpl(const std::string& event_name, |
| + const ExtensionId& extension_id, |
| + int worker_thread_id); |
| + void RemoveLazyEventListenerImpl(const std::string& event_name, |
| + const ExtensionId& extension_id, |
| + int worker_thread_id); |
| + |
| // Shared by all event dispatch methods. If |restrict_to_extension_id| is |
| // empty, the event is broadcast. An event that just came off the pending |
| // list may not be delayed again. |
| @@ -257,6 +284,7 @@ class EventRouter : public KeyedService, |
| void DispatchEventToProcess(const std::string& extension_id, |
| const GURL& listener_url, |
| content::RenderProcessHost* process, |
| + int worker_thread_id, |
| const linked_ptr<Event>& event, |
| const base::DictionaryValue* listener_filter, |
| bool did_enqueue); |
| @@ -291,7 +319,8 @@ class EventRouter : public KeyedService, |
| // Returns the dictionary of event filters that the given extension has |
| // registered. |
| const base::DictionaryValue* GetFilteredEvents( |
| - const std::string& extension_id); |
| + const std::string& extension_id, |
| + const char* pref_key); |
| // Track the dispatched events that have not yet sent an ACK from the |
| // renderer. |