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

Side by Side Diff: extensions/browser/process_manager.h

Issue 408523005: Reland: Refactor code that defers extension background page loading (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_PROCESS_MANAGER_H_ 5 #ifndef EXTENSIONS_BROWSER_PROCESS_MANAGER_H_
6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ 6 #define EXTENSIONS_BROWSER_PROCESS_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 15 matching lines...) Expand all
26 class DevToolsAgentHost; 26 class DevToolsAgentHost;
27 class RenderViewHost; 27 class RenderViewHost;
28 class RenderFrameHost; 28 class RenderFrameHost;
29 class SiteInstance; 29 class SiteInstance;
30 }; 30 };
31 31
32 namespace extensions { 32 namespace extensions {
33 33
34 class Extension; 34 class Extension;
35 class ExtensionHost; 35 class ExtensionHost;
36 class ExtensionRegistry;
37 class ProcessManagerDelegate;
36 class ProcessManagerObserver; 38 class ProcessManagerObserver;
37 39
38 // Manages dynamic state of running Chromium extensions. There is one instance 40 // Manages dynamic state of running Chromium extensions. There is one instance
39 // of this class per Profile. OTR Profiles have a separate instance that keeps 41 // of this class per Profile. OTR Profiles have a separate instance that keeps
40 // track of split-mode extensions only. 42 // track of split-mode extensions only.
41 class ProcessManager : public content::NotificationObserver { 43 class ProcessManager : public content::NotificationObserver {
42 public: 44 public:
43 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet; 45 typedef std::set<extensions::ExtensionHost*> ExtensionHostSet;
44 typedef ExtensionHostSet::const_iterator const_iterator; 46 typedef ExtensionHostSet::const_iterator const_iterator;
45 47
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 117
116 // Tracks network requests for a given RenderFrameHost, used to know 118 // Tracks network requests for a given RenderFrameHost, used to know
117 // when network activity is idle for lazy background pages. 119 // when network activity is idle for lazy background pages.
118 void OnNetworkRequestStarted(content::RenderFrameHost* render_frame_host); 120 void OnNetworkRequestStarted(content::RenderFrameHost* render_frame_host);
119 void OnNetworkRequestDone(content::RenderFrameHost* render_frame_host); 121 void OnNetworkRequestDone(content::RenderFrameHost* render_frame_host);
120 122
121 // Prevents |extension|'s background page from being closed and sends the 123 // Prevents |extension|'s background page from being closed and sends the
122 // onSuspendCanceled() event to it. 124 // onSuspendCanceled() event to it.
123 void CancelSuspend(const Extension* extension); 125 void CancelSuspend(const Extension* extension);
124 126
125 // Ensures background hosts are loaded for a new browser window. 127 // Creates background hosts if the embedder is ready and they are not already
126 void OnBrowserWindowReady(); 128 // loaded.
129 void MaybeCreateStartupBackgroundHosts();
127 130
128 // Gets the BrowserContext associated with site_instance_ and all other 131 // Gets the BrowserContext associated with site_instance_ and all other
129 // related SiteInstances. 132 // related SiteInstances.
130 content::BrowserContext* GetBrowserContext() const; 133 content::BrowserContext* GetBrowserContext() const;
131 134
132 // Sets callbacks for testing keepalive impulse behavior. 135 // Sets callbacks for testing keepalive impulse behavior.
133 typedef base::Callback<void(const std::string& extension_id)> 136 typedef base::Callback<void(const std::string& extension_id)>
134 ImpulseCallbackForTesting; 137 ImpulseCallbackForTesting;
135 void SetKeepaliveImpulseCallbackForTesting( 138 void SetKeepaliveImpulseCallbackForTesting(
136 const ImpulseCallbackForTesting& callback); 139 const ImpulseCallbackForTesting& callback);
137 void SetKeepaliveImpulseDecrementCallbackForTesting( 140 void SetKeepaliveImpulseDecrementCallbackForTesting(
138 const ImpulseCallbackForTesting& callback); 141 const ImpulseCallbackForTesting& callback);
139 142
140 // Creates an incognito-context instance for tests. Tests for non-incognito 143 // Creates a non-incognito instance for tests. |registry| allows unit tests
141 // contexts can just use Create() above. 144 // to inject an ExtensionRegistry that is not managed by the usual
145 // BrowserContextKeyedServiceFactory system.
146 static ProcessManager* CreateForTesting(content::BrowserContext* context,
147 ExtensionRegistry* registry);
148
149 // Creates an incognito-context instance for tests.
142 static ProcessManager* CreateIncognitoForTesting( 150 static ProcessManager* CreateIncognitoForTesting(
143 content::BrowserContext* incognito_context, 151 content::BrowserContext* incognito_context,
144 content::BrowserContext* original_context, 152 content::BrowserContext* original_context,
145 ProcessManager* original_manager); 153 ProcessManager* original_manager,
154 ExtensionRegistry* registry);
155
156 bool startup_background_hosts_created_for_test() const {
157 return startup_background_hosts_created_;
158 }
146 159
147 protected: 160 protected:
148 // If |context| is incognito pass the master context as |original_context|. 161 // If |context| is incognito pass the master context as |original_context|.
149 // Otherwise pass the same context for both. 162 // Otherwise pass the same context for both. Pass the ExtensionRegistry for
163 // |context| as |registry|, or override it for testing.
150 ProcessManager(content::BrowserContext* context, 164 ProcessManager(content::BrowserContext* context,
151 content::BrowserContext* original_context); 165 content::BrowserContext* original_context,
166 ExtensionRegistry* registry);
152 167
153 // Called on browser shutdown to close our extension hosts. 168 // Called on browser shutdown to close our extension hosts.
154 void CloseBackgroundHosts(); 169 void CloseBackgroundHosts();
155 170
156 // content::NotificationObserver: 171 // content::NotificationObserver:
157 virtual void Observe(int type, 172 virtual void Observe(int type,
158 const content::NotificationSource& source, 173 const content::NotificationSource& source,
159 const content::NotificationDetails& details) OVERRIDE; 174 const content::NotificationDetails& details) OVERRIDE;
160 175
161 // Load all background pages once the profile data is ready and the pages
162 // should be loaded.
163 void CreateBackgroundHostsForProfileStartup();
164
165 content::NotificationRegistrar registrar_; 176 content::NotificationRegistrar registrar_;
166 177
167 // The set of ExtensionHosts running viewless background extensions. 178 // The set of ExtensionHosts running viewless background extensions.
168 ExtensionHostSet background_hosts_; 179 ExtensionHostSet background_hosts_;
169 180
170 // A SiteInstance related to the SiteInstance for all extensions in 181 // A SiteInstance related to the SiteInstance for all extensions in
171 // this profile. We create it in such a way that a new 182 // this profile. We create it in such a way that a new
172 // browsing instance is created. This controls process grouping. 183 // browsing instance is created. This controls process grouping.
173 scoped_refptr<content::SiteInstance> site_instance_; 184 scoped_refptr<content::SiteInstance> site_instance_;
174 185
186 // Not owned. Also used by IncognitoProcessManager.
187 ExtensionRegistry* extension_registry_;
188
175 private: 189 private:
176 friend class ProcessManagerTest; 190 friend class ProcessManagerTest;
177 191
178 // Extra information we keep for each extension's background page. 192 // Extra information we keep for each extension's background page.
179 struct BackgroundPageData; 193 struct BackgroundPageData;
180 typedef std::string ExtensionId; 194 typedef std::string ExtensionId;
181 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap; 195 typedef std::map<ExtensionId, BackgroundPageData> BackgroundPageDataMap;
182 typedef std::map<content::RenderViewHost*, 196 typedef std::map<content::RenderViewHost*,
183 extensions::ViewType> ExtensionRenderViews; 197 extensions::ViewType> ExtensionRenderViews;
184 198
199 // Load all background pages once the profile data is ready and the pages
200 // should be loaded.
201 void CreateStartupBackgroundHosts();
202
185 // Called just after |host| is created so it can be registered in our lists. 203 // Called just after |host| is created so it can be registered in our lists.
186 void OnBackgroundHostCreated(ExtensionHost* host); 204 void OnBackgroundHostCreated(ExtensionHost* host);
187 205
188 // Close the given |host| iff it's a background page. 206 // Close the given |host| iff it's a background page.
189 void CloseBackgroundHost(ExtensionHost* host); 207 void CloseBackgroundHost(ExtensionHost* host);
190 208
191 // Internal implementation of DecrementLazyKeepaliveCount with an 209 // Internal implementation of DecrementLazyKeepaliveCount with an
192 // |extension_id| known to have a lazy background page. 210 // |extension_id| known to have a lazy background page.
193 void DecrementLazyKeepaliveCount(const std::string& extension_id); 211 void DecrementLazyKeepaliveCount(const std::string& extension_id);
194 212
(...skipping 14 matching lines...) Expand all
209 // with an extension). 227 // with an extension).
210 bool RegisterRenderViewHost(content::RenderViewHost* render_view_host); 228 bool RegisterRenderViewHost(content::RenderViewHost* render_view_host);
211 229
212 // Unregister RenderViewHosts and clear background page data for an extension 230 // Unregister RenderViewHosts and clear background page data for an extension
213 // which has been unloaded. 231 // which has been unloaded.
214 void UnregisterExtension(const std::string& extension_id); 232 void UnregisterExtension(const std::string& extension_id);
215 233
216 // Clears background page data for this extension. 234 // Clears background page data for this extension.
217 void ClearBackgroundPageData(const std::string& extension_id); 235 void ClearBackgroundPageData(const std::string& extension_id);
218 236
219 // Returns true if loading background pages should be deferred.
220 bool DeferLoadingBackgroundHosts() const;
221
222 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); 237 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
223 238
224 // Contains all active extension-related RenderViewHost instances for all 239 // Contains all active extension-related RenderViewHost instances for all
225 // extensions. We also keep a cache of the host's view type, because that 240 // extensions. We also keep a cache of the host's view type, because that
226 // information is not accessible at registration/deregistration time. 241 // information is not accessible at registration/deregistration time.
227 ExtensionRenderViews all_extension_views_; 242 ExtensionRenderViews all_extension_views_;
228 243
229 BackgroundPageDataMap background_page_data_; 244 BackgroundPageDataMap background_page_data_;
230 245
231 // The time to delay between an extension becoming idle and 246 // The time to delay between an extension becoming idle and
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 278
264 // Must be last member, see doc on WeakPtrFactory. 279 // Must be last member, see doc on WeakPtrFactory.
265 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_; 280 base::WeakPtrFactory<ProcessManager> weak_ptr_factory_;
266 281
267 DISALLOW_COPY_AND_ASSIGN(ProcessManager); 282 DISALLOW_COPY_AND_ASSIGN(ProcessManager);
268 }; 283 };
269 284
270 } // namespace extensions 285 } // namespace extensions
271 286
272 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_ 287 #endif // EXTENSIONS_BROWSER_PROCESS_MANAGER_H_
OLDNEW
« no previous file with comments | « extensions/browser/lazy_background_task_queue_unittest.cc ('k') | extensions/browser/process_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698