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

Side by Side Diff: chrome/browser/extensions/extension_event_router.h

Issue 7672009: Lazy creating of background pages --enable-lazy-background-pages) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move implementation to ExtensionEventRouter and store pending events in a queue Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 void DispatchEventsToRenderersAcrossIncognito( 82 void DispatchEventsToRenderersAcrossIncognito(
83 const std::string& event_name, 83 const std::string& event_name,
84 const std::string& event_args, 84 const std::string& event_args,
85 Profile* restrict_to_profile, 85 Profile* restrict_to_profile,
86 const std::string& cross_incognito_args, 86 const std::string& cross_incognito_args,
87 const GURL& event_url); 87 const GURL& event_url);
88 88
89 protected: 89 protected:
90 // Shared by DispatchEvent*. If |extension_id| is empty, the event is 90 // Shared by DispatchEvent*. If |extension_id| is empty, the event is
91 // broadcast. 91 // broadcast.
92 // Eventually DispatchEventImpl will be called, but it may be delayed
93 // sif the extension has a lazy background page.
94 void MaybeDispatchEventImpl(
95 const std::string& extension_id,
96 const std::string& event_name,
97 const std::string& event_args,
98 Profile* restrict_to_profile,
99 const std::string& cross_incognito_args,
100 const GURL& event_url);
92 virtual void DispatchEventImpl( 101 virtual void DispatchEventImpl(
93 const std::string& extension_id, 102 const std::string& extension_id,
94 const std::string& event_name, 103 const std::string& event_name,
95 const std::string& event_args, 104 const std::string& event_args,
96 Profile* restrict_to_profile, 105 Profile* restrict_to_profile,
97 const std::string& cross_incognito_args, 106 const std::string& cross_incognito_args,
98 const GURL& event_url); 107 const GURL& event_url);
99 108
109 // Store the event and dispatch it when the background page is done loading.
110 void EnqueueEvent(const std::string& extension_id,
111 const std::string& event_name,
112 const std::string& event_args,
113 Profile* restrict_to_profile,
114 const std::string& cross_incognito_args,
115 const GURL& event_url);
116 void DispatchPendingEvents(const std::string& extension_id);
117 void ClearPendingEvents(const std::string& extension_id);
118
100 private: 119 private:
101 // An extension listening to an event. 120 // An extension listening to an event.
102 struct EventListener; 121 struct EventListener;
103 122
123 // An event that is waiting to be dispatched.
124 struct PendingEvent;
125
104 virtual void Observe(int type, 126 virtual void Observe(int type,
105 const NotificationSource& source, 127 const NotificationSource& source,
106 const NotificationDetails& details); 128 const NotificationDetails& details);
107 129
108 Profile* profile_; 130 Profile* profile_;
109 131
110 NotificationRegistrar registrar_; 132 NotificationRegistrar registrar_;
111 133
112 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; 134 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_;
113 135
114 // A map between an event name and a set of extensions that are listening 136 // A map between an event name and a set of extensions that are listening
115 // to that event. 137 // to that event.
116 typedef std::map<std::string, std::set<EventListener> > ListenerMap; 138 typedef std::map<std::string, std::set<EventListener> > ListenerMap;
117 ListenerMap listeners_; 139 ListenerMap listeners_;
118 140
141 // A map between an extension id and the queue of events pending
142 // the load of it's background page.
143 typedef std::vector<PendingEvent> PendingEventsQueue;
Aaron Boodman 2011/08/18 19:25:55 You can use std::queue.
Tessa MacDuff 2011/08/18 20:49:39 Yeah, I just thought it was overkill since I never
Aaron Boodman 2011/08/18 21:19:23 ok.
Tessa MacDuff 2011/08/23 18:18:42 Done.
144 std::map<std::string, PendingEventsQueue> pending_events_;
Aaron Boodman 2011/08/18 19:25:55 Nit: this is a bit inefficient because as these ma
Tessa MacDuff 2011/08/23 18:18:42 Done.
145
119 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); 146 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter);
120 }; 147 };
121 148
122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 149 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698