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