[cros] Define session_manager component with SessionManager base class

SessionManager is responsible for performing Chrome OS-specific steps to re-launch user session (after crash/stub or in tests) or pre-session UI such as out-of-box or login.

ChromeSessionManager is chrome/browser implementation of SessionManager.

SessionManager is initialized with specific delegate that is reponsible for initial behavior. These delegates are introduced, see ChromeSessionManager::CreateSessionManager():

* LoginOobeSessionManagerDelegate - launches either out-of-box or login UI,
actual branching still happens in ShowLoginWizard()

* RestoreAfterCrashSessionManagerDelegate - responsible for re-launching Chrome into existing user session,
happens after browser process crash or in "stub user" session.

* StubLoginSessionManagerDelegate - starts "stub user" session, when executed on non-CrOS machine w/o parameters or in tests. Extends RestoreAfterCrashSessionManagerDelegate.

* KioskAutoLauncherSessionManagerDelegate - automatically starts kiosk app session.

Code move in ChromeBrowserMainPartsChromeos:
* OptionallyRunChromeOSLoginManager() -> ChromeSessionManager::CreateSessionManager()
* RunAutoLaunchKioskApp() -> KioskAutoLauncherSessionManagerDelegate
* Session restore code in PostProfileInit() -> RestoreAfterCrashSessionManagerDelegate
* Blocks in OptionallyRunChromeOSLoginManager -> to delegates.

BUG=387610

