Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Unified Diff: chrome/browser/chromeos/login/existing_user_controller.cc

Issue 12218078: Implement a policy to autologin a public account. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reset timer on user activity, review comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0cf370e5eaffb717f5cfdc32ff4e795bfeae8f30..166c91a55cc641e24dd9105bbcf5c6cbfc0dcef1 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"
@@ -144,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;
@@ -164,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();
@@ -229,6 +238,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_POLICY_USER_LIST_CHANGED) {
if (host_ != NULL) {
@@ -278,6 +294,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;
@@ -332,6 +354,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);
@@ -388,6 +413,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);
@@ -435,6 +464,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
@@ -450,6 +482,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);
@@ -463,11 +498,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;
}
@@ -481,6 +518,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;
}
@@ -500,6 +538,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);
@@ -520,8 +561,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.
@@ -529,6 +572,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;
}
@@ -541,6 +585,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;
@@ -681,6 +730,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(
@@ -840,6 +891,9 @@ void ExistingUserController::PolicyLoadFailed() {
login_display_->SetUIEnabled(true);
display_email_.clear();
+
+ // Policy load failure stops login attempts---restart the timer.
bartfab (slow) 2013/02/11 17:11:21 Hmm. The request to add space around the odd -- yi
+ StartPublicSessionAutoLoginTimer();
}
void ExistingUserController::OnOnlineChecked(const std::string& username,
@@ -881,6 +935,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_timer_)) {
+ public_session_auto_login_timer_ = 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);
+ StartPublicSessionAutoLoginTimer();
+ } else {
+ ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this);
+ StopPublicSessionAutoLoginTimer();
+ }
+}
+
+void ExistingUserController::OnUserActivity() {
+ if (auto_login_timer_.IsRunning()) {
+ StopPublicSessionAutoLoginTimer();
+ StartPublicSessionAutoLoginTimer();
+ }
+}
+
+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_timer_),
+ base::Bind(
+ &ExistingUserController::LoginAsPublicAccount,
+ weak_factory_.GetWeakPtr(),
+ public_session_auto_login_username_));
+}
+
gfx::NativeWindow ExistingUserController::GetNativeWindow() const {
return host_->GetNativeWindow();
}

Powered by Google App Engine
This is Rietveld 408576698