Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / login / session / chrome_session_manager.cc
blob34258c11804c3ccc8825247851d93856d7f266fe
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.
5 #include "chrome/browser/chromeos/login/session/chrome_session_manager.h"
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_manager_delegate.h"
14 #include "chrome/browser/chromeos/login/session/login_oobe_session_manager_delegate.h"
15 #include "chrome/browser/chromeos/login/session/restore_after_crash_session_manager_delegate.h"
16 #include "chrome/browser/chromeos/login/session/stub_login_session_manager_delegate.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chromeos/chromeos_switches.h"
19 #include "chromeos/login/user_names.h"
21 namespace chromeos {
23 namespace {
25 bool ShouldAutoLaunchKioskApp(const base::CommandLine& command_line) {
26 KioskAppManager* app_manager = KioskAppManager::Get();
27 return command_line.HasSwitch(switches::kLoginManager) &&
28 !command_line.HasSwitch(switches::kForceLoginManagerInTests) &&
29 app_manager->IsAutoLaunchEnabled() &&
30 KioskAppLaunchError::Get() == KioskAppLaunchError::NONE;
33 } // namespace
35 // static
36 scoped_ptr<session_manager::SessionManager>
37 ChromeSessionManager::CreateSessionManager(
38 const base::CommandLine& parsed_command_line,
39 Profile* profile,
40 bool is_running_test) {
41 // Tests should be able to tune login manager before showing it. Thus only
42 // show login UI (login and out-of-box) in normal (non-testing) mode with
43 // --login-manager switch and if test passed --force-login-manager-in-tests.
44 bool force_login_screen_in_test =
45 parsed_command_line.HasSwitch(switches::kForceLoginManagerInTests);
47 std::string login_user_id =
48 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser);
50 KioskAppManager::RemoveObsoleteCryptohomes();
52 if (ShouldAutoLaunchKioskApp(parsed_command_line)) {
53 VLOG(1) << "Starting Chrome with KioskAutoLauncherSessionManagerDelegate";
54 return scoped_ptr<session_manager::SessionManager>(new ChromeSessionManager(
55 new KioskAutoLauncherSessionManagerDelegate()));
56 } else if (parsed_command_line.HasSwitch(switches::kLoginManager) &&
57 (!is_running_test || force_login_screen_in_test)) {
58 VLOG(1) << "Starting Chrome with LoginOobeSessionManagerDelegate";
59 return scoped_ptr<session_manager::SessionManager>(
60 new ChromeSessionManager(new LoginOobeSessionManagerDelegate()));
61 } else if (!base::SysInfo::IsRunningOnChromeOS() &&
62 login_user_id == login::kStubUser) {
63 VLOG(1) << "Starting Chrome with StubLoginSessionManagerDelegate";
64 return scoped_ptr<session_manager::SessionManager>(new ChromeSessionManager(
65 new StubLoginSessionManagerDelegate(profile, login_user_id)));
66 } else {
67 VLOG(1) << "Starting Chrome with RestoreAfterCrashSessionManagerDelegate";
68 // Restarting Chrome inside existing user session. Possible cases:
69 // 1. Chrome is restarted after crash.
70 // 2. Chrome is restarted for Guest session.
71 // 3. Chrome is started in browser_tests skipping the login flow.
72 // 4. Chrome is started on dev machine i.e. not on Chrome OS device w/o
73 // login flow. In that case --login-user=[chromeos::login::kStubUser] is
74 // added. See PreEarlyInitialization().
75 return scoped_ptr<session_manager::SessionManager>(new ChromeSessionManager(
76 new RestoreAfterCrashSessionManagerDelegate(profile, login_user_id)));
80 ChromeSessionManager::ChromeSessionManager(
81 session_manager::SessionManagerDelegate* delegate) {
82 Initialize(delegate);
85 ChromeSessionManager::~ChromeSessionManager() {
88 } // namespace chromeos