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 154073dec497c2ad6adcb34d6955ecacecf066b6..d3f0bbf485a2d07535a958f0e5215cfc27178224 100644 |
| --- a/chrome/browser/chromeos/login/existing_user_controller.cc |
| +++ b/chrome/browser/chromeos/login/existing_user_controller.cc |
| @@ -143,7 +143,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 +164,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(); |
| @@ -237,6 +245,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) { |
| @@ -286,6 +302,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; |
| @@ -340,6 +362,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); |
| @@ -396,6 +421,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); |
| @@ -443,6 +472,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 |
| @@ -458,6 +490,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); |
| @@ -471,6 +506,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) { |
| @@ -489,6 +525,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; |
| } |
| @@ -510,6 +547,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); |
| @@ -539,6 +579,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; |
| } |
| @@ -551,6 +592,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; |
| @@ -689,6 +735,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 |
| @@ -710,6 +757,8 @@ void ExistingUserController::OnLoginSuccess( |
| is_login_in_progress_ = false; |
| offline_failed_ = false; |
| + StopPublicSessionAutoLoginTimer(); |
| + |
| bool has_cookies = |
| login_performer_->auth_mode() == LoginPerformer::AUTH_MODE_EXTENSION; |
| @@ -835,6 +884,8 @@ void ExistingUserController::WhiteListCheckFailed(const std::string& email) { |
| } |
| display_email_.clear(); |
| + |
| + StartPublicSessionAutoLoginTimer(); |
| } |
| void ExistingUserController::PolicyLoadFailed() { |
| @@ -844,6 +895,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, |
| @@ -868,6 +922,63 @@ 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_ = ""; |
| + } |
| + if (!cros_settings_->GetInteger( |
| + kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| + &public_session_auto_login_delay_)) { |
| + public_session_auto_login_delay_ = 0; |
| + } |
| + |
| + if (!public_session_auto_login_username_.empty()) |
| + StartPublicSessionAutoLoginTimer(); |
| + else |
| + StopPublicSessionAutoLoginTimer(); |
| +} |
| + |
| +void ExistingUserController::ResetPublicSessionAutoLoginTimer() { |
| + // Only restart the auto-login timer if it's already running. |
| + if (auto_login_timer_ && auto_login_timer_->IsRunning()) { |
| + StopPublicSessionAutoLoginTimer(); |
| + StartPublicSessionAutoLoginTimer(); |
| + } |
| +} |
| + |
| +void ExistingUserController::OnPublicSessionAutoLoginTimerFire() { |
| + DCHECK(signin_screen_ready_ && |
|
Mattias Nissler (ping if slow)
2013/03/01 10:37:21
Make this a check maybe?
dconnelly
2013/03/06 10:02:59
Done.
|
| + !is_login_in_progress_ && |
| + !public_session_auto_login_username_.empty()); |
| + LoginAsPublicAccount(public_session_auto_login_username_); |
| +} |
| + |
| +void ExistingUserController::StopPublicSessionAutoLoginTimer() { |
| + if (auto_login_timer_) |
| + 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. |
| + if (!auto_login_timer_) |
| + auto_login_timer_.reset(new base::OneShotTimer<ExistingUserController>); |
|
Nikita (slow)
2013/03/04 15:52:08
nit: Insert one empty line after this one to impro
dconnelly
2013/03/06 10:02:59
Done.
|
| + 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(); |
| } |