Chromium Code Reviews| Index: chrome/browser/chromeos/login/session/chrome_session_manager.cc |
| diff --git a/chrome/browser/chromeos/login/session/chrome_session_manager.cc b/chrome/browser/chromeos/login/session/chrome_session_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3fe4227f79674178e42312ec6155b2bd85f8a248 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/session/chrome_session_manager.cc |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/login/session/chrome_session_manager.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/sys_info.h" |
| +#include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" |
| +#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| +#include "chrome/browser/chromeos/login/session/kiosk_auto_launcher_session_manager_delegate.h" |
| +#include "chrome/browser/chromeos/login/session/login_oobe_session_manager_delegate.h" |
| +#include "chrome/browser/chromeos/login/session/restore_after_crash_session_manager_delegate.h" |
| +#include "chrome/browser/chromeos/login/session/stub_login_session_manager_delegate.h" |
| +#include "chrome/browser/chromeos/login/users/user_manager.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chromeos/chromeos_switches.h" |
| +#include "chromeos/login/user_names.h" |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| + |
| +bool ShouldAutoLaunchKioskApp(const base::CommandLine& command_line) { |
| + KioskAppManager* app_manager = KioskAppManager::Get(); |
| + return command_line.HasSwitch(switches::kLoginManager) && |
| + !command_line.HasSwitch( |
| + switches::kForceLoginManagerInTests) && |
| + app_manager->IsAutoLaunchEnabled() && |
| + KioskAppLaunchError::Get() == |
| + KioskAppLaunchError::NONE; |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +scoped_ptr<session_manager::SessionManager> |
| +ChromeSessionManager::CreateSessionManager( |
| + const base::CommandLine& parsed_command_line, |
| + Profile* profile, |
| + bool is_running_test) { |
| + // Tests should be able to tune login manager before showing it. Thus only |
| + // show login UI (login and out-of-box) in normal (non-testing) mode with |
| + // --login-manager switch and if test passed --force-login-manager-in-tests. |
| + bool force_login_screen_in_test = parsed_command_line.HasSwitch( |
| + switches::kForceLoginManagerInTests); |
| + |
| + // If kLoginUser is passed this indicates that user has already |
| + // logged in and we should behave accordingly. |
| + bool immediate_login = |
| + parsed_command_line.HasSwitch(switches::kLoginUser); |
| + |
| + std::string login_user_id = |
| + parsed_command_line.GetSwitchValueASCII(switches::kLoginUser); |
| + |
| + if (ShouldAutoLaunchKioskApp(parsed_command_line)) { |
| + VLOG(1) << "Starting Chrome with KioskAutoLauncherSessionManagerDelegate"; |
| + return scoped_ptr<session_manager::SessionManager>( |
| + new ChromeSessionManager( |
| + new KioskAutoLauncherSessionManagerDelegate())); |
| + } else if (parsed_command_line.HasSwitch(switches::kLoginManager) && |
| + (!is_running_test || force_login_screen_in_test)) { |
| + VLOG(1) << "Starting Chrome with LoginOobeSessionManagerDelegate"; |
| + return scoped_ptr<session_manager::SessionManager>( |
| + new ChromeSessionManager( |
| + new LoginOobeSessionManagerDelegate())); |
| + } else if (!base::SysInfo::IsRunningOnChromeOS() && |
| + login_user_id == login::kStubUser) { |
| + VLOG(1) << "Starting Chrome with StubLoginSessionManagerDelegate"; |
| + return scoped_ptr<session_manager::SessionManager>( |
| + new ChromeSessionManager( |
| + new StubLoginSessionManagerDelegate(profile, |
| + login_user_id))); |
|
oshima
2014/07/14 20:03:53
indent. (or git cl format)
Nikita (slow)
2014/07/15 10:18:42
Done.
|
| + } else if (immediate_login) { |
| + VLOG(1) << "Starting Chrome with RestoreAfterCrashSessionManagerDelegate"; |
| + // Restarting Chrome inside existing user session. Possible cases: |
| + // 1. Chrome is restarted after crash. |
| + // 2. Chrome is started in browser_tests skipping the login flow. |
| + // 3. Chrome is started on dev machine i.e. not on Chrome OS device w/o |
| + // login flow. In that case --login-user=[chromeos::login::kStubUser] is |
| + // added. See PreEarlyInitialization(). |
| + return scoped_ptr<session_manager::SessionManager>( |
| + new ChromeSessionManager( |
| + new RestoreAfterCrashSessionManagerDelegate( |
| + profile, login_user_id))); |
| + } else { |
|
oshima
2014/07/14 20:03:53
nit: you can omit this else.
|
| + VLOG(1) << "Starting Chrome with StubLoginSessionManagerDelegate"; |
| + return scoped_ptr<session_manager::SessionManager>( |
| + new ChromeSessionManager( |
| + new StubLoginSessionManagerDelegate(profile, |
| + login_user_id))); |
| + } |
| +} |
| + |
| +ChromeSessionManager::ChromeSessionManager( |
| + session_manager::SessionManagerDelegate* delegate) { |
| + Initialize(delegate); |
| +} |
| + |
| +ChromeSessionManager::~ChromeSessionManager() { |
| +} |
| + |
| +} // namespace chromeos |