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

Unified Diff: trunk/src/extensions/browser/process_manager.cc

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 side-by-side diff with in-line comments
Download patch
Index: trunk/src/extensions/browser/process_manager.cc
===================================================================
--- trunk/src/extensions/browser/process_manager.cc (revision 283800)
+++ trunk/src/extensions/browser/process_manager.cc (working copy)
@@ -33,7 +33,6 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
-#include "extensions/browser/process_manager_delegate.h"
#include "extensions/browser/process_manager_observer.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/constants.h"
@@ -246,6 +245,8 @@
content::NotificationService::AllSources());
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
content::NotificationService::AllSources());
+ registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
+ content::Source<BrowserContext>(original_context));
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<BrowserContext>(context));
if (context->IsOffTheRecord()) {
@@ -306,15 +307,12 @@
const GURL& url) {
// Hosted apps are taken care of from BackgroundContentsService. Ignore them
// here.
- if (extension->is_hosted_app())
+ if (extension->is_hosted_app() ||
+ !ExtensionsBrowserClient::Get()->
+ IsBackgroundPageAllowed(GetBrowserContext())) {
return false;
+ }
- // Don't create hosts if the embedder doesn't allow it.
- ProcessManagerDelegate* delegate =
- ExtensionsBrowserClient::Get()->GetProcessManagerDelegate();
- if (delegate && !delegate->IsBackgroundPageAllowed(GetBrowserContext()))
- return false;
-
// Don't create multiple background hosts for an extension.
if (GetBackgroundHostForExtension(extension->id()))
return true; // TODO(kalman): return false here? It might break things...
@@ -622,6 +620,16 @@
}
}
+void ProcessManager::OnBrowserWindowReady() {
+ // If the extension system isn't ready yet the background hosts will be
+ // created via NOTIFICATION_EXTENSIONS_READY below.
+ ExtensionSystem* system = ExtensionSystem::Get(GetBrowserContext());
+ if (!system->ready().is_signaled())
+ return;
+
+ CreateBackgroundHostsForProfileStartup();
+}
+
content::BrowserContext* ProcessManager::GetBrowserContext() const {
return site_instance_->GetBrowserContext();
}
@@ -640,10 +648,15 @@
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
- case chrome::NOTIFICATION_EXTENSIONS_READY: {
- // TODO(jamescook): Convert this to use ExtensionSystem::ready() instead
- // of a notification.
- MaybeCreateStartupBackgroundHosts();
+ case chrome::NOTIFICATION_EXTENSIONS_READY:
+ case chrome::NOTIFICATION_PROFILE_CREATED: {
+ // Don't load background hosts now if the loading should be deferred.
+ // Instead they will be loaded when a browser window for this profile
+ // (or an incognito profile from this profile) is ready.
+ if (DeferLoadingBackgroundHosts())
+ break;
+
+ CreateBackgroundHostsForProfileStartup();
break;
}
@@ -771,24 +784,24 @@
}
}
-void ProcessManager::MaybeCreateStartupBackgroundHosts() {
- if (startup_background_hosts_created_)
+void ProcessManager::CreateBackgroundHostsForProfileStartup() {
+ if (startup_background_hosts_created_ ||
+ !ExtensionsBrowserClient::Get()->
+ IsBackgroundPageAllowed(GetBrowserContext())) {
return;
+ }
- // The embedder might disallow background pages entirely.
- ProcessManagerDelegate* delegate =
- ExtensionsBrowserClient::Get()->GetProcessManagerDelegate();
- if (delegate && !delegate->IsBackgroundPageAllowed(GetBrowserContext()))
- return;
+ const ExtensionSet& enabled_extensions =
+ ExtensionRegistry::Get(GetBrowserContext())->enabled_extensions();
+ for (ExtensionSet::const_iterator extension = enabled_extensions.begin();
+ extension != enabled_extensions.end();
+ ++extension) {
+ CreateBackgroundHostForExtensionLoad(this, extension->get());
- // The embedder might want to defer background page loading. For example,
- // Chrome defers background page loading when it is launched to show the app
- // list, then triggers a load later when a browser window opens.
- if (delegate &&
- delegate->DeferCreatingStartupBackgroundHosts(GetBrowserContext()))
- return;
-
- CreateStartupBackgroundHosts();
+ FOR_EACH_OBSERVER(ProcessManagerObserver,
+ observer_list_,
+ OnBackgroundHostStartup(*extension));
+ }
startup_background_hosts_created_ = true;
// Background pages should only be loaded once. To prevent any further loads
@@ -797,6 +810,14 @@
ExtensionsBrowserClient::Get()->GetOriginalContext(GetBrowserContext());
if (registrar_.IsRegistered(
this,
+ chrome::NOTIFICATION_PROFILE_CREATED,
+ content::Source<BrowserContext>(original_context))) {
+ registrar_.Remove(this,
+ chrome::NOTIFICATION_PROFILE_CREATED,
+ content::Source<BrowserContext>(original_context));
+ }
+ if (registrar_.IsRegistered(
+ this,
chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<BrowserContext>(original_context))) {
registrar_.Remove(this,
@@ -805,21 +826,6 @@
}
}
-void ProcessManager::CreateStartupBackgroundHosts() {
- DCHECK(!startup_background_hosts_created_);
- const ExtensionSet& enabled_extensions =
- ExtensionRegistry::Get(GetBrowserContext())->enabled_extensions();
- for (ExtensionSet::const_iterator extension = enabled_extensions.begin();
- extension != enabled_extensions.end();
- ++extension) {
- CreateBackgroundHostForExtensionLoad(this, extension->get());
-
- FOR_EACH_OBSERVER(ProcessManagerObserver,
- observer_list_,
- OnBackgroundHostStartup(*extension));
- }
-}
-
void ProcessManager::OnBackgroundHostCreated(ExtensionHost* host) {
DCHECK_EQ(GetBrowserContext(), host->browser_context());
background_hosts_.insert(host);
@@ -884,6 +890,12 @@
}
}
+bool ProcessManager::DeferLoadingBackgroundHosts() const {
+ // The extensions embedder may have special rules about background hosts.
+ return ExtensionsBrowserClient::Get()->DeferLoadingBackgroundHosts(
+ GetBrowserContext());
+}
+
//
// IncognitoProcessManager
//
@@ -902,6 +914,8 @@
// in the NOTIFICATION_BROWSER_WINDOW_READY notification handler.
registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY,
content::Source<BrowserContext>(original_context));
+ registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED,
+ content::Source<BrowserContext>(original_context));
}
bool IncognitoProcessManager::CreateBackgroundHost(const Extension* extension,
« no previous file with comments | « trunk/src/extensions/browser/process_manager.h ('k') | trunk/src/extensions/browser/process_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698