| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/extensions/chrome_process_manager_delegate.h" | 5 #include "chrome/browser/extensions/chrome_process_manager_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/extension_management.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 18 #include "components/user_manager/user_manager.h" | 17 #include "components/user_manager/user_manager.h" |
| 19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 20 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 21 #include "extensions/browser/process_manager.h" | 20 #include "extensions/browser/process_manager.h" |
| 22 #include "extensions/browser/process_manager_factory.h" | 21 #include "extensions/browser/process_manager_factory.h" |
| 23 #include "extensions/common/one_shot_event.h" | 22 #include "extensions/common/one_shot_event.h" |
| 24 | 23 |
| 25 #if defined(OS_CHROMEOS) | |
| 26 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 27 #endif | |
| 28 | |
| 29 namespace extensions { | 24 namespace extensions { |
| 30 | 25 |
| 31 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() { | 26 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() { |
| 32 registrar_.Add(this, | 27 registrar_.Add(this, |
| 33 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 28 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 34 content::NotificationService::AllSources()); | 29 content::NotificationService::AllSources()); |
| 35 registrar_.Add(this, | 30 registrar_.Add(this, |
| 36 chrome::NOTIFICATION_PROFILE_CREATED, | 31 chrome::NOTIFICATION_PROFILE_CREATED, |
| 37 content::NotificationService::AllSources()); | 32 content::NotificationService::AllSources()); |
| 38 registrar_.Add(this, | 33 registrar_.Add(this, |
| 39 chrome::NOTIFICATION_PROFILE_DESTROYED, | 34 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 40 content::NotificationService::AllSources()); | 35 content::NotificationService::AllSources()); |
| 41 } | 36 } |
| 42 | 37 |
| 43 ChromeProcessManagerDelegate::~ChromeProcessManagerDelegate() { | 38 ChromeProcessManagerDelegate::~ChromeProcessManagerDelegate() { |
| 44 } | 39 } |
| 45 | 40 |
| 46 bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed( | 41 bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed( |
| 47 content::BrowserContext* context) const { | 42 content::BrowserContext* context) const { |
| 48 Profile* profile = static_cast<Profile*>(context); | 43 Profile* profile = static_cast<Profile*>(context); |
| 49 | 44 |
| 50 bool is_normal_session = !profile->IsGuestSession() && | 45 bool is_normal_session = !profile->IsGuestSession() && |
| 51 !profile->IsSystemProfile(); | 46 !profile->IsSystemProfile(); |
| 52 bool allow_for_signin_profile = false; | |
| 53 | |
| 54 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 55 const bool is_signin_profile = | 48 is_normal_session = is_normal_session && |
| 56 chromeos::ProfileHelper::IsSigninProfile(profile); | 49 user_manager::UserManager::Get()->IsUserLoggedIn(); |
| 57 | |
| 58 if (is_signin_profile) { | |
| 59 const bool signin_apps_enabled = | |
| 60 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 61 switches::kEnableSigninApps); | |
| 62 const bool signin_apps_installed = | |
| 63 !ExtensionManagementFactory::GetForBrowserContext(context) | |
| 64 ->GetForceInstallList() | |
| 65 ->empty(); | |
| 66 allow_for_signin_profile = signin_apps_enabled && signin_apps_installed; | |
| 67 } else { | |
| 68 const bool user_logged_in = | |
| 69 user_manager::UserManager::Get()->IsUserLoggedIn(); | |
| 70 is_normal_session &= user_logged_in; | |
| 71 } | |
| 72 #endif | 50 #endif |
| 73 | 51 |
| 74 // Disallow if the current session is a Guest mode session or login screen but | 52 // Disallow if the current session is a Guest mode session or login screen but |
| 75 // the current browser context is *not* off-the-record. Such context is | 53 // the current browser context is *not* off-the-record. Such context is |
| 76 // artificial and background page shouldn't be created in it. | 54 // artificial and background page shouldn't be created in it. |
| 77 // http://crbug.com/329498 | 55 // http://crbug.com/329498 |
| 78 return is_normal_session || profile->IsOffTheRecord() || | 56 return is_normal_session || profile->IsOffTheRecord(); |
| 79 allow_for_signin_profile; | |
| 80 } | 57 } |
| 81 | 58 |
| 82 bool ChromeProcessManagerDelegate::DeferCreatingStartupBackgroundHosts( | 59 bool ChromeProcessManagerDelegate::DeferCreatingStartupBackgroundHosts( |
| 83 content::BrowserContext* context) const { | 60 content::BrowserContext* context) const { |
| 84 Profile* profile = static_cast<Profile*>(context); | 61 Profile* profile = static_cast<Profile*>(context); |
| 85 | 62 |
| 86 // The profile may not be valid yet if it is still being initialized. | 63 // The profile may not be valid yet if it is still being initialized. |
| 87 // In that case, defer loading, since it depends on an initialized profile. | 64 // In that case, defer loading, since it depends on an initialized profile. |
| 88 // Background hosts will be loaded later via NOTIFICATION_PROFILE_CREATED. | 65 // Background hosts will be loaded later via NOTIFICATION_PROFILE_CREATED. |
| 89 // http://crbug.com/222473 | 66 // http://crbug.com/222473 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 ProcessManager* incognito_manager = | 164 ProcessManager* incognito_manager = |
| 188 ProcessManagerFactory::GetForBrowserContextIfExists( | 165 ProcessManagerFactory::GetForBrowserContextIfExists( |
| 189 profile->GetOffTheRecordProfile()); | 166 profile->GetOffTheRecordProfile()); |
| 190 if (incognito_manager) { | 167 if (incognito_manager) { |
| 191 incognito_manager->CloseBackgroundHosts(); | 168 incognito_manager->CloseBackgroundHosts(); |
| 192 } | 169 } |
| 193 } | 170 } |
| 194 } | 171 } |
| 195 | 172 |
| 196 } // namespace extensions | 173 } // namespace extensions |
| OLD | NEW |