Chromium Code Reviews| Index: chrome/browser/chromeos/login/existing_user_controller.cc |
| diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc |
| index 3b6632a38632b468b8ba668e69fe9d1ae19949f0..0ce479639bd1078ec2c0e73e7241510ec3888d6f 100644 |
| --- a/chrome/browser/chromeos/login/existing_user_controller.cc |
| +++ b/chrome/browser/chromeos/login/existing_user_controller.cc |
| @@ -6,6 +6,7 @@ |
| #include <vector> |
| +#include "ash/wm/user_activity_detector.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/callback.h" |
| @@ -143,7 +144,8 @@ ExistingUserController::ExistingUserController(LoginDisplayHost* host) |
| offline_failed_(false), |
| is_login_in_progress_(false), |
| password_changed_(false), |
| - do_auto_enrollment_(false) { |
| + do_auto_enrollment_(false), |
| + signin_screen_ready_(false) { |
| DCHECK(current_controller_ == NULL); |
| current_controller_ = this; |
| @@ -163,11 +165,18 @@ ExistingUserController::ExistingUserController(LoginDisplayHost* host) |
| cros_settings_->AddSettingsObserver(kAccountsPrefAllowNewUser, this); |
| cros_settings_->AddSettingsObserver(kAccountsPrefAllowGuest, this); |
| cros_settings_->AddSettingsObserver(kAccountsPrefUsers, this); |
| + cros_settings_->AddSettingsObserver( |
| + kAccountsPrefDeviceLocalAccountAutoLoginId, |
| + this); |
| + cros_settings_->AddSettingsObserver( |
| + kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| + this); |
| } |
| void ExistingUserController::Init(const UserList& users) { |
| time_init_ = base::Time::Now(); |
| UpdateLoginDisplay(users); |
| + ConfigurePublicSessionAutoLogin(); |
| LoginUtils::Get()->PrewarmAuthentication(); |
| DBusThreadManager::Get()->GetSessionManagerClient()->EmitLoginPromptReady(); |
| @@ -228,6 +237,13 @@ void ExistingUserController::Observe( |
| registrar_.RemoveAll(); |
| return; |
| } |
| + if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED) { |
| + std::string setting = *content::Details<const std::string>(details).ptr(); |
| + if (setting == kAccountsPrefDeviceLocalAccountAutoLoginId || |
| + setting == kAccountsPrefDeviceLocalAccountAutoLoginDelay) { |
| + ConfigurePublicSessionAutoLogin(); |
| + } |
| + } |
| if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED || |
| type == chrome::NOTIFICATION_USER_LIST_CHANGED) { |
| if (host_ != NULL) { |
| @@ -277,6 +293,12 @@ ExistingUserController::~ExistingUserController() { |
| cros_settings_->RemoveSettingsObserver(kAccountsPrefAllowNewUser, this); |
| cros_settings_->RemoveSettingsObserver(kAccountsPrefAllowGuest, this); |
| cros_settings_->RemoveSettingsObserver(kAccountsPrefUsers, this); |
| + cros_settings_->RemoveSettingsObserver( |
| + kAccountsPrefDeviceLocalAccountAutoLoginId, |
| + this); |
| + cros_settings_->RemoveSettingsObserver( |
| + kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| + this); |
| if (current_controller_ == this) { |
| current_controller_ = NULL; |
| @@ -331,6 +353,9 @@ void ExistingUserController::CompleteLogin(const std::string& username, |
| return; |
| } |
| + // Stop the auto-login timer when attempting login. |
| + StopPublicSessionAutoLoginTimer(); |
| + |
| // Disable UI while loading user profile. |
| login_display_->SetUIEnabled(false); |
| @@ -387,6 +412,10 @@ void ExistingUserController::Login(const std::string& username, |
| const std::string& password) { |
| if (username.empty() || password.empty()) |
| return; |
| + |
| + // Stop the auto-login timer when attempting login. |
| + StopPublicSessionAutoLoginTimer(); |
| + |
| // Disable clicking on other windows. |
| login_display_->SetUIEnabled(false); |
| @@ -434,6 +463,9 @@ void ExistingUserController::PerformLogin( |
| } |
| void ExistingUserController::LoginAsRetailModeUser() { |
| + // Stop the auto-login timer when attempting login. |
| + StopPublicSessionAutoLoginTimer(); |
| + |
| // Disable clicking on other windows. |
| login_display_->SetUIEnabled(false); |
| // TODO(rkc): Add a CHECK to make sure retail mode logins are allowed once |
| @@ -449,6 +481,9 @@ void ExistingUserController::LoginAsRetailModeUser() { |
| } |
| void ExistingUserController::LoginAsGuest() { |
| + // Stop the auto-login timer when attempting login. |
| + StopPublicSessionAutoLoginTimer(); |
| + |
| // Disable clicking on other windows. |
| login_display_->SetUIEnabled(false); |
| @@ -462,11 +497,13 @@ void ExistingUserController::LoginAsGuest() { |
| HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
| // Reenable clicking on other windows and status area. |
| login_display_->SetUIEnabled(true); |
| + StartPublicSessionAutoLoginTimer(); |
| display_email_.clear(); |
| return; |
| } else if (status != CrosSettingsProvider::TRUSTED) { |
| // Value of AllowNewUser setting is still not verified. |
| // Another attempt will be invoked after verification completion. |
| + StartPublicSessionAutoLoginTimer(); |
| return; |
| } |
| @@ -480,6 +517,7 @@ void ExistingUserController::LoginAsGuest() { |
| HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT); |
| // Reenable clicking on other windows and status area. |
| login_display_->SetUIEnabled(true); |
| + StartPublicSessionAutoLoginTimer(); |
| display_email_.clear(); |
| return; |
| } |
| @@ -499,6 +537,9 @@ void ExistingUserController::MigrateUserData(const std::string& old_password) { |
| void ExistingUserController::LoginAsPublicAccount( |
| const std::string& username) { |
| + // Stop the auto-login timer when attempting login. |
| + StopPublicSessionAutoLoginTimer(); |
| + |
| // Disable clicking on other windows. |
| login_display_->SetUIEnabled(false); |
| @@ -519,8 +560,10 @@ void ExistingUserController::LoginAsPublicAccount( |
| // If device policy is not verified yet, this function will be called again |
| // when verification finishes. |
| - if (status != CrosSettingsProvider::TRUSTED) |
| + if (status != CrosSettingsProvider::TRUSTED) { |
| + StartPublicSessionAutoLoginTimer(); |
| return; |
| + } |
| // If there is no public account with the given |username|, logging in is not |
| // possible. |
| @@ -528,6 +571,7 @@ void ExistingUserController::LoginAsPublicAccount( |
| if (!user || user->GetType() != User::USER_TYPE_PUBLIC_ACCOUNT) { |
| // Re-enable clicking on other windows. |
| login_display_->SetUIEnabled(true); |
| + StartPublicSessionAutoLoginTimer(); |
| return; |
| } |
| @@ -540,6 +584,11 @@ void ExistingUserController::LoginAsPublicAccount( |
| l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_LOGIN_SIGNIN_PUBLIC_ACCOUNT)); |
| } |
| +void ExistingUserController::OnSigninScreenReady() { |
| + signin_screen_ready_ = true; |
| + StartPublicSessionAutoLoginTimer(); |
| +} |
| + |
| void ExistingUserController::OnUserSelected(const std::string& username) { |
| login_performer_.reset(NULL); |
| num_login_attempts_ = 0; |
| @@ -680,6 +729,8 @@ void ExistingUserController::OnLoginFailure(const LoginFailure& failure) { |
| // Clear the recorded displayed email so it won't affect any future attempts. |
| display_email_.clear(); |
| + |
| + StartPublicSessionAutoLoginTimer(); |
| } |
| void ExistingUserController::OnLoginSuccess( |
| @@ -834,6 +885,9 @@ void ExistingUserController::PolicyLoadFailed() { |
| login_display_->SetUIEnabled(true); |
| display_email_.clear(); |
| + |
| + // Policy load failure stops login attempts---restart the timer. |
| + StartPublicSessionAutoLoginTimer(); |
| } |
| void ExistingUserController::OnOnlineChecked(const std::string& username, |
| @@ -875,6 +929,52 @@ void ExistingUserController::ActivateWizard(const std::string& screen_name) { |
| host_->StartWizard(screen_name, params); |
| } |
| +void ExistingUserController::ConfigurePublicSessionAutoLogin() { |
| + if (!cros_settings_->GetString( |
| + kAccountsPrefDeviceLocalAccountAutoLoginId, |
| + &public_session_auto_login_username_) || |
| + public_session_auto_login_username_.empty()) { |
| + public_session_auto_login_username_ = ""; |
| + } |
| + if (!cros_settings_->GetInteger( |
| + kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| + &public_session_auto_login_delay_)) { |
| + public_session_auto_login_delay_ = 0; |
| + } |
| + |
| + if (!public_session_auto_login_username_.empty()) { |
| + if (!ash::Shell::GetInstance()->user_activity_detector()->HasObserver(this)) |
| + ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); |
|
Nikita (slow)
2013/02/11 17:30:29
Remove observer in dtor?
bartfab (slow)
2013/02/11 17:37:31
The observer could be unconditionally added and re
Nikita (slow)
2013/02/11 17:51:31
Ok then.
dconnelly
2013/02/21 10:42:21
Done.
|
| + StartPublicSessionAutoLoginTimer(); |
| + } else { |
| + ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
|
Nikita (slow)
2013/02/11 17:30:29
On a normal boot path (i.e. no public accounts con
bartfab (slow)
2013/02/11 17:37:31
It's actually benign to remove an observer that do
Nikita (slow)
2013/02/11 17:51:31
I thought that previously it had a such check so i
dconnelly
2013/02/21 10:42:21
You're not confused--there was a check before. I
|
| + StopPublicSessionAutoLoginTimer(); |
| + } |
| +} |
| + |
| +void ExistingUserController::OnUserActivity() { |
| + if (auto_login_timer_.IsRunning()) { |
| + StopPublicSessionAutoLoginTimer(); |
| + StartPublicSessionAutoLoginTimer(); |
|
Nikita (slow)
2013/02/11 17:30:29
What's the point of restarting timer?
bartfab (slow)
2013/02/11 17:37:31
The idea is that the timer performs an auto-login
Nikita (slow)
2013/02/11 17:57:17
Take into account that device will power off after
|
| + } |
| +} |
| + |
| +void ExistingUserController::StopPublicSessionAutoLoginTimer() { |
| + auto_login_timer_.Stop(); |
| +} |
| + |
| +void ExistingUserController::StartPublicSessionAutoLoginTimer() { |
| + if (!signin_screen_ready_ || public_session_auto_login_username_.empty()) |
| + return; |
| + auto_login_timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromMilliseconds( |
| + public_session_auto_login_delay_), |
| + base::Bind( |
| + &ExistingUserController::LoginAsPublicAccount, |
| + weak_factory_.GetWeakPtr(), |
| + public_session_auto_login_username_)); |
| +} |
| + |
| gfx::NativeWindow ExistingUserController::GetNativeWindow() const { |
| return host_->GetNativeWindow(); |
| } |