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( | |
30 switches::kForceLoginManagerInTests) && | |
31 app_manager->IsAutoLaunchEnabled() && | |
32 KioskAppLaunchError::Get() == | |
33 KioskAppLaunchError::NONE; | |
34 } | |
35 | |
36 } // namespace | |
37 | |
38 // static | |
39 scoped_ptr<session_manager::SessionManager> | |
40 ChromeSessionManager::CreateSessionManager( | |
41 const base::CommandLine& parsed_command_line, | |
42 Profile* profile, | |
43 bool is_running_test) { | |
44 // Tests should be able to tune login manager before showing it. Thus only | |
45 // show login UI (login and out-of-box) in normal (non-testing) mode with | |
46 // --login-manager switch and if test passed --force-login-manager-in-tests. | |
47 bool force_login_screen_in_test = parsed_command_line.HasSwitch( | |
48 switches::kForceLoginManagerInTests); | |
49 | |
50 // If kLoginUser is passed this indicates that user has already | |
51 // logged in and we should behave accordingly. | |
52 bool immediate_login = | |
53 parsed_command_line.HasSwitch(switches::kLoginUser); | |
54 | |
55 std::string login_user_id = | |
56 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser); | |
57 | |
58 if (ShouldAutoLaunchKioskApp(parsed_command_line)) { | |
59 VLOG(1) << "Starting Chrome with KioskAutoLauncherSessionManagerDelegate"; | |
60 return scoped_ptr<session_manager::SessionManager>( | |
61 new ChromeSessionManager( | |
62 new KioskAutoLauncherSessionManagerDelegate())); | |
63 } else if (parsed_command_line.HasSwitch(switches::kLoginManager) && | |
64 (!is_running_test || force_login_screen_in_test)) { | |
65 VLOG(1) << "Starting Chrome with LoginOobeSessionManagerDelegate"; | |
66 return scoped_ptr<session_manager::SessionManager>( | |
67 new ChromeSessionManager( | |
68 new LoginOobeSessionManagerDelegate())); | |
69 } else if (!base::SysInfo::IsRunningOnChromeOS() && | |
70 login_user_id == login::kStubUser) { | |
71 VLOG(1) << "Starting Chrome with StubLoginSessionManagerDelegate"; | |
72 return scoped_ptr<session_manager::SessionManager>( | |
73 new ChromeSessionManager( | |
74 new StubLoginSessionManagerDelegate(profile, | |
75 login_user_id))); | |
oshima
2014/07/14 20:03:53
indent. (or git cl format)
Nikita (slow)
2014/07/15 10:18:42
Done.
| |
76 } else if (immediate_login) { | |
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 started in browser_tests skipping the login flow. | |
81 // 3. Chrome is started on dev machine i.e. not on Chrome OS device w/o | |
82 // login flow. In that case --login-user=[chromeos::login::kStubUser] is | |
83 // added. See PreEarlyInitialization(). | |
84 return scoped_ptr<session_manager::SessionManager>( | |
85 new ChromeSessionManager( | |
86 new RestoreAfterCrashSessionManagerDelegate( | |
87 profile, login_user_id))); | |
88 } else { | |
oshima
2014/07/14 20:03:53
nit: you can omit this else.
| |
89 VLOG(1) << "Starting Chrome with StubLoginSessionManagerDelegate"; | |
90 return scoped_ptr<session_manager::SessionManager>( | |
91 new ChromeSessionManager( | |
92 new StubLoginSessionManagerDelegate(profile, | |
93 login_user_id))); | |
94 } | |
95 } | |
96 | |
97 ChromeSessionManager::ChromeSessionManager( | |
98 session_manager::SessionManagerDelegate* delegate) { | |
99 Initialize(delegate); | |
100 } | |
101 | |
102 ChromeSessionManager::~ChromeSessionManager() { | |
103 } | |
104 | |
105 } // namespace chromeos | |
OLD | NEW |