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

Side by Side Diff: extensions/browser/event_router.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/BUILD.gn ('k') | extensions/browser/event_router.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_BROWSER_EVENT_ROUTER_H_ 5 #ifndef EXTENSIONS_BROWSER_EVENT_ROUTER_H_
6 #define EXTENSIONS_BROWSER_EVENT_ROUTER_H_ 6 #define EXTENSIONS_BROWSER_EVENT_ROUTER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <unordered_map> 10 #include <unordered_map>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/linked_ptr.h" 16 #include "base/memory/linked_ptr.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h"
18 #include "base/scoped_observer.h" 19 #include "base/scoped_observer.h"
19 #include "base/values.h" 20 #include "base/values.h"
20 #include "components/keyed_service/core/keyed_service.h" 21 #include "components/keyed_service/core/keyed_service.h"
21 #include "content/public/browser/render_process_host_observer.h" 22 #include "content/public/browser/render_process_host_observer.h"
22 #include "extensions/browser/event_listener_map.h" 23 #include "extensions/browser/event_listener_map.h"
23 #include "extensions/browser/events/lazy_event_dispatch_util.h" 24 #include "extensions/browser/events/lazy_event_dispatch_util.h"
24 #include "extensions/browser/extension_event_histogram_value.h" 25 #include "extensions/browser/extension_event_histogram_value.h"
25 #include "extensions/browser/extension_registry_observer.h" 26 #include "extensions/browser/extension_registry_observer.h"
26 #include "extensions/common/constants.h" 27 #include "extensions/common/constants.h"
27 #include "extensions/common/event_filtering_info.h" 28 #include "extensions/common/event_filtering_info.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // methods BroadcastEvent or DispatchEventToExtension. 96 // methods BroadcastEvent or DispatchEventToExtension.
96 static void DispatchEventToSender(IPC::Sender* ipc_sender, 97 static void DispatchEventToSender(IPC::Sender* ipc_sender,
97 void* browser_context_id, 98 void* browser_context_id,
98 const std::string& extension_id, 99 const std::string& extension_id,
99 events::HistogramValue histogram_value, 100 events::HistogramValue histogram_value,
100 const std::string& event_name, 101 const std::string& event_name,
101 std::unique_ptr<base::ListValue> event_args, 102 std::unique_ptr<base::ListValue> event_args,
102 UserGestureState user_gesture, 103 UserGestureState user_gesture,
103 const EventFilteringInfo& info); 104 const EventFilteringInfo& info);
104 105
106 // Returns false when the event is scoped to a context and the listening
107 // extension does not have access to events from that context.
108 static bool CanDispatchEventToBrowserContext(content::BrowserContext* context,
109 const Extension* extension,
110 const Event& event);
111
105 // An EventRouter is shared between |browser_context| and its associated 112 // An EventRouter is shared between |browser_context| and its associated
106 // incognito context. |extension_prefs| may be NULL in tests. 113 // incognito context. |extension_prefs| may be NULL in tests.
107 EventRouter(content::BrowserContext* browser_context, 114 EventRouter(content::BrowserContext* browser_context,
108 ExtensionPrefs* extension_prefs); 115 ExtensionPrefs* extension_prefs);
109 ~EventRouter() override; 116 ~EventRouter() override;
110 117
111 // Add or remove an extension as an event listener for |event_name|. 118 // Add or remove an extension as an event listener for |event_name|.
112 // 119 //
113 // Note that multiple extensions can share a process due to process 120 // Note that multiple extensions can share a process due to process
114 // collapsing. Also, a single extension can have 2 processes if it is a split 121 // collapsing. Also, a single extension can have 2 processes if it is a split
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // Dispatches the event to the specified extension or URL running in 299 // Dispatches the event to the specified extension or URL running in
293 // |process|. 300 // |process|.
294 void DispatchEventToProcess(const std::string& extension_id, 301 void DispatchEventToProcess(const std::string& extension_id,
295 const GURL& listener_url, 302 const GURL& listener_url,
296 content::RenderProcessHost* process, 303 content::RenderProcessHost* process,
297 int worker_thread_id, 304 int worker_thread_id,
298 const linked_ptr<Event>& event, 305 const linked_ptr<Event>& event,
299 const base::DictionaryValue* listener_filter, 306 const base::DictionaryValue* listener_filter,
300 bool did_enqueue); 307 bool did_enqueue);
301 308
302 // Returns false when the event is scoped to a context and the listening
303 // extension does not have access to events from that context. Also fills
304 // |event_args| with the proper arguments to send, which may differ if
305 // the event crosses the incognito boundary.
306 bool CanDispatchEventToBrowserContext(content::BrowserContext* context,
307 const Extension* extension,
308 const linked_ptr<Event>& event);
309
310 // Possibly loads given extension's background page in preparation to 309 // Possibly loads given extension's background page in preparation to
311 // dispatch an event. Returns true if the event was queued for subsequent 310 // dispatch an event. Returns true if the event was queued for subsequent
312 // dispatch, false otherwise. 311 // dispatch, false otherwise.
313 bool MaybeLoadLazyBackgroundPageToDispatchEvent( 312 bool MaybeLoadLazyBackgroundPageToDispatchEvent(
314 content::BrowserContext* context, 313 content::BrowserContext* context,
315 const Extension* extension, 314 const Extension* extension,
316 const linked_ptr<Event>& event, 315 const linked_ptr<Event>& event,
317 const base::DictionaryValue* listener_filter); 316 const base::DictionaryValue* listener_filter);
318 317
319 // Adds a filter to an event. 318 // Adds a filter to an event.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EventListenerMap listeners_; 370 EventListenerMap listeners_;
372 371
373 // Map from base event name to observer. 372 // Map from base event name to observer.
374 using ObserverMap = std::unordered_map<std::string, Observer*>; 373 using ObserverMap = std::unordered_map<std::string, Observer*>;
375 ObserverMap observers_; 374 ObserverMap observers_;
376 375
377 std::set<content::RenderProcessHost*> observed_process_set_; 376 std::set<content::RenderProcessHost*> observed_process_set_;
378 377
379 LazyEventDispatchUtil lazy_event_dispatch_util_; 378 LazyEventDispatchUtil lazy_event_dispatch_util_;
380 379
380 base::WeakPtrFactory<EventRouter> weak_factory_;
381
381 DISALLOW_COPY_AND_ASSIGN(EventRouter); 382 DISALLOW_COPY_AND_ASSIGN(EventRouter);
382 }; 383 };
383 384
384 struct Event { 385 struct Event {
385 // This callback should return true if the event should be dispatched to the 386 // This callback should return true if the event should be dispatched to the
386 // given context and extension, and false otherwise. 387 // given context and extension, and false otherwise.
387 using WillDispatchCallback = 388 using WillDispatchCallback =
388 base::Callback<bool(content::BrowserContext*, 389 base::Callback<bool(content::BrowserContext*,
389 const Extension*, 390 const Extension*,
390 Event*, 391 Event*,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 const std::string event_name; 466 const std::string event_name;
466 467
467 const std::string extension_id; 468 const std::string extension_id;
468 const GURL listener_url; 469 const GURL listener_url;
469 content::BrowserContext* const browser_context; 470 content::BrowserContext* const browser_context;
470 }; 471 };
471 472
472 } // namespace extensions 473 } // namespace extensions
473 474
474 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ 475 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « extensions/browser/BUILD.gn ('k') | extensions/browser/event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698