| 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/chromeos/login/session/chrome_session_manager.h" | 5 #include "chrome/browser/chromeos/login/session/chrome_session_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" | 13 #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
| 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 14 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 15 #include "chrome/browser/chromeos/login/session/kiosk_auto_launcher_session_mana
ger_delegate.h" | 15 #include "chrome/browser/chromeos/login/session/kiosk_auto_launcher_session_init
ializer.h" |
| 16 #include "chrome/browser/chromeos/login/session/login_oobe_session_manager_deleg
ate.h" | 16 #include "chrome/browser/chromeos/login/session/login_oobe_session_initializer.h
" |
| 17 #include "chrome/browser/chromeos/login/session/restore_after_crash_session_mana
ger_delegate.h" | 17 #include "chrome/browser/chromeos/login/session/restore_after_crash_session_init
ializer.h" |
| 18 #include "chrome/browser/chromeos/login/session/stub_login_session_manager_deleg
ate.h" | 18 #include "chrome/browser/chromeos/login/session/stub_session_initializer.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/cryptohome/cryptohome_parameters.h" | 21 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 22 #include "chromeos/login/user_names.h" | 22 #include "chromeos/login/user_names.h" |
| 23 #include "components/signin/core/account_id/account_id.h" | 23 #include "components/signin/core/account_id/account_id.h" |
| 24 #include "components/user_manager/user_manager.h" | 24 #include "components/user_manager/user_manager.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 | 26 |
| 27 namespace chromeos { | 27 namespace chromeos { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 bool ShouldAutoLaunchKioskApp(const base::CommandLine& command_line) { | 31 bool ShouldAutoLaunchKioskApp(const base::CommandLine& command_line) { |
| 32 KioskAppManager* app_manager = KioskAppManager::Get(); | 32 KioskAppManager* app_manager = KioskAppManager::Get(); |
| 33 return command_line.HasSwitch(switches::kLoginManager) && | 33 return command_line.HasSwitch(switches::kLoginManager) && |
| 34 !command_line.HasSwitch(switches::kForceLoginManagerInTests) && | 34 !command_line.HasSwitch(switches::kForceLoginManagerInTests) && |
| 35 app_manager->IsAutoLaunchEnabled() && | 35 app_manager->IsAutoLaunchEnabled() && |
| 36 KioskAppLaunchError::Get() == KioskAppLaunchError::NONE; | 36 KioskAppLaunchError::Get() == KioskAppLaunchError::NONE; |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 // static | 41 ChromeSessionManager::ChromeSessionManager() {} |
| 42 std::unique_ptr<session_manager::SessionManager> | 42 ChromeSessionManager::~ChromeSessionManager() {} |
| 43 ChromeSessionManager::CreateSessionManager( | 43 |
| 44 void ChromeSessionManager::Initialize( |
| 44 const base::CommandLine& parsed_command_line, | 45 const base::CommandLine& parsed_command_line, |
| 45 Profile* profile, | 46 Profile* profile, |
| 46 bool is_running_test) { | 47 bool is_running_test) { |
| 47 // Tests should be able to tune login manager before showing it. Thus only | 48 // Tests should be able to tune login manager before showing it. Thus only |
| 48 // show login UI (login and out-of-box) in normal (non-testing) mode with | 49 // show login UI (login and out-of-box) in normal (non-testing) mode with |
| 49 // --login-manager switch and if test passed --force-login-manager-in-tests. | 50 // --login-manager switch and if test passed --force-login-manager-in-tests. |
| 50 bool force_login_screen_in_test = | 51 bool force_login_screen_in_test = |
| 51 parsed_command_line.HasSwitch(switches::kForceLoginManagerInTests); | 52 parsed_command_line.HasSwitch(switches::kForceLoginManagerInTests); |
| 52 | 53 |
| 53 const std::string cryptohome_id = | 54 const std::string cryptohome_id = |
| 54 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser); | 55 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser); |
| 55 const AccountId login_account_id( | 56 const AccountId login_account_id( |
| 56 cryptohome::Identification::FromString(cryptohome_id).GetAccountId()); | 57 cryptohome::Identification::FromString(cryptohome_id).GetAccountId()); |
| 57 | 58 |
| 58 KioskAppManager::RemoveObsoleteCryptohomes(); | 59 KioskAppManager::RemoveObsoleteCryptohomes(); |
| 59 | 60 |
| 60 if (ShouldAutoLaunchKioskApp(parsed_command_line)) { | 61 if (ShouldAutoLaunchKioskApp(parsed_command_line)) { |
| 61 VLOG(1) << "Starting Chrome with KioskAutoLauncherSessionManagerDelegate"; | 62 VLOG(1) << "Starting Chrome with KioskAutoLauncherSessionInitializer"; |
| 62 return std::unique_ptr<session_manager::SessionManager>( | 63 KioskAutoLauncherSessionInitializer().Start(); |
| 63 new ChromeSessionManager( | 64 return; |
| 64 new KioskAutoLauncherSessionManagerDelegate())); | |
| 65 } else if (parsed_command_line.HasSwitch(switches::kLoginManager) && | |
| 66 (!is_running_test || force_login_screen_in_test)) { | |
| 67 VLOG(1) << "Starting Chrome with LoginOobeSessionManagerDelegate"; | |
| 68 return std::unique_ptr<session_manager::SessionManager>( | |
| 69 new ChromeSessionManager(new LoginOobeSessionManagerDelegate())); | |
| 70 } else if (!base::SysInfo::IsRunningOnChromeOS() && | |
| 71 login_account_id == login::StubAccountId()) { | |
| 72 VLOG(1) << "Starting Chrome with StubLoginSessionManagerDelegate"; | |
| 73 return std::unique_ptr<session_manager::SessionManager>( | |
| 74 new ChromeSessionManager(new StubLoginSessionManagerDelegate( | |
| 75 profile, login_account_id.GetUserEmail()))); | |
| 76 } else { | |
| 77 VLOG(1) << "Starting Chrome with RestoreAfterCrashSessionManagerDelegate"; | |
| 78 // Restarting Chrome inside existing user session. Possible cases: | |
| 79 // 1. Chrome is restarted after crash. | |
| 80 // 2. Chrome is restarted for Guest session. | |
| 81 // 3. Chrome is started in browser_tests skipping the login flow. | |
| 82 // 4. Chrome is started on dev machine i.e. not on Chrome OS device w/o | |
| 83 // login flow. In that case --login-user=[chromeos::login::kStubUser] is | |
| 84 // added. See PreEarlyInitialization(). | |
| 85 return std::unique_ptr<session_manager::SessionManager>( | |
| 86 new ChromeSessionManager(new RestoreAfterCrashSessionManagerDelegate( | |
| 87 profile, login_account_id.GetUserEmail()))); | |
| 88 } | 65 } |
| 89 } | |
| 90 | 66 |
| 91 ChromeSessionManager::ChromeSessionManager( | 67 if (parsed_command_line.HasSwitch(switches::kLoginManager) && |
| 92 session_manager::SessionManagerDelegate* delegate) { | 68 (!is_running_test || force_login_screen_in_test)) { |
| 93 Initialize(delegate); | 69 VLOG(1) << "Starting Chrome with LoginOobeSessionInitializer"; |
| 94 } | 70 LoginOobeSessionInitializer().Start(); |
| 71 return; |
| 72 } |
| 95 | 73 |
| 96 ChromeSessionManager::~ChromeSessionManager() { | 74 if (!base::SysInfo::IsRunningOnChromeOS() && |
| 75 login_account_id == login::StubAccountId()) { |
| 76 VLOG(1) << "Starting Chrome with StubSessionInitializer"; |
| 77 StubSessionInitializer(profile, login_account_id.GetUserEmail()).Start(); |
| 78 return; |
| 79 } |
| 80 |
| 81 VLOG(1) << "Starting Chrome with RestoreAfterCrashSessionInitializer"; |
| 82 // Restarting Chrome inside existing user session. Possible cases: |
| 83 // 1. Chrome is restarted after crash. |
| 84 // 2. Chrome is restarted for Guest session. |
| 85 // 3. Chrome is started in browser_tests skipping the login flow. |
| 86 // 4. Chrome is started on dev machine i.e. not on Chrome OS device w/o |
| 87 // login flow. In that case --login-user=[chromeos::login::kStubUser] is |
| 88 // added. See PreEarlyInitialization(). |
| 89 RestoreAfterCrashSessionInitializer(profile, login_account_id.GetUserEmail()) |
| 90 .Start(); |
| 97 } | 91 } |
| 98 | 92 |
| 99 void ChromeSessionManager::SessionStarted() { | 93 void ChromeSessionManager::SessionStarted() { |
| 100 session_manager::SessionManager::SessionStarted(); | 94 session_manager::SessionManager::SessionStarted(); |
| 101 SetSessionState(session_manager::SessionState::ACTIVE); | 95 SetSessionState(session_manager::SessionState::ACTIVE); |
| 102 | 96 |
| 103 // Notifies UserManager so that it can update login state. | 97 // Notifies UserManager so that it can update login state. |
| 104 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 98 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 105 if (user_manager) | 99 if (user_manager) |
| 106 user_manager->OnSessionStarted(); | 100 user_manager->OnSessionStarted(); |
| 107 | 101 |
| 108 content::NotificationService::current()->Notify( | 102 content::NotificationService::current()->Notify( |
| 109 chrome::NOTIFICATION_SESSION_STARTED, | 103 chrome::NOTIFICATION_SESSION_STARTED, |
| 110 content::Source<session_manager::SessionManager>(this), | 104 content::Source<session_manager::SessionManager>(this), |
| 111 content::Details<const user_manager::User>( | 105 content::Details<const user_manager::User>( |
| 112 user_manager->GetActiveUser())); | 106 user_manager->GetActiveUser())); |
| 113 } | 107 } |
| 114 | 108 |
| 115 } // namespace chromeos | 109 } // namespace chromeos |
| OLD | NEW |