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..b8446578ef89327fff4a100158153e5450d950ae 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>; |
void DispatchToLazyContext(LazyContextId* dispatch_context, |
const base::DictionaryValue* listener_filter); |
@@ -78,7 +86,10 @@ class LazyEventDispatcher { |
linked_ptr<Event> event_; |
DispatchFunction dispatch_function_; |
+ // TODO(lazyboy): Instead of keeping these two std::sets, compbine them using |
+ // LazyContextId key when service worker event listeners are more common. |
std::set<EventPageDispatchIdentifier> dispatched_ids_for_event_page_; |
+ std::set<ServiceWorkerDispatchIdentifier> dispatched_ids_for_service_worker_; |
DISALLOW_COPY_AND_ASSIGN(LazyEventDispatcher); |
}; |