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

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: split out FakeSessionManagerClient 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 06f697ec7906a033097dec31addf20cbb4040189..82479f7aa14a12b447d37e30f65431bfe7774efd 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,13 @@ void ExistingUserController::Observe(
registrar_.RemoveAll();
return;
}
+ if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED) {
+ std::string setting = *content::Details<const std::string>(details).ptr();
bartfab (slow) 2013/02/25 16:51:23 Nit: I would make this a "const std::string"
dconnelly 2013/02/26 18:04:15 Done.
+ if (setting == kAccountsPrefDeviceLocalAccountAutoLoginId ||
+ setting == kAccountsPrefDeviceLocalAccountAutoLoginDelay) {
+ ConfigurePublicSessionAutoLogin();
+ }
+ }
if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED ||
type == chrome::NOTIFICATION_USER_LIST_CHANGED) {
if (host_ != NULL) {
@@ -277,6 +294,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 +357,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 +416,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 +467,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 +485,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 +501,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();
bartfab (slow) 2013/02/25 16:51:23 Notice that we end up here if the policy subsystem
dconnelly 2013/02/26 18:04:15 Done.
return;
}
@@ -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);
@@ -521,8 +566,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();
bartfab (slow) 2013/02/25 16:51:23 Notice that we end up here if the policy subsystem
dconnelly 2013/02/26 18:04:15 Done.
return;
+ }
// If there is no public account with the given |username|, logging in is not
// possible.
@@ -530,6 +577,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 +590,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 +733,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 +755,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 +881,8 @@ void ExistingUserController::WhiteListCheckFailed(const std::string& email) {
}
display_email_.clear();
+
+ StartPublicSessionAutoLoginTimer();
}
void ExistingUserController::PolicyLoadFailed() {
@@ -834,6 +892,9 @@ void ExistingUserController::PolicyLoadFailed() {
login_display_->SetUIEnabled(true);
display_email_.clear();
+
+ // Policy load failure stops login attempts---restart the timer.
bartfab (slow) 2013/02/25 16:51:23 Nit: I am still bothered by these triple dashes an
dconnelly 2013/02/26 18:04:15 Done. But I'm going to make sure that every email
+ StartPublicSessionAutoLoginTimer();
}
void ExistingUserController::OnOnlineChecked(const std::string& username,
@@ -858,6 +919,67 @@ 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_ = "";
bartfab (slow) 2013/02/25 16:51:23 You can simplify this to: if (!cros_settings_->Ge
dconnelly 2013/02/26 18:04:15 Done.
+ }
+ 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;
bartfab (slow) 2013/02/25 16:51:23 I think it is allowed to put the |?| at the start
dconnelly 2013/02/26 18:04:15 Done.
+ if (!public_session_auto_login_username_.empty()) {
+ StartPublicSessionAutoLoginTimer();
+ if (detector && !detector->HasObserver(this))
+ detector->AddObserver(this);
+ } else {
+ if (detector)
+ detector->RemoveObserver(this);
+ StopPublicSessionAutoLoginTimer();
+ }
+}
+
+void ExistingUserController::OnUserActivity() {
+ if (auto_login_timer_.IsRunning()) {
bartfab (slow) 2013/02/25 16:51:23 It is pretty obvious what this function is doing b
dconnelly 2013/02/26 18:04:15 Done.
+ 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_ ||
+ public_session_auto_login_username_.empty() ||
+ is_login_in_progress_) {
bartfab (slow) 2013/02/25 16:51:23 Nit: The conditions in lines 956-958 and 967-969 a
dconnelly 2013/02/26 18:04:15 Done.
+ 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();
}

Powered by Google App Engine
This is Rietveld 408576698