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 06f697ec7906a033097dec31addf20cbb4040189..5f40ee32344b3b0cdf6ea2ca341380d650519c0e 100644 |
| --- a/chrome/browser/chromeos/login/existing_user_controller.cc |
| +++ b/chrome/browser/chromeos/login/existing_user_controller.cc |
| @@ -6,6 +6,8 @@ |
| #include <vector> |
| +#include "ash/shell.h" |
| +#include "ash/wm/user_activity_detector.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/callback.h" |
| @@ -143,7 +145,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 +166,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 +238,14 @@ void ExistingUserController::Observe( |
| registrar_.RemoveAll(); |
| return; |
| } |
| + if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED) { |
| + const 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 +295,15 @@ 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 (ash::Shell::HasInstance()) |
| + ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| if (current_controller_ == this) { |
| current_controller_ = NULL; |
| @@ -331,6 +358,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 +417,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 +468,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 +486,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,6 +502,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; |
| } else if (status != CrosSettingsProvider::TRUSTED) { |
| @@ -480,6 +521,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; |
| } |
| @@ -501,6 +543,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); |
| @@ -530,6 +575,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; |
| } |
| @@ -542,6 +588,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 +731,7 @@ void ExistingUserController::OnLoginFailure(const LoginFailure& failure) { |
| } |
| // Reenable clicking on other windows and status area. |
| login_display_->SetUIEnabled(true); |
| + StartPublicSessionAutoLoginTimer(); |
| } |
| // Reset user flow to default, so that special flow will not affect next |
| @@ -701,6 +753,8 @@ void ExistingUserController::OnLoginSuccess( |
| is_login_in_progress_ = false; |
| offline_failed_ = false; |
| + StopPublicSessionAutoLoginTimer(); |
| + |
| bool has_cookies = |
| login_performer_->auth_mode() == LoginPerformer::AUTH_MODE_EXTENSION; |
| @@ -825,6 +879,8 @@ void ExistingUserController::WhiteListCheckFailed(const std::string& email) { |
| } |
| display_email_.clear(); |
| + |
| + StartPublicSessionAutoLoginTimer(); |
| } |
| void ExistingUserController::PolicyLoadFailed() { |
| @@ -834,6 +890,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, |
| @@ -858,6 +917,74 @@ void ExistingUserController::ActivateWizard(const std::string& screen_name) { |
| host_->StartWizard(screen_name, params); |
| } |
| +base::OneShotTimer<ExistingUserController>& |
| + ExistingUserController::auto_login_timer() { |
| + if (!auto_login_timer_) |
| + auto_login_timer_.reset(new base::OneShotTimer<ExistingUserController>); |
| + return *auto_login_timer_; |
| +} |
| + |
| +void ExistingUserController::ConfigurePublicSessionAutoLogin() { |
| + if (!cros_settings_->GetString( |
| + kAccountsPrefDeviceLocalAccountAutoLoginId, |
| + &public_session_auto_login_username_)) { |
| + public_session_auto_login_username_ = ""; |
| + } |
| + if (!cros_settings_->GetInteger( |
| + kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| + &public_session_auto_login_delay_)) { |
| + public_session_auto_login_delay_ = 0; |
| + } |
| + |
| + ash::UserActivityDetector* detector = ash::Shell::HasInstance() ? |
| + ash::Shell::GetInstance()->user_activity_detector() : NULL; |
| + if (!public_session_auto_login_username_.empty()) { |
| + StartPublicSessionAutoLoginTimer(); |
| + if (detector && !detector->HasObserver(this)) |
| + detector->AddObserver(this); |
|
Nikita (slow)
2013/02/27 19:17:03
Please see another CL that recently has landed:
h
dconnelly
2013/02/28 09:29:15
Cool. Done.
|
| + } else { |
| + if (detector) |
| + detector->RemoveObserver(this); |
| + StopPublicSessionAutoLoginTimer(); |
| + } |
| +} |
| + |
| +void ExistingUserController::OnUserActivity() { |
| + // Only restart the auto-login timer if it's already running. |
| + if (auto_login_timer().IsRunning()) { |
| + StopPublicSessionAutoLoginTimer(); |
| + StartPublicSessionAutoLoginTimer(); |
| + } |
| +} |
| + |
| +void ExistingUserController::OnPublicSessionAutoLoginTimerFire() { |
| + DCHECK(signin_screen_ready_ && |
| + !is_login_in_progress_ && |
| + !public_session_auto_login_username_.empty()); |
| + LoginAsPublicAccount(public_session_auto_login_username_); |
| +} |
| + |
| +void ExistingUserController::StopPublicSessionAutoLoginTimer() { |
| + auto_login_timer().Stop(); |
| +} |
| + |
| +void ExistingUserController::StartPublicSessionAutoLoginTimer() { |
| + if (!signin_screen_ready_ || |
| + is_login_in_progress_ || |
| + public_session_auto_login_username_.empty()) { |
| + return; |
| + } |
| + |
| + // Start the auto-login timer. |
| + auto_login_timer().Start( |
| + FROM_HERE, |
| + base::TimeDelta::FromMilliseconds( |
| + public_session_auto_login_delay_), |
| + base::Bind( |
| + &ExistingUserController::OnPublicSessionAutoLoginTimerFire, |
| + weak_factory_.GetWeakPtr())); |
| +} |
| + |
| gfx::NativeWindow ExistingUserController::GetNativeWindow() const { |
| return host_->GetNativeWindow(); |
| } |