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

Unified 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: dependency inject ExtensionRegistry 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/process_manager.h
diff --git a/extensions/browser/process_manager.h b/extensions/browser/process_manager.h
index e580bbd9335205b8b22ec164c25930d9e9853802..e3c6bcf06aa550e2ca8d350312b1e0732ec01d0b 100644
--- a/extensions/browser/process_manager.h
+++ b/extensions/browser/process_manager.h
@@ -33,6 +33,8 @@ namespace extensions {
class Extension;
class ExtensionHost;
+class ExtensionRegistry;
+class ProcessManagerDelegate;
class ProcessManagerObserver;
// Manages dynamic state of running Chromium extensions. There is one instance
@@ -122,8 +124,9 @@ class ProcessManager : public content::NotificationObserver {
// onSuspendCanceled() event to it.
void CancelSuspend(const Extension* extension);
- // Ensures background hosts are loaded for a new browser window.
- void OnBrowserWindowReady();
+ // Creates background hosts if the embedder is ready and they are not already
+ // loaded.
+ void MaybeCreateStartupBackgroundHosts();
// Gets the BrowserContext associated with site_instance_ and all other
// related SiteInstances.
@@ -137,18 +140,30 @@ class ProcessManager : public content::NotificationObserver {
void SetKeepaliveImpulseDecrementCallbackForTesting(
const ImpulseCallbackForTesting& callback);
- // Creates an incognito-context instance for tests. Tests for non-incognito
- // contexts can just use Create() above.
+ // Creates a non-incognito instance for tests. |registry| allows unit tests
+ // to inject an ExtensionRegistry that is not managed by the usual
+ // BrowserContextKeyedServiceFactory system.
+ static ProcessManager* CreateForTesting(content::BrowserContext* context,
+ ExtensionRegistry* registry);
+
+ // Creates an incognito-context instance for tests.
static ProcessManager* CreateIncognitoForTesting(
content::BrowserContext* incognito_context,
content::BrowserContext* original_context,
- ProcessManager* original_manager);
+ ProcessManager* original_manager,
+ ExtensionRegistry* registry);
+
+ bool startup_background_hosts_created_for_test() const {
+ return startup_background_hosts_created_;
+ }
protected:
// If |context| is incognito pass the master context as |original_context|.
- // Otherwise pass the same context for both.
+ // Otherwise pass the same context for both. Pass the ExtensionRegistry for
+ // |context| as |registry|, or override it for testing.
ProcessManager(content::BrowserContext* context,
- content::BrowserContext* original_context);
+ content::BrowserContext* original_context,
+ ExtensionRegistry* registry);
// Called on browser shutdown to close our extension hosts.
void CloseBackgroundHosts();
@@ -158,10 +173,6 @@ class ProcessManager : public content::NotificationObserver {
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // Load all background pages once the profile data is ready and the pages
- // should be loaded.
- void CreateBackgroundHostsForProfileStartup();
-
content::NotificationRegistrar registrar_;
// The set of ExtensionHosts running viewless background extensions.
@@ -172,6 +183,9 @@ class ProcessManager : public content::NotificationObserver {
// browsing instance is created. This controls process grouping.
scoped_refptr<content::SiteInstance> site_instance_;
+ // Not owned. Also used by IncognitoProcessManager.
+ ExtensionRegistry* extension_registry_;
+
private:
friend class ProcessManagerTest;
@@ -182,6 +196,10 @@ class ProcessManager : public content::NotificationObserver {
typedef std::map<content::RenderViewHost*,
extensions::ViewType> ExtensionRenderViews;
+ // Load all background pages once the profile data is ready and the pages
+ // should be loaded.
+ void CreateStartupBackgroundHosts();
+
// Called just after |host| is created so it can be registered in our lists.
void OnBackgroundHostCreated(ExtensionHost* host);
@@ -216,9 +234,6 @@ class ProcessManager : public content::NotificationObserver {
// Clears background page data for this extension.
void ClearBackgroundPageData(const std::string& extension_id);
- // Returns true if loading background pages should be deferred.
- bool DeferLoadingBackgroundHosts() const;
-
void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
// Contains all active extension-related RenderViewHost instances for all

Powered by Google App Engine
This is Rietveld 408576698