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