| 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,
|
|
|