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

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

Issue 2940883007: Move lazy event dispatching code out of EventRouter. (Closed)
Patch Set: 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
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 DispatchFunc =
Devlin 2017/06/15 01:37:26 nit: s/Func/Function (avoid less common abbreviati
lazyboy 2017/06/15 04:39:22 Done.
38 base::Callback<void(const linked_ptr<Event>&, ExtensionHost*)>;
39
40 LazyEventDispatcher(content::BrowserContext* browser_context,
41 const linked_ptr<Event>& event,
42 const DispatchFunc& dispatch_func);
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 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.
53 bool HasAlreadyDispatched(content::BrowserContext* context,
54 const EventListener* listener) const;
55
56 private:
57 using EventPageDispatchIdentifier =
58 std::pair<const content::BrowserContext*, std::string>;
59
60 void DispatchToLazyContext(LazyContextId* dispatch_context,
61 const base::DictionaryValue* listener_filter);
Devlin 2017/06/15 01:37:26 nit: \n
lazyboy 2017/06/15 04:39:22 Done.
62 // Possibly loads given extension's background page or extension Service
63 // Worker in preparation to dispatch an event. Returns true if the event was
64 // queued for subsequent dispatch, false otherwise.
65 bool QueueEventDispatch(LazyContextId* dispatch_context,
66 const Extension* extension,
67 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.
68 bool HasAlreadyDispatchedImpl(const LazyContextId* dispatch_context) const;
69 void RecordAlreadyDispatched(LazyContextId* dispatch_context);
70 content::BrowserContext* GetIncognitoContext(const Extension* extension);
71
72 content::BrowserContext* const browser_context_;
73 linked_ptr<Event> event_;
74 DispatchFunc dispatch_func_;
75
76 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/
77
78 DISALLOW_COPY_AND_ASSIGN(LazyEventDispatcher);
79 };
80
81 } // namespace extensions
82
83 #endif // EXTENSIONS_BROWSER_EVENTS_LAZY_EVENT_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698