Chromium Code Reviews| Index: extensions/browser/events/lazy_event_dispatcher.h |
| diff --git a/extensions/browser/events/lazy_event_dispatcher.h b/extensions/browser/events/lazy_event_dispatcher.h |
| index 0ad46d367b5308af92df7091e80610ebeac26d8c..588cdd8635080dda6d196f5400e0cde40d844918 100644 |
| --- a/extensions/browser/events/lazy_event_dispatcher.h |
| +++ b/extensions/browser/events/lazy_event_dispatcher.h |
| @@ -10,6 +10,7 @@ |
| #include "base/callback.h" |
| #include "base/memory/linked_ptr.h" |
| +#include "extensions/browser/lazy_context_task_queue.h" |
| #include "extensions/common/extension_id.h" |
| namespace base { |
| @@ -23,7 +24,6 @@ class BrowserContext; |
| namespace extensions { |
| class EventListener; |
| class Extension; |
| -class ExtensionHost; |
| class LazyContextId; |
| struct Event; |
| @@ -32,22 +32,28 @@ struct Event; |
| // Manages waking up lazy contexts if they are stopped. |
| class LazyEventDispatcher { |
| public: |
| - // TODO(lazyboy): ExtensionHost is specific to events pages, provide a generic |
| - // context info that works for both event pages and service workers. |
| using DispatchFunction = |
| - base::Callback<void(const linked_ptr<Event>&, ExtensionHost*)>; |
| + base::Callback<void(const linked_ptr<Event>&, |
| + std::unique_ptr<LazyContextTaskQueue::ContextInfo>)>; |
| LazyEventDispatcher(content::BrowserContext* browser_context, |
| const linked_ptr<Event>& event, |
| const DispatchFunction& dispatch_function); |
| ~LazyEventDispatcher(); |
| - // Dispatches a lazy event to |extension_id|. |
| + // Dispatches the lazy |event_| to |extension_id|. |
| // |
| // Ensures that all lazy background pages that are interested in the given |
| // event are loaded, and queues the event if the page is not ready yet. |
| void DispatchToEventPage(const ExtensionId& extension_id, |
| const base::DictionaryValue* listener_filter); |
| + // Dispatches the lazy |event_| to |extension_id|'s service worker. |
| + // |
| + // Service workers are started if they were stopped, before dispatching the |
| + // event. |
| + void DispatchToServiceWorker(const ExtensionId& extension_id, |
| + const GURL& service_worker_scope, |
| + const base::DictionaryValue* listener_filter); |
| // Returns whether or not an event listener identical to |listener| is queued |
| // for dispatch already. |
| @@ -57,6 +63,8 @@ class LazyEventDispatcher { |
| private: |
| using EventPageDispatchIdentifier = |
| std::pair<const content::BrowserContext*, std::string>; |
| + using ServiceWorkerDispatchIdentifier = |
| + std::pair<const content::BrowserContext*, GURL>; |
|
Devlin
2017/06/16 02:34:42
Might be worth commenting on what GURL is here (I
lazyboy
2017/06/16 18:48:05
Done.
|
| void DispatchToLazyContext(LazyContextId* dispatch_context, |
| const base::DictionaryValue* listener_filter); |
| @@ -79,6 +87,7 @@ class LazyEventDispatcher { |
| DispatchFunction dispatch_function_; |
| std::set<EventPageDispatchIdentifier> dispatched_ids_for_event_page_; |
| + std::set<ServiceWorkerDispatchIdentifier> dispatched_ids_for_service_worker_; |
|
Devlin
2017/06/16 02:34:42
Could we instead just have a single set of LazyCon
lazyboy
2017/06/16 18:48:05
I agree that is simpler, but with the cost of keep
|
| DISALLOW_COPY_AND_ASSIGN(LazyEventDispatcher); |
| }; |