summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/chrome_process_manager_delegate.cc
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 17:21:45 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-17 17:21:45 +0000
commit46a19f626f5794f298cd1e4d8bdcbfcb07fd0b4e (patch)
tree5a04abc6c4c823a4ddf1ca0d76fcc1ea47ff009a /chrome/browser/extensions/chrome_process_manager_delegate.cc
parentdddea5bb5ab70ac91118754eb09ccb30dcb178a2 (diff)
downloadchromium_src-46a19f626f5794f298cd1e4d8bdcbfcb07fd0b4e.zip
chromium_src-46a19f626f5794f298cd1e4d8bdcbfcb07fd0b4e.tar.gz
chromium_src-46a19f626f5794f298cd1e4d8bdcbfcb07fd0b4e.tar.bz2
Revert 283678 "Refactor code that defers extension background pa..."
This broke Chrome OS valgrind bots, for example: http://build.chromium.org/p/chromium.memory.fyi/builders/Chromium%20OS%20%28valgrind%29%284%29/builds/27033 > Refactor code that defers extension background page loading > > src/extensions depends on chrome::NOTIFICATION_PROFILE_CREATED to support deferred loading of extension background pages when the profile isn't ready yet. This is a layering violation. > > * Remove Chrome concepts like "browser window ready" and "profile created" from ProcessManager. Introduce ProcessManagerDelegate with a general concept of deferring background page loading. > * Consolidate all the tricky Chrome-specific background page loading rules into ChromeProcessManagerDelegate. This keeps all the rules in one place. Annotate each block of special case code with the bug that inspired it. > * Extend unit test coverage for ProcessManager. > > This will make it easier to eliminate chrome::NOTIFICATION_PROFILE_DESTROYED in ProcessManager in a later CL. > > BUG=392658 > TEST=unit_tests ProcessManagerTest, browser_tests ProcessManagerBrowserTest, manual > > Review URL: https://codereview.chromium.org/381283002 TBR=jamescook@chromium.org Review URL: https://codereview.chromium.org/399153002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283801 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/chrome_process_manager_delegate.cc')
-rw-r--r--chrome/browser/extensions/chrome_process_manager_delegate.cc143
1 files changed, 0 insertions, 143 deletions
diff --git a/chrome/browser/extensions/chrome_process_manager_delegate.cc b/chrome/browser/extensions/chrome_process_manager_delegate.cc
deleted file mode 100644
index 12e0c16..0000000
--- a/chrome/browser/extensions/chrome_process_manager_delegate.cc
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/extensions/chrome_process_manager_delegate.h"
-
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/ui/browser.h"
-#include "content/public/browser/notification_service.h"
-#include "extensions/browser/extension_system.h"
-#include "extensions/browser/process_manager.h"
-#include "extensions/common/one_shot_event.h"
-
-#if !defined(OS_ANDROID)
-#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/common/chrome_switches.h"
-#endif
-
-namespace extensions {
-
-ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() {
- registrar_.Add(this,
- chrome::NOTIFICATION_BROWSER_WINDOW_READY,
- content::NotificationService::AllSources());
- registrar_.Add(this,
- chrome::NOTIFICATION_PROFILE_CREATED,
- content::NotificationService::AllSources());
- // TODO(jamescook): Move observation of NOTIFICATION_PROFILE_DESTROYED here.
- // http://crbug.com/392658
-}
-
-ChromeProcessManagerDelegate::~ChromeProcessManagerDelegate() {
-}
-
-bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed(
- content::BrowserContext* context) const {
- Profile* profile = static_cast<Profile*>(context);
-
- // Disallow if the current session is a Guest mode session but the current
- // browser context is *not* off-the-record. Such context is artificial and
- // background page shouldn't be created in it.
- // http://crbug.com/329498
- return !(profile->IsGuestSession() && !profile->IsOffTheRecord());
-}
-
-bool ChromeProcessManagerDelegate::DeferCreatingStartupBackgroundHosts(
- content::BrowserContext* context) const {
- Profile* profile = static_cast<Profile*>(context);
-
- // The profile may not be valid yet if it is still being initialized.
- // In that case, defer loading, since it depends on an initialized profile.
- // Background hosts will be loaded later via NOTIFICATION_PROFILE_CREATED.
- // http://crbug.com/222473
- if (!g_browser_process->profile_manager()->IsValidProfile(profile))
- return true;
-
-#if defined(OS_ANDROID)
- return false;
-#else
- // There are no browser windows open and the browser process was
- // started to show the app launcher. Background hosts will be loaded later
- // via NOTIFICATION_BROWSER_WINDOW_READY. http://crbug.com/178260
- return chrome::GetTotalBrowserCountForProfile(profile) == 0 &&
- CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList);
-#endif
-}
-
-void ChromeProcessManagerDelegate::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
- Browser* browser = content::Source<Browser>(source).ptr();
- OnBrowserWindowReady(browser);
- break;
- }
- case chrome::NOTIFICATION_PROFILE_CREATED: {
- Profile* profile = content::Source<Profile>(source).ptr();
- OnProfileCreated(profile);
- break;
- }
-
- default:
- NOTREACHED();
- }
-}
-
-void ChromeProcessManagerDelegate::OnBrowserWindowReady(Browser* browser) {
- Profile* profile = browser->profile();
- DCHECK(profile);
-
- // If the extension system isn't ready yet the background hosts will be
- // created automatically when it is.
- ExtensionSystem* system = ExtensionSystem::Get(profile);
- if (!system->ready().is_signaled())
- return;
-
- // Inform the process manager for this profile that the window is ready.
- // We continue to observe the notification in case browser windows open for
- // a related incognito profile or other regular profiles.
- ProcessManager* manager = system->process_manager();
- if (!manager) // Tests may not have a process manager.
- return;
- DCHECK_EQ(profile, manager->GetBrowserContext());
- manager->MaybeCreateStartupBackgroundHosts();
-
- // For incognito profiles also inform the original profile's process manager
- // that the window is ready. This will usually be a no-op because the
- // original profile's process manager should have been informed when the
- // non-incognito window opened.
- if (profile->IsOffTheRecord()) {
- Profile* original_profile = profile->GetOriginalProfile();
- ProcessManager* original_manager =
- ExtensionSystem::Get(original_profile)->process_manager();
- DCHECK(original_manager);
- DCHECK_EQ(original_profile, original_manager->GetBrowserContext());
- original_manager->MaybeCreateStartupBackgroundHosts();
- }
-}
-
-void ChromeProcessManagerDelegate::OnProfileCreated(Profile* profile) {
- // Incognito profiles are handled by their original profile.
- if (profile->IsOffTheRecord())
- return;
-
- // The profile can be created before the extension system is ready.
- ProcessManager* manager = ExtensionSystem::Get(profile)->process_manager();
- if (!manager)
- return;
-
- // The profile might have been initialized asynchronously (in parallel with
- // extension system startup). Now that initialization is complete the
- // ProcessManager can load deferred background pages.
- manager->MaybeCreateStartupBackgroundHosts();
-}
-
-} // namespace extensions