Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: extensions/browser/events/lazy_event_dispatcher.h

Issue 2940883007: Move lazy event dispatching code out of EventRouter. (Closed)
Patch Set: address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/event_router.cc ('k') | extensions/browser/events/lazy_event_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCHER_H_
6 #define EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCHER_H_
7
8 #include <set>
9 #include <utility>
10
11 #include "base/callback.h"
12 #include "base/memory/linked_ptr.h"
13 #include "extensions/common/extension_id.h"
14
15 namespace base {
16 class DictionaryValue;
17 }
18
19 namespace content {
20 class BrowserContext;
21 }
22
23 namespace extensions {
24 class EventListener;
25 class Extension;
26 class ExtensionHost;
27 class LazyContextId;
28 struct Event;
29
30 // Helper class for EventRouter to dispatch lazy events to lazy contexts.
31 //
32 // Manages waking up lazy contexts if they are stopped.
33 class LazyEventDispatcher {
34 public:
35 // TODO(lazyboy): ExtensionHost is specific to events pages, provide a generic
36 // context info that works for both event pages and service workers.
37 using DispatchFunction =
38 base::Callback<void(const linked_ptr<Event>&, ExtensionHost*)>;
39
40 LazyEventDispatcher(content::BrowserContext* browser_context,
41 const linked_ptr<Event>& event,
42 const DispatchFunction& dispatch_function);
43 ~LazyEventDispatcher();
44
45 // Dispatches a lazy event to |extension_id|.
46 //
47 // Ensures that all lazy background pages that are interested in the given
48 // event are loaded, and queues the event if the page is not ready yet.
49 void DispatchToEventPage(const ExtensionId& extension_id,
50 const base::DictionaryValue* listener_filter);
51
52 // Returns whether or not an event listener identical to |listener| is queued
53 // for dispatch already.
54 bool HasAlreadyDispatched(content::BrowserContext* context,
55 const EventListener* listener) const;
56
57 private:
58 using EventPageDispatchIdentifier =
59 std::pair<const content::BrowserContext*, std::string>;
60
61 void DispatchToLazyContext(LazyContextId* dispatch_context,
62 const base::DictionaryValue* listener_filter);
63
64 // Possibly loads given extension's background page or extension Service
65 // Worker in preparation to dispatch an event. Returns true if the event was
66 // queued for subsequent dispatch, false otherwise.
67 bool QueueEventDispatch(LazyContextId* dispatch_context,
68 const Extension* extension,
69 const base::DictionaryValue* listener_filter);
70
71 bool HasAlreadyDispatchedImpl(const LazyContextId* dispatch_context) const;
72
73 void RecordAlreadyDispatched(LazyContextId* dispatch_context);
74
75 content::BrowserContext* GetIncognitoContext(const Extension* extension);
76
77 content::BrowserContext* const browser_context_;
78 linked_ptr<Event> event_;
79 DispatchFunction dispatch_function_;
80
81 std::set<EventPageDispatchIdentifier> dispatched_ids_for_event_page_;
82
83 DISALLOW_COPY_AND_ASSIGN(LazyEventDispatcher);
84 };
85
86 } // namespace extensions
87
88 #endif // EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCHER_H_
OLDNEW
« no previous file with comments | « extensions/browser/event_router.cc ('k') | extensions/browser/events/lazy_event_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698