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

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

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

Powered by Google App Engine
This is Rietveld 408576698