Review URL: https://codereview.chromium.org/363613004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283437 0039d316-1c4b-4281-b951-d872f2087c98
parent e9931bb5
......@@ -48,6 +48,7 @@ include_rules = [
"+components/rappor",
"+components/search_engines",
"+components/search_provider_logos",
"+components/session_manager",
"+components/sessions",
"+components/signin",
"+components/startup_metric_utils",
......
......@@ -4,14 +4,18 @@
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/session/chrome_session_manager.h"
#include "chrome/browser/chromeos/memory/oom_priority_manager.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "components/session_manager/core/session_manager.h"
BrowserProcessPlatformPart::BrowserProcessPlatformPart()
: created_profile_helper_(false) {
......@@ -31,6 +35,24 @@ void BrowserProcessPlatformPart::ShutdownAutomaticRebootManager() {
automatic_reboot_manager_.reset();
}
void BrowserProcessPlatformPart::InitializeSessionManager(
const base::CommandLine& parsed_command_line,
Profile* profile,
bool is_running_test) {
DCHECK(!session_manager_);
session_manager_ = chromeos::ChromeSessionManager::CreateSessionManager(
parsed_command_line, profile, is_running_test);
}
void BrowserProcessPlatformPart::ShutdownSessionManager() {
session_manager_.reset();
}
session_manager::SessionManager* BrowserProcessPlatformPart::SessionManager() {
DCHECK(CalledOnValidThread());
return session_manager_.get();
}
chromeos::OomPriorityManager*
BrowserProcessPlatformPart::oom_priority_manager() {
DCHECK(CalledOnValidThread());
......
......@@ -10,6 +10,10 @@
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/browser_process_platform_part_base.h"
namespace base {
class CommandLine;
}
namespace chromeos {
class OomPriorityManager;
class ProfileHelper;
......@@ -26,6 +30,12 @@ class BrowserPolicyConnector;
class BrowserPolicyConnectorChromeOS;
}
namespace session_manager {
class SessionManager;
}
class Profile;
class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase,
public base::NonThreadSafe {
public:
......@@ -35,6 +45,16 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase,
void InitializeAutomaticRebootManager();
void ShutdownAutomaticRebootManager();
void InitializeSessionManager(const base::CommandLine& parsed_command_line,
Profile* profile,
bool is_running_test);
void ShutdownSessionManager();
// Returns the SessionManager instance that is used to initialize and
// start user sessions as well as responsible on launching pre-session UI like
// out-of-box or login.
virtual session_manager::SessionManager* SessionManager();
// Returns the out-of-memory priority manager.
// Virtual for testing (see TestingBrowserProcessPlatformPart).
virtual chromeos::OomPriorityManager* oom_priority_manager();
......@@ -50,7 +70,7 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase,
policy::BrowserPolicyConnectorChromeOS* browser_policy_connector_chromeos();
// Overridden from BrowserProcessPlatformPartBase:
virtual void StartTearDown() OVERRIDE;
virtual void StartTearDown() OVERRIDE;
virtual scoped_ptr<policy::BrowserPolicyConnector>
CreateBrowserPolicyConnector() OVERRIDE;
......@@ -58,6 +78,8 @@ class BrowserProcessPlatformPart : public BrowserProcessPlatformPartBase,
private:
void CreateProfileHelper();
scoped_ptr<session_manager::SessionManager> session_manager_;
bool created_profile_helper_;
scoped_ptr<chromeos::ProfileHelper> profile_helper_;
......
......@@ -103,6 +103,7 @@
#include "chromeos/system/statistics_provider.h"
#include "chromeos/tpm_token_loader.h"
#include "components/metrics/metrics_service.h"
#include "components/session_manager/core/session_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/power_save_blocker.h"
......@@ -130,9 +131,7 @@ void ChromeOSVersionCallback(const std::string& version) {
base::SetLinuxDistro(std::string("CrOS ") + version);
}
// Login -----------------------------------------------------------------------
bool ShouldAutoLaunchKioskApp(const CommandLine& command_line) {
bool ShouldAutoLaunchKioskApp(const base::CommandLine& command_line) {
KioskAppManager* app_manager = KioskAppManager::Get();
return command_line.HasSwitch(switches::kLoginManager) &&
!command_line.HasSwitch(switches::kForceLoginManagerInTests) &&
......@@ -140,52 +139,6 @@ bool ShouldAutoLaunchKioskApp(const CommandLine& command_line) {
KioskAppLaunchError::Get() == KioskAppLaunchError::NONE;
}
void RunAutoLaunchKioskApp() {
ShowLoginWizard(chromeos::WizardController::kAppLaunchSplashScreenName);
// Login screen is skipped but 'login-prompt-visible' signal is still needed.
VLOG(1) << "Kiosk app auto launch >> login-prompt-visible";
DBusThreadManager::Get()->GetSessionManagerClient()->
EmitLoginPromptVisible();
}
void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line,
Profile* profile) {
std::string login_user = parsed_command_line.
GetSwitchValueASCII(chromeos::switches::kLoginUser);
if (!base::SysInfo::IsRunningOnChromeOS() &&
login_user == chromeos::login::kStubUser) {
return;
}
if (ShouldAutoLaunchKioskApp(parsed_command_line)) {
RunAutoLaunchKioskApp();
} else if (parsed_command_line.HasSwitch(switches::kLoginManager)) {
ShowLoginWizard(std::string());
if (KioskModeSettings::Get()->IsKioskModeEnabled())
InitializeKioskModeScreensaver();
// Reset reboot after update flag when login screen is shown.
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (!connector->IsEnterpriseManaged()) {
PrefService* local_state = g_browser_process->local_state();
local_state->ClearPref(prefs::kRebootAfterUpdate);
}
} else {
if (!parsed_command_line.HasSwitch(::switches::kTestName)) {
// Enable CrasAudioHandler logging when chrome restarts after crashing.
if (chromeos::CrasAudioHandler::IsInitialized())
chromeos::CrasAudioHandler::Get()->LogErrors();
// We did not log in (we crashed or are debugging), so we need to
// restore Sync.
UserSessionManager::GetInstance()->RestoreAuthenticationSession(profile);
}
}
}
} // namespace
namespace internal {
......@@ -557,48 +510,11 @@ void ChromeBrowserMainPartsChromeos::PostProfileInit() {
BootTimesLoader::Get()->OnChromeProcessStart();
// 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().
if (parsed_command_line().HasSwitch(switches::kLoginUser)) {
std::string login_user = login::CanonicalizeUserID(
parsed_command_line().GetSwitchValueASCII(
chromeos::switches::kLoginUser));
if (!base::SysInfo::IsRunningOnChromeOS() &&
login_user == chromeos::login::kStubUser) {
// For dev machines and stub user emulate as if sync has been initialized.
profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
login_user);
}
// This is done in SessionManager::OnProfileCreated during normal login.
UserSessionManager::GetInstance()->InitRlz(profile());
// Send the PROFILE_PREPARED notification and call SessionStarted()
// so that the Launcher and other Profile dependent classes are created.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources(),
content::Details<Profile>(profile()));
UserManager::Get()->SessionStarted();
// Now is the good time to retrieve other logged in users for this session.
// First user has been already marked as logged in and active in
// PreProfileInit(). Chrome should tread other user in a session as active
// in the background.
UserSessionManager::GetInstance()->RestoreActiveSessions();
}
// Initialize the network portal detector for Chrome OS. The network
// portal detector starts to listen for notifications from
// NetworkStateHandler and initiates captive portal detection for
// active networks. Shoule be called before call to
// OptionallyRunChromeOSLoginManager, because it depends on
// NetworkPortalDetector.
// active networks. Should be called before call to CreateSessionManager,
// because it depends on NetworkPortalDetector.
NetworkPortalDetectorImpl::Initialize(
g_browser_process->system_request_context());
{
......@@ -614,12 +530,10 @@ void ChromeBrowserMainPartsChromeos::PostProfileInit() {
detector->Enable(true);
}
// Tests should be able to tune login manager before showing it.
// Thus only show login manager in normal (non-testing) mode.
if (!parameters().ui_task ||
parsed_command_line().HasSwitch(switches::kForceLoginManagerInTests)) {
OptionallyRunChromeOSLoginManager(parsed_command_line(), profile());
}
bool is_running_test = parameters().ui_task != NULL;
g_browser_process->platform_part()->InitializeSessionManager(
parsed_command_line(), profile(), is_running_test);
g_browser_process->platform_part()->SessionManager()->Start();
// Guest user profile is never initialized with locale settings,
// so we need special handling for Guest session.
......@@ -810,6 +724,8 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
NetworkPortalDetector::Shutdown();
UserManager::Destroy();
g_browser_process->platform_part()->ShutdownSessionManager();
}
void ChromeBrowserMainPartsChromeos::PostDestroyThreads() {
......
......@@ -15,6 +15,10 @@ namespace content {
class PowerSaveBlocker;
}
namespace session_manager {
class SessionManager;
}
namespace chromeos {
class DataPromoNotification;
......@@ -70,6 +74,8 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux {
scoped_ptr<internal::DBusServices> dbus_services_;
scoped_ptr<session_manager::SessionManager> session_manager_;
scoped_ptr<EventRewriterController> keyboard_event_rewriters_;
scoped_refptr<chromeos::ExternalMetrics> external_metrics_;
......
......@@ -18,6 +18,7 @@
#include "base/threading/thread.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
#include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
#include "chrome/browser/chromeos/login/auth/authenticator.h"
......@@ -258,6 +259,9 @@ class LoginUtilsTest : public testing::Test,
NULL, NULL));
browser_process_->SetIOThread(io_thread_state_.get());
browser_process_->platform_part()->InitializeSessionManager(
*CommandLine::ForCurrentProcess(), NULL, true);
#if defined(ENABLE_RLZ)
rlz_initialized_cb_ = base::Bind(&base::DoNothing);
rlz_lib::testing::SetRlzStoreDirectory(scoped_temp_dir_.path());
......@@ -276,11 +280,13 @@ class LoginUtilsTest : public testing::Test,
message_center::MessageCenter::Shutdown();
test_user_manager_.reset();
KioskAppManager::Shutdown();
InvokeOnIO(
base::Bind(&LoginUtilsTest::TearDownOnIO, base::Unretained(this)));
test_user_manager_.reset();
// LoginUtils instance must not outlive Profile instances.
LoginUtils::Set(NULL);
......
// 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);
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)));
} else {
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)));
}
}
ChromeSessionManager::ChromeSessionManager(
session_manager::SessionManagerDelegate* delegate) {
Initialize(delegate);
}
ChromeSessionManager::~ChromeSessionManager() {
}
} // namespace chromeos
// 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.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_CHROME_SESSION_MANAGER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_CHROME_SESSION_MANAGER_H_
#include "base/basictypes.h"
#include "components/session_manager/core/session_manager.h"
namespace base {
class CommandLine;
}
class Profile;
namespace chromeos {
class ChromeSessionManager : public session_manager::SessionManager {
public:
static scoped_ptr<session_manager::SessionManager> CreateSessionManager(
const base::CommandLine& parsed_command_line,
Profile* profile,
bool is_running_test);
private:
explicit ChromeSessionManager(
session_manager::SessionManagerDelegate* delegate);
virtual ~ChromeSessionManager();
DISALLOW_COPY_AND_ASSIGN(ChromeSessionManager);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_CHROME_SESSION_MANAGER_H_
// 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/kiosk_auto_launcher_session_manager_delegate.h"
#include "base/logging.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
namespace chromeos {
KioskAutoLauncherSessionManagerDelegate::
KioskAutoLauncherSessionManagerDelegate() {
}
KioskAutoLauncherSessionManagerDelegate::
~KioskAutoLauncherSessionManagerDelegate() {
}
void KioskAutoLauncherSessionManagerDelegate::Start() {
// Kiosk app launcher starts with login state.
session_manager_->SetSessionState(
session_manager::SESSION_STATE_LOGIN_PRIMARY);
ShowLoginWizard(chromeos::WizardController::kAppLaunchSplashScreenName);
// Login screen is skipped but 'login-prompt-visible' signal is still needed.
VLOG(1) << "Kiosk app auto launch >> login-prompt-visible";
DBusThreadManager::Get()->GetSessionManagerClient()->EmitLoginPromptVisible();
}
} // namespace chromeos
// 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.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_KIOSK_AUTO_LAUNCHER_SESSION_MANAGER_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_KIOSK_AUTO_LAUNCHER_SESSION_MANAGER_DELEGATE_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "components/session_manager/core/session_manager.h"
namespace chromeos {
class KioskAutoLauncherSessionManagerDelegate
: public session_manager::SessionManagerDelegate {
public:
KioskAutoLauncherSessionManagerDelegate();
virtual ~KioskAutoLauncherSessionManagerDelegate();
private:
// session_manager::SessionManagerDelegate implementation:
virtual void Start() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(KioskAutoLauncherSessionManagerDelegate);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_KIOSK_AUTO_LAUNCHER_SESSION_MANAGER_DELEGATE_H_
// 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/login_oobe_session_manager_delegate.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/common/pref_names.h"
namespace chromeos {
LoginOobeSessionManagerDelegate::LoginOobeSessionManagerDelegate() {
}
LoginOobeSessionManagerDelegate::~LoginOobeSessionManagerDelegate() {
}
void LoginOobeSessionManagerDelegate::Start() {
// State will be defined once out-of-box/login branching is complete.
ShowLoginWizard(std::string());
if (KioskModeSettings::Get()->IsKioskModeEnabled())
InitializeKioskModeScreensaver();
// Reset reboot after update flag when login screen is shown.
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (!connector->IsEnterpriseManaged()) {
PrefService* local_state = g_browser_process->local_state();
local_state->ClearPref(prefs::kRebootAfterUpdate);
}
}
} // namespace chromeos
// 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.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_LOGIN_OOBE_SESSION_MANAGER_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_LOGIN_OOBE_SESSION_MANAGER_DELEGATE_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "components/session_manager/core/session_manager.h"
namespace chromeos {
class LoginOobeSessionManagerDelegate
: public session_manager::SessionManagerDelegate {
public:
LoginOobeSessionManagerDelegate();
virtual ~LoginOobeSessionManagerDelegate();
private:
// session_manager::SessionManagerDelegate implementation:
virtual void Start() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(LoginOobeSessionManagerDelegate);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_LOGIN_OOBE_SESSION_MANAGER_DELEGATE_H_
// 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/restore_after_crash_session_manager_delegate.h"
#include "base/command_line.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/login/users/user_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/chromeos_switches.h"
#include "content/public/browser/notification_service.h"
namespace chromeos {
RestoreAfterCrashSessionManagerDelegate::
RestoreAfterCrashSessionManagerDelegate(Profile* profile,
const std::string& login_user_id)
: profile_(profile), login_user_id_(login_user_id) {
}
RestoreAfterCrashSessionManagerDelegate::
~RestoreAfterCrashSessionManagerDelegate() {
}
void RestoreAfterCrashSessionManagerDelegate::Start() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
session_manager_->SetSessionState(session_manager::SESSION_STATE_ACTIVE);
// TODO(nkostylev): Identify tests that do not set this kLoginUser flag but
// still rely on "stub user" session. Keeping existing behavior to avoid
// breaking tests.
if (command_line->HasSwitch(chromeos::switches::kLoginUser)) {
// This is done in SessionManager::OnProfileCreated during normal login.
UserSessionManager::GetInstance()->InitRlz(profile());
// Send the PROFILE_PREPARED notification and call SessionStarted()
// so that the Launcher and other Profile dependent classes are created.
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources(),
content::Details<Profile>(profile()));
// This call will set session state to SESSION_STATE_ACTIVE (same one).
UserManager::Get()->SessionStarted();
// Now is the good time to retrieve other logged in users for this session.
// First user has been already marked as logged in and active in
// PreProfileInit(). Restore sessions for other users in the background.
UserSessionManager::GetInstance()->RestoreActiveSessions();
}
bool is_running_test = command_line->HasSwitch(::switches::kTestName) ||
command_line->HasSwitch(::switches::kTestType);
if (!is_running_test) {
// Enable CrasAudioHandler logging when chrome restarts after crashing.
if (chromeos::CrasAudioHandler::IsInitialized())
chromeos::CrasAudioHandler::Get()->LogErrors();
// We did not log in (we crashed or are debugging), so we need to
// restore Sync.
UserSessionManager::GetInstance()->RestoreAuthenticationSession(profile());
}
}
} // namespace chromeos
// 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.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_RESTORE_AFTER_CRASH_SESSION_MANAGER_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_RESTORE_AFTER_CRASH_SESSION_MANAGER_DELEGATE_H_
#include <string>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "components/session_manager/core/session_manager.h"
class Profile;
namespace chromeos {
class RestoreAfterCrashSessionManagerDelegate
: public session_manager::SessionManagerDelegate {
public:
RestoreAfterCrashSessionManagerDelegate(Profile* profile,
const std::string& login_user_id);
virtual ~RestoreAfterCrashSessionManagerDelegate();
protected:
// session_manager::SessionManagerDelegate implementation:
virtual void Start() OVERRIDE;
Profile* profile() { return profile_; }
const std::string& login_user_id() const { return login_user_id_; }
private:
Profile* profile_;
const std::string login_user_id_;
DISALLOW_COPY_AND_ASSIGN(RestoreAfterCrashSessionManagerDelegate);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_RESTORE_AFTER_CRASH_SESSION_MANAGER_DELEGATE_H_
// 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/stub_login_session_manager_delegate.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
namespace chromeos {
StubLoginSessionManagerDelegate::StubLoginSessionManagerDelegate(
Profile* profile,
const std::string& login_user_id)
: RestoreAfterCrashSessionManagerDelegate(profile, login_user_id) {
}
StubLoginSessionManagerDelegate::~StubLoginSessionManagerDelegate() {
}
void StubLoginSessionManagerDelegate::Start() {
session_manager_->SetSessionState(session_manager::SESSION_STATE_ACTIVE);
// For dev machines and stub user emulate as if sync has been initialized.
profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
login_user_id());
RestoreAfterCrashSessionManagerDelegate::Start();
}
} // namespace chromeos
// 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.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_STUB_LOGIN_SESSION_MANAGER_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_STUB_LOGIN_SESSION_MANAGER_DELEGATE_H_
#include <string>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/login/session/restore_after_crash_session_manager_delegate.h"
class Profile;
namespace chromeos {
class StubLoginSessionManagerDelegate
: public RestoreAfterCrashSessionManagerDelegate {
public:
StubLoginSessionManagerDelegate(Profile* profile,
const std::string& login_user_id);
virtual ~StubLoginSessionManagerDelegate();
private:
// session_manager::SessionManagerDelegate implementation:
virtual void Start() OVERRIDE;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(StubLoginSessionManagerDelegate);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_STUB_LOGIN_SESSION_MANAGER_DELEGATE_H_
......@@ -55,6 +55,7 @@
#include "chromeos/ime/input_method_manager.h"
#include "chromeos/network/portal_detector/network_portal_detector.h"
#include "chromeos/network/portal_detector/network_portal_detector_strategy.h"
#include "components/session_manager/core/session_manager.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
......@@ -466,11 +467,15 @@ void UserSessionManager::OnNewRefreshTokenAvaiable(Profile* user_profile) {
void UserSessionManager::OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) {
bool is_running_test =
base::CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kTestName) ||
base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType);
UserManager* user_manager = UserManager::Get();
if (type == net::NetworkChangeNotifier::CONNECTION_NONE ||
!user_manager->IsUserLoggedIn() ||
!user_manager->IsLoggedInAsRegularUser() ||
user_manager->IsLoggedInAsStub()) {
user_manager->IsLoggedInAsStub() || is_running_test) {
return;
}
......@@ -682,6 +687,9 @@ void UserSessionManager::FinalizePrepareProfile(Profile* profile) {
profile->OnLogin();
g_browser_process->platform_part()->SessionManager()->SetSessionState(
session_manager::SESSION_STATE_LOGGED_IN_NOT_ACTIVE);
// Send the notification before creating the browser so additional objects
// that need the profile (e.g. the launcher) can be created first.
content::NotificationService::current()->Notify(
......
......@@ -68,6 +68,7 @@
#include "chromeos/ime/input_method_manager.h"
#include "chromeos/login/login_state.h"
#include "chromeos/settings/timezone_settings.h"
#include "components/session_manager/core/session_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_frame_host.h"
......@@ -1182,32 +1183,36 @@ void ShowLoginWizard(const std::string& first_screen_name) {
gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
g_browser_process->platform_part()->SessionManager()->SetSessionState(
StartupUtils::IsOobeCompleted()
? session_manager::SESSION_STATE_LOGIN_PRIMARY
: session_manager::SESSION_STATE_OOBE);
LoginDisplayHost* display_host = new LoginDisplayHostImpl(screen_bounds);
bool show_app_launch_splash_screen = (first_screen_name ==
chromeos::WizardController::kAppLaunchSplashScreenName);
bool show_app_launch_splash_screen =
(first_screen_name == WizardController::kAppLaunchSplashScreenName);
if (show_app_launch_splash_screen) {
const std::string& auto_launch_app_id =
chromeos::KioskAppManager::Get()->GetAutoLaunchApp();
KioskAppManager::Get()->GetAutoLaunchApp();
display_host->StartAppLaunch(auto_launch_app_id,
false /* diagnostic_mode */);
return;
}
// Check whether we need to execute OOBE process.
bool oobe_complete = chromeos::StartupUtils::IsOobeCompleted();
// Check whether we need to execute OOBE flow.
bool oobe_complete = StartupUtils::IsOobeCompleted();
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
bool enrollment_screen_wanted =
chromeos::WizardController::ShouldRecoverEnrollment() ||
(chromeos::WizardController::ShouldAutoStartEnrollment() &&
oobe_complete &&
WizardController::ShouldRecoverEnrollment() ||
(WizardController::ShouldAutoStartEnrollment() && oobe_complete &&
!connector->IsEnterpriseManaged());
if (enrollment_screen_wanted && first_screen_name.empty()) {
// Shows networks screen instead of enrollment screen to resume the
// interrupted auto start enrollment flow because enrollment screen does
// not handle flaky network. See http://crbug.com/332572
display_host->StartWizard(chromeos::WizardController::kNetworkScreenName,
display_host->StartWizard(WizardController::kNetworkScreenName,
scoped_ptr<base::DictionaryValue>());
return;
}
......@@ -1221,7 +1226,7 @@ void ShowLoginWizard(const std::string& first_screen_name) {
bool show_login_screen =
(first_screen_name.empty() && oobe_complete) ||
first_screen_name == chromeos::WizardController::kLoginScreenName;
first_screen_name == WizardController::kLoginScreenName;
if (show_login_screen) {
display_host->StartSignInScreen(LoginScreenContext());
......@@ -1229,12 +1234,12 @@ void ShowLoginWizard(const std::string& first_screen_name) {
}
// Load startup manifest.
const chromeos::StartupCustomizationDocument* startup_manifest =
chromeos::StartupCustomizationDocument::GetInstance();
const StartupCustomizationDocument* startup_manifest =
StartupCustomizationDocument::GetInstance();
// Switch to initial locale if specified by customization
// and has not been set yet. We cannot call
// chromeos::LanguageSwitchMenu::SwitchLanguage here before
// LanguageSwitchMenu::SwitchLanguage here before
// EmitLoginPromptReady.
PrefService* prefs = g_browser_process->local_state();
const std::string& current_locale =
......@@ -1259,7 +1264,7 @@ void ShowLoginWizard(const std::string& first_screen_name) {
// Don't need to schedule pref save because setting initial local
// will enforce preference saving.
prefs->SetString(prefs::kApplicationLocale, locale);
chromeos::StartupUtils::SetInitialLocale(locale);
StartupUtils::SetInitialLocale(locale);
scoped_ptr<ShowLoginWizardSwitchLanguageCallbackData> data(
new ShowLoginWizardSwitchLanguageCallbackData(
......
......@@ -9,8 +9,10 @@
#include "base/bind.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/helper.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "components/session_manager/core/session_manager.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
......@@ -47,6 +49,9 @@ void UserAddingScreenImpl::Start() {
display_host_->StartUserAdding(
base::Bind(&UserAddingScreenImpl::OnDisplayHostCompletion,
base::Unretained(this)));
g_browser_process->platform_part()->SessionManager()->SetSessionState(
session_manager::SESSION_STATE_LOGIN_SECONDARY);
FOR_EACH_OBSERVER(Observer, observers_, OnUserAddingStarted());
}
......@@ -73,6 +78,9 @@ void UserAddingScreenImpl::RemoveObserver(Observer* observer) {
void UserAddingScreenImpl::OnDisplayHostCompletion() {
CHECK(IsRunning());
display_host_ = NULL;
g_browser_process->platform_part()->SessionManager()->SetSessionState(
session_manager::SESSION_STATE_ACTIVE);
FOR_EACH_OBSERVER(Observer, observers_, OnUserAddingFinished());
}
......
......@@ -58,6 +58,7 @@
#include "chromeos/login/login_state.h"
#include "chromeos/login/user_names.h"
#include "chromeos/settings/cros_settings_names.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/user_type.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
......@@ -493,7 +494,11 @@ void UserManagerImpl::SwitchActiveUser(const std::string& user_id) {
void UserManagerImpl::SessionStarted() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
session_started_ = true;
UpdateLoginState();
g_browser_process->platform_part()->SessionManager()->SetSessionState(
session_manager::SESSION_STATE_ACTIVE);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_SESSION_STARTED,
content::Source<UserManager>(this),
......
......@@ -52,6 +52,7 @@
'../components/components.gyp:cloud_policy_proto',
'../components/components.gyp:onc_component',
'../components/components.gyp:policy',
'../components/components.gyp:session_manager_component',
'../components/components.gyp:user_manager',
# This depends directly on the variations target, rather than just
# transitively via the common target because the proto sources need to
......@@ -647,6 +648,16 @@
'browser/chromeos/login/screens/wrong_hwid_screen.cc',
'browser/chromeos/login/screens/wrong_hwid_screen.h',
'browser/chromeos/login/screens/wrong_hwid_screen_actor.h',
'browser/chromeos/login/session/chrome_session_manager.cc',
'browser/chromeos/login/session/chrome_session_manager.h',
'browser/chromeos/login/session/kiosk_auto_launcher_session_manager_delegate.cc',
'browser/chromeos/login/session/kiosk_auto_launcher_session_manager_delegate.h',
'browser/chromeos/login/session/login_oobe_session_manager_delegate.cc',
'browser/chromeos/login/session/login_oobe_session_manager_delegate.h',
'browser/chromeos/login/session/restore_after_crash_session_manager_delegate.cc',
'browser/chromeos/login/session/restore_after_crash_session_manager_delegate.h',
'browser/chromeos/login/session/stub_login_session_manager_delegate.cc',
'browser/chromeos/login/session/stub_login_session_manager_delegate.h',
'browser/chromeos/login/session/user_session_manager.cc',
'browser/chromeos/login/session/user_session_manager.h',
'browser/chromeos/login/signin/auth_sync_observer.cc',
......
......@@ -84,6 +84,7 @@
}],
['use_ash==1', {
'includes': [
'session_manager.gypi',
'user_manager.gypi',
],
}],
......
# 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.
{
'targets': [
{
'target_name': 'session_manager_component',
'type': '<(component)',
'dependencies': [
'../base/base.gyp:base',
],
'include_dirs': [
'..',
],
'defines': [
'SESSION_IMPLEMENTATION',
],
'sources': [
'session_manager/core/session_manager.h',
'session_manager/core/session_manager.cc',
'session_manager/session_manager_export.h',
],
},
],
}
nkostylev@chromium.org
antrim@chromium.org
dpolukhin@chromium.org
dzhioev@chromium.org
ygorshenin@chromium.org
// 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 "components/session_manager/core/session_manager.h"
#include "base/logging.h"
namespace session_manager {
SessionManager::SessionManager() : session_state_(SESSION_STATE_UNKNOWN) {
}
SessionManager::~SessionManager() {
}
void SessionManager::SetSessionState(SessionState state) {
VLOG(1) << "Changing session state to: " << state;
if (session_state_ != state) {
// TODO(nkostylev): Notify observers about the state change.
// TODO(nkostylev): Add code to process session state change and probably
// replace delegate_ if needed.
session_state_ = state;
}
}
void SessionManager::Initialize(SessionManagerDelegate* delegate) {
DCHECK(delegate);
delegate_.reset(delegate);
delegate_->SetSessionManager(this);
}
void SessionManager::Start() {
delegate_->Start();
}
SessionManagerDelegate::SessionManagerDelegate() : session_manager_(NULL) {
}
SessionManagerDelegate::~SessionManagerDelegate() {
}
void SessionManagerDelegate::SetSessionManager(
session_manager::SessionManager* session_manager) {
session_manager_ = session_manager;
}
} // namespace session_manager
// 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.
#ifndef COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_
#define COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_
#include "base/memory/scoped_ptr.h"
#include "components/session_manager/session_manager_export.h"
namespace session_manager {
class SessionManagerDelegate;
// TODO(nkostylev): Get rid/consolidate with:
// ash::SessionStateDelegate::SessionState and chromeos::LoggedInState.
enum SESSION_EXPORT SessionState {
// Default value, when session state hasn't been initialized yet.
SESSION_STATE_UNKNOWN = 0,
// Running out of box UI.
SESSION_STATE_OOBE,
// Running login UI (primary user) but user sign in hasn't completed yet.
SESSION_STATE_LOGIN_PRIMARY,
// Running login UI (primary or secondary user), user sign in has been
// completed but login UI hasn't been hidden yet. This means that either
// some session initialization is happening or user has to go through some
// UI flow on the same login UI like select avatar, agree to terms of
// service etc.
SESSION_STATE_LOGGED_IN_NOT_ACTIVE,
// A user(s) has logged in *and* login UI is hidden i.e. user session is
// not blocked.
SESSION_STATE_ACTIVE,
// Same as SESSION_STATE_LOGIN_PRIMARY but for multi-profiles sign in i.e.
// when there's at least one user already active in the session.
SESSION_STATE_LOGIN_SECONDARY,
};
class SESSION_EXPORT SessionManager {
public:
SessionManager();
virtual ~SessionManager();
SessionState session_state() const { return session_state_; }
virtual void SetSessionState(SessionState state);
// Let session delegate executed on its plan of actions depending on the
// current session type / state.
void Start();
protected:
// Initializes SessionManager with delegate.
void Initialize(SessionManagerDelegate* delegate);
private:
SessionState session_state_;
scoped_ptr<SessionManagerDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(SessionManager);
};
class SESSION_EXPORT SessionManagerDelegate {
public:
SessionManagerDelegate();
virtual ~SessionManagerDelegate();
virtual void SetSessionManager(
session_manager::SessionManager* session_manager);
// Executes specific actions defined by this delegate.
virtual void Start() = 0;
protected:
session_manager::SessionManager* session_manager_;
private:
DISALLOW_COPY_AND_ASSIGN(SessionManagerDelegate);
};
} // namespace session_manager
#endif // COMPONENTS_SESSION_MANAGER_CORE_SESSION_MANAGER_H_
// 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.
#ifndef COMPONENTS_SESSION_MANAGER_SESSION_MANAGER_EXPORT_H_
#define COMPONENTS_SESSION_MANAGER_SESSION_MANAGER_EXPORT_H_
#if defined(COMPONENT_BUILD)
#if defined(WIN32)
#if defined(SESSION_IMPLEMENTATION)
#define SESSION_EXPORT __declspec(dllexport)
#else
#define SESSION_EXPORT __declspec(dllimport)
#endif // defined(SESSION_EXPORT)
#else // defined(WIN32)
#if defined(SESSION_IMPLEMENTATION)
#define SESSION_EXPORT __attribute__((visibility("default")))
#else
#define SESSION_EXPORT
#endif
#endif
#else // defined(COMPONENT_BUILD)
#define SESSION_EXPORT
#endif
#endif // COMPONENTS_SESSION_MANAGER_SESSION_MANAGER_EXPORT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment