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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6dcf9406100a03ca063f10d649335daee6393b45 |
| --- /dev/null |
| +++ b/extensions/browser/events/lazy_event_dispatcher.h |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCHER_H_ |
| +#define EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCHER_H_ |
| + |
| +#include <set> |
| +#include <utility> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/linked_ptr.h" |
| +#include "extensions/common/extension_id.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +} |
| + |
| +namespace content { |
| +class BrowserContext; |
| +} |
| + |
| +namespace extensions { |
| +class EventListener; |
| +class Extension; |
| +class ExtensionHost; |
| +class LazyContextId; |
| +struct Event; |
| + |
| +// Helper class for EventRouter to dispatch lazy events to lazy contexts. |
| +// |
| +// 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 DispatchFunc = |
|
Devlin
2017/06/15 01:37:26
nit: s/Func/Function (avoid less common abbreviati
lazyboy
2017/06/15 04:39:22
Done.
|
| + base::Callback<void(const linked_ptr<Event>&, ExtensionHost*)>; |
| + |
| + LazyEventDispatcher(content::BrowserContext* browser_context, |
| + const linked_ptr<Event>& event, |
| + const DispatchFunc& dispatch_func); |
| + ~LazyEventDispatcher(); |
| + |
| + // Dispatches a 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); |
| + |
| + // Returns whether or not a listener is queued for dispatch already. |
|
Devlin
2017/06/15 01:37:26
nit: maybe s/a listener/an identical listener?
lazyboy
2017/06/15 04:39:22
Done.
|
| + bool HasAlreadyDispatched(content::BrowserContext* context, |
| + const EventListener* listener) const; |
| + |
| + private: |
| + using EventPageDispatchIdentifier = |
| + std::pair<const content::BrowserContext*, std::string>; |
| + |
| + void DispatchToLazyContext(LazyContextId* dispatch_context, |
| + const base::DictionaryValue* listener_filter); |
|
Devlin
2017/06/15 01:37:26
nit: \n
lazyboy
2017/06/15 04:39:22
Done.
|
| + // Possibly loads given extension's background page or extension Service |
| + // Worker in preparation to dispatch an event. Returns true if the event was |
| + // queued for subsequent dispatch, false otherwise. |
| + bool QueueEventDispatch(LazyContextId* dispatch_context, |
| + const Extension* extension, |
| + const base::DictionaryValue* listener_filter); |
|
Devlin
2017/06/15 01:37:26
nit: \n (after the other functions, too)
lazyboy
2017/06/15 04:39:22
Done.
|
| + bool HasAlreadyDispatchedImpl(const LazyContextId* dispatch_context) const; |
| + void RecordAlreadyDispatched(LazyContextId* dispatch_context); |
| + content::BrowserContext* GetIncognitoContext(const Extension* extension); |
| + |
| + content::BrowserContext* const browser_context_; |
| + linked_ptr<Event> event_; |
| + DispatchFunc dispatch_func_; |
| + |
| + std::set<EventPageDispatchIdentifier> dispatched_ep_ids_; |
|
Devlin
2017/06/15 01:37:26
s/ep/<something else - or nothing. dispatched_ids
lazyboy
2017/06/15 04:39:22
I want something other than plain dispatch_ids_ b/
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(LazyEventDispatcher); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCHER_H_ |