Commit 9c486559 authored by pavely@chromium.org's avatar pavely@chromium.org

Revert 275550 "Revert 275046 "ChromeOS login webui refactoring: ..."

Tree doesn't compile, returning to original state.
> Revert 275046 "ChromeOS login webui refactoring: split user sele..."
> 
> Revert change as it likely causes KioskTest failure
> http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%28dbg%29%283%29/builds/35748
> 
> > ChromeOS login webui refactoring: split user selection/gaia login screens.
> > Phase two : move user list processing to UserSelectionScreen
> > 
> > BUG=373314
> > R=nkostylev@chromium.org
> > 
> > Review URL: https://codereview.chromium.org/296823009
> 
> TBR=antrim@chromium.org
> 
> Review URL: https://codereview.chromium.org/317243006

TBR=pavely@chromium.org

Review URL: https://codereview.chromium.org/319273002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275555 0039d316-1c4b-4281-b951-d872f2087c98
parent 98fb1921
......@@ -7,6 +7,8 @@
#include "base/values.h"
#include "chrome/browser/chromeos/login/help_app_launcher.h"
#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui.h"
......@@ -151,6 +153,9 @@ void AppLaunchSigninScreen::ShowSigninScreenForCreds(
}
const UserList& AppLaunchSigninScreen::GetUsers() const {
if (test_user_manager_) {
return test_user_manager_->GetUsers();
}
return owner_user_list_;
}
......@@ -162,10 +167,6 @@ bool AppLaunchSigninScreen::IsShowUsers() const {
return true;
}
bool AppLaunchSigninScreen::IsShowNewUser() const {
return false;
}
bool AppLaunchSigninScreen::IsSigninInProgress() const {
// Return true to suppress network processing in the signin screen.
return true;
......@@ -202,4 +203,33 @@ void AppLaunchSigninScreen::OnLoginSuccess(const UserContext& user_context) {
delegate_->OnOwnerSigninSuccess();
}
void AppLaunchSigninScreen::HandleGetUsers() {
base::ListValue users_list;
const UserList& users = GetUsers();
for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
ScreenlockBridge::LockHandler::AuthType initial_auth_type =
UserSelectionScreen::ShouldForceOnlineSignIn(*it)
? ScreenlockBridge::LockHandler::ONLINE_SIGN_IN
: ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
base::DictionaryValue* user_dict = new base::DictionaryValue();
UserSelectionScreen::FillUserDictionary(
*it, true, false, initial_auth_type, user_dict);
users_list.Append(user_dict);
}
webui_handler_->LoadUsers(users_list, false, false);
}
void AppLaunchSigninScreen::SetAuthType(
const std::string& username,
ScreenlockBridge::LockHandler::AuthType auth_type) {
return;
}
ScreenlockBridge::LockHandler::AuthType AppLaunchSigninScreen::GetAuthType(
const std::string& username) const {
return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
}
} // namespace chromeos
......@@ -452,6 +452,9 @@ class KioskTest : public OobeBaseTest {
}
void RunAppLaunchNetworkDownTest() {
mock_user_manager()->SetActiveUser(kTestOwnerEmail);
AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager());
// Mock network could be configured with owner's password.
ScopedCanConfigureNetwork can_configure_network(true, true);
......@@ -465,8 +468,6 @@ class KioskTest : public OobeBaseTest {
JsExpect("$('splash-config-network').hidden == false");
// Set up fake user manager with an owner for the test.
mock_user_manager()->SetActiveUser(kTestOwnerEmail);
AppLaunchSigninScreen::SetUserManagerForTesting(mock_user_manager());
static_cast<LoginDisplayHostImpl*>(LoginDisplayHostImpl::default_host())
->GetOobeUI()->ShowOobeUI(false);
......
......@@ -4,24 +4,144 @@
#include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
#include "ash/shell.h"
#include "base/logging.h"
#include "chrome/browser/chromeos/login/screens/screen_observer.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/common/pref_names.h"
#include "ui/wm/core/user_activity_detector.h"
namespace chromeos {
namespace {
// User dictionary keys.
const char kKeyUsername[] = "username";
const char kKeyDisplayName[] = "displayName";
const char kKeyEmailAddress[] = "emailAddress";
const char kKeyEnterpriseDomain[] = "enterpriseDomain";
const char kKeyPublicAccount[] = "publicAccount";
const char kKeyLocallyManagedUser[] = "locallyManagedUser";
const char kKeySignedIn[] = "signedIn";
const char kKeyCanRemove[] = "canRemove";
const char kKeyIsOwner[] = "isOwner";
const char kKeyInitialAuthType[] = "initialAuthType";
const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed";
const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy";
// Max number of users to show.
const size_t kMaxUsers = 18;
const int kPasswordClearTimeoutSec = 60;
} // namespace
UserSelectionScreen::UserSelectionScreen() : handler_(NULL) {
}
UserSelectionScreen::~UserSelectionScreen() {
wm::UserActivityDetector* activity_detector =
ash::Shell::GetInstance()->user_activity_detector();
if (activity_detector->HasObserver(this))
activity_detector->RemoveObserver(this);
}
// static
void UserSelectionScreen::FillUserDictionary(
User* user,
bool is_owner,
bool is_signin_to_add,
ScreenlockBridge::LockHandler::AuthType auth_type,
base::DictionaryValue* user_dict) {
const std::string& user_id = user->email();
const bool is_public_account =
user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT;
const bool is_locally_managed_user =
user->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
user_dict->SetString(kKeyUsername, user_id);
user_dict->SetString(kKeyEmailAddress, user->display_email());
user_dict->SetString(kKeyDisplayName, user->GetDisplayName());
user_dict->SetBoolean(kKeyPublicAccount, is_public_account);
user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user);
user_dict->SetInteger(kKeyInitialAuthType, auth_type);
user_dict->SetBoolean(kKeySignedIn, user->is_logged_in());
user_dict->SetBoolean(kKeyIsOwner, is_owner);
// Fill in multi-profiles related fields.
if (is_signin_to_add) {
MultiProfileUserController* multi_profile_user_controller =
UserManager::Get()->GetMultiProfileUserController();
std::string behavior =
multi_profile_user_controller->GetCachedValue(user_id);
user_dict->SetBoolean(kKeyMultiProfilesAllowed,
multi_profile_user_controller->IsUserAllowedInSession(
user_id) == MultiProfileUserController::ALLOWED);
user_dict->SetString(kKeyMultiProfilesPolicy, behavior);
} else {
user_dict->SetBoolean(kKeyMultiProfilesAllowed, true);
}
if (is_public_account) {
policy::BrowserPolicyConnectorChromeOS* policy_connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (policy_connector->IsEnterpriseManaged()) {
user_dict->SetString(kKeyEnterpriseDomain,
policy_connector->GetEnterpriseDomain());
}
}
}
// static
bool UserSelectionScreen::ShouldForceOnlineSignIn(const User* user) {
// Public sessions are always allowed to log in offline.
// Supervised user are allowed to log in offline if their OAuth token status
// is unknown or valid.
// For all other users, force online sign in if:
// * The flag to force online sign-in is set for the user.
// * The user's OAuth token is invalid.
// * The user's OAuth token status is unknown (except supervised users,
// see above).
if (user->is_logged_in())
return false;
const User::OAuthTokenStatus token_status = user->oauth_token_status();
const bool is_locally_managed_user =
user->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
const bool is_public_session =
user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT;
if (is_locally_managed_user &&
token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN) {
return false;
}
if (is_public_session)
return false;
return user->force_online_signin() ||
(token_status == User::OAUTH2_TOKEN_STATUS_INVALID) ||
(token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN);
}
void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) {
handler_ = handler;
}
void UserSelectionScreen::Init(const UserList& users) {
void UserSelectionScreen::Init(const UserList& users, bool show_guest) {
users_ = users;
show_guest_ = show_guest;
wm::UserActivityDetector* activity_detector =
ash::Shell::GetInstance()->user_activity_detector();
if (!activity_detector->HasObserver(this))
activity_detector->AddObserver(this);
}
void UserSelectionScreen::OnBeforeUserRemoved(const std::string& username) {
......@@ -51,4 +171,102 @@ const UserList& UserSelectionScreen::GetUsers() const {
return users_;
}
void UserSelectionScreen::OnPasswordClearTimerExpired() {
if (handler_)
handler_->ClearUserPodPassword();
}
void UserSelectionScreen::OnUserActivity(const ui::Event* event) {
if (!password_clear_timer_.IsRunning()) {
password_clear_timer_.Start(
FROM_HERE,
base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec),
this,
&UserSelectionScreen::OnPasswordClearTimerExpired);
}
password_clear_timer_.Reset();
}
void UserSelectionScreen::SendUserList(bool animated) {
base::ListValue users_list;
const UserList& users = GetUsers();
// TODO(nkostylev): Move to a separate method in UserManager.
// http://crbug.com/230852
bool is_signin_to_add = LoginDisplayHostImpl::default_host() &&
UserManager::Get()->IsUserLoggedIn();
user_auth_type_map_.clear();
bool single_user = users.size() == 1;
std::string owner;
chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
bool has_owner = owner.size() > 0;
size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers;
size_t non_owner_count = 0;
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
bool is_enterprise_managed = connector->IsEnterpriseManaged();
for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
const std::string& user_id = (*it)->email();
bool is_owner = (user_id == owner);
bool is_public_account =
((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT);
if ((is_public_account && !is_signin_to_add) || is_owner ||
(!is_public_account && non_owner_count < max_non_owner_users)) {
ScreenlockBridge::LockHandler::AuthType initial_auth_type =
ShouldForceOnlineSignIn(*it)
? ScreenlockBridge::LockHandler::ONLINE_SIGN_IN
: ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
user_auth_type_map_[user_id] = initial_auth_type;
base::DictionaryValue* user_dict = new base::DictionaryValue();
FillUserDictionary(
*it, is_owner, is_signin_to_add, initial_auth_type, user_dict);
bool signed_in = (*it)->is_logged_in();
// Single user check here is necessary because owner info might not be
// available when running into login screen on first boot.
// See http://crosbug.com/12723
bool can_remove_user =
((!single_user || is_enterprise_managed) && !user_id.empty() &&
!is_owner && !is_public_account && !signed_in && !is_signin_to_add);
user_dict->SetBoolean(kKeyCanRemove, can_remove_user);
if (!is_owner)
++non_owner_count;
if (is_owner && users_list.GetSize() > kMaxUsers) {
// Owner is always in the list.
users_list.Insert(kMaxUsers - 1, user_dict);
while (users_list.GetSize() > kMaxUsers)
users_list.Remove(kMaxUsers, NULL);
} else if (users_list.GetSize() < kMaxUsers) {
users_list.Append(user_dict);
}
}
}
handler_->LoadUsers(users_list, animated, show_guest_);
}
void UserSelectionScreen::HandleGetUsers() {
SendUserList(false);
}
void UserSelectionScreen::SetAuthType(
const std::string& username,
ScreenlockBridge::LockHandler::AuthType auth_type) {
user_auth_type_map_[username] = auth_type;
}
ScreenlockBridge::LockHandler::AuthType UserSelectionScreen::GetAuthType(
const std::string& username) const {
if (user_auth_type_map_.find(username) == user_auth_type_map_.end())
return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
return user_auth_type_map_.find(username)->second;
}
} // namespace chromeos
......@@ -5,36 +5,74 @@
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_SELECTION_SCREEN_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_SELECTION_SCREEN_H_
#include <map>
#include <string>
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/users/user.h"
#include "chrome/browser/signin/screenlock_bridge.h"
#include "ui/wm/core/user_activity_observer.h"
namespace chromeos {
class LoginDisplayWebUIHandler;
// This class represents User Selection screen: user pod-based login screen.
class UserSelectionScreen {
class UserSelectionScreen : public wm::UserActivityObserver {
public:
UserSelectionScreen();
virtual ~UserSelectionScreen();
void SetHandler(LoginDisplayWebUIHandler* handler);
void Init(const UserList& users);
void Init(const UserList& users, bool show_guest);
const UserList& GetUsers() const;
void OnUserImageChanged(const User& user);
void OnBeforeUserRemoved(const std::string& username);
void OnUserRemoved(const std::string& username);
void OnPasswordClearTimerExpired();
void SendUserList(bool animated);
void HandleGetUsers();
void SetAuthType(const std::string& username,
ScreenlockBridge::LockHandler::AuthType auth_type);
ScreenlockBridge::LockHandler::AuthType GetAuthType(
const std::string& username) const;
// wm::UserActivityDetector implementation:
virtual void OnUserActivity(const ui::Event* event) OVERRIDE;
// Fills |user_dict| with information about |user|.
static void FillUserDictionary(
User* user,
bool is_owner,
bool is_signin_to_add,
ScreenlockBridge::LockHandler::AuthType auth_type,
base::DictionaryValue* user_dict);
// Determines if user auth status requires online sign in.
static bool ShouldForceOnlineSignIn(const User* user);
private:
LoginDisplayWebUIHandler* handler_;
// Set of Users that are visible.
UserList users_;
// Whether to show guest login.
bool show_guest_;
// Map of usernames to their current authentication type. If a user is not
// contained in the map, it is using the default authentication type.
std::map<std::string, ScreenlockBridge::LockHandler::AuthType>
user_auth_type_map_;
// Timer for measuring idle state duration before password clear.
base::OneShotTimer<UserSelectionScreen> password_clear_timer_;
DISALLOW_COPY_AND_ASSIGN(UserSelectionScreen);
};
......
......@@ -23,12 +23,6 @@
namespace chromeos {
namespace {
const int kPasswordClearTimeoutSec = 60;
}
// WebUILoginDisplay, public: --------------------------------------------------
WebUILoginDisplay::~WebUILoginDisplay() {
......@@ -63,7 +57,7 @@ void WebUILoginDisplay::Init(const UserList& users,
// Testing that the delegate has been set.
DCHECK(delegate_);
user_selection_screen_->Init(users);
user_selection_screen_->Init(users, show_guest);
show_guest_ = show_guest;
show_users_ = show_users;
show_new_user_ = show_new_user;
......@@ -90,12 +84,27 @@ void WebUILoginDisplay::OnUserImageChanged(const User& user) {
user_selection_screen_->OnUserImageChanged(user);
}
// User selection screen, screen lock API
void WebUILoginDisplay::HandleGetUsers() {
user_selection_screen_->HandleGetUsers();
}
const UserList& WebUILoginDisplay::GetUsers() const {
return user_selection_screen_->GetUsers();
}
// User selection screen, screen lock API
void WebUILoginDisplay::SetAuthType(
const std::string& username,
ScreenlockBridge::LockHandler::AuthType auth_type) {
user_selection_screen_->SetAuthType(username, auth_type);
}
ScreenlockBridge::LockHandler::AuthType WebUILoginDisplay::GetAuthType(
const std::string& username) const {
return user_selection_screen_->GetAuthType(username);
}
// ---- Gaia screen methods
// ---- Not yet classified methods
......@@ -333,10 +342,6 @@ bool WebUILoginDisplay::IsShowUsers() const {
return show_users_;
}
bool WebUILoginDisplay::IsShowNewUser() const {
return show_new_user_;
}
bool WebUILoginDisplay::IsSigninInProgress() const {
return delegate_->IsSigninInProgress();
}
......@@ -360,23 +365,9 @@ void WebUILoginDisplay::LoginAsKioskApp(const std::string& app_id,
}
void WebUILoginDisplay::OnUserActivity(const ui::Event* event) {
if (!password_clear_timer_.IsRunning())
StartPasswordClearTimer();
password_clear_timer_.Reset();
if (delegate_)
delegate_->ResetPublicSessionAutoLoginTimer();
}
void WebUILoginDisplay::StartPasswordClearTimer() {
DCHECK(!password_clear_timer_.IsRunning());
password_clear_timer_.Start(FROM_HERE,
base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), this,
&WebUILoginDisplay::OnPasswordClearTimerExpired);
}
void WebUILoginDisplay::OnPasswordClearTimerExpired() {
if (webui_handler_)
webui_handler_->ClearUserPodPassword();
}
} // namespace chromeos
......@@ -9,7 +9,6 @@
#include <vector>
#include "base/compiler_specific.h"
#include "base/timer/timer.h"
#include "chrome/browser/chromeos/login/screens/gaia_screen.h"
#include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
#include "chrome/browser/chromeos/login/ui/login_display.h"
......@@ -77,20 +76,23 @@ class WebUILoginDisplay : public LoginDisplay,
virtual const UserList& GetUsers() const OVERRIDE;
virtual bool IsShowGuest() const OVERRIDE;
virtual bool IsShowUsers() const OVERRIDE;
virtual bool IsShowNewUser() const OVERRIDE;
virtual bool IsSigninInProgress() const OVERRIDE;
virtual bool IsUserSigninCompleted() const OVERRIDE;
virtual void SetDisplayEmail(const std::string& email) OVERRIDE;
virtual void Signout() OVERRIDE;
virtual void LoginAsKioskApp(const std::string& app_id,
bool diagnostic_mode) OVERRIDE;
virtual void HandleGetUsers() OVERRIDE;
virtual void SetAuthType(
const std::string& username,
ScreenlockBridge::LockHandler::AuthType auth_type) OVERRIDE;
virtual ScreenlockBridge::LockHandler::AuthType GetAuthType(
const std::string& username) const OVERRIDE;
// wm::UserActivityDetector implementation:
virtual void OnUserActivity(const ui::Event* event) OVERRIDE;
private:
void StartPasswordClearTimer();
void OnPasswordClearTimerExpired();
// Whether to show guest login.
bool show_guest_;
......@@ -102,9 +104,6 @@ class WebUILoginDisplay : public LoginDisplay,
// Whether to show add new user.
bool show_new_user_;
// Timer for measuring idle state duration before password clear.
base::OneShotTimer<WebUILoginDisplay> password_clear_timer_;
// Reference to the WebUI handling layer for the login screen
LoginDisplayWebUIHandler* webui_handler_;
......
......@@ -1019,6 +1019,9 @@ void UserManagerImpl::OnExternalDataFetched(const std::string& policy,
}
void UserManagerImpl::OnPolicyUpdated(const std::string& user_id) {
const User* user = FindUserInList(user_id);
if (!user || user->GetType() != User::USER_TYPE_PUBLIC_ACCOUNT)
return;
UpdatePublicAccountDisplayName(user_id);
NotifyUserListChanged();
}
......
......@@ -8,12 +8,12 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_flow.h"
#include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
#include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
#include "chrome/browser/chromeos/login/users/user_manager.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/common/url_constants.h"
#include "chromeos/audio/chromeos_sounds.h"
#include "google_apis/gaia/gaia_auth_util.h"
......@@ -220,7 +220,7 @@ void LocallyManagedUserCreationScreenHandler::Show() {
continue;
bool is_owner = ((*it)->email() == owner);
base::DictionaryValue* user_dict = new base::DictionaryValue();
SigninScreenHandler::FillUserDictionary(
UserSelectionScreen::FillUserDictionary(
*it,
is_owner,
false /* is_signin_to_add */,
......
......@@ -82,20 +82,6 @@ using content::BrowserThread;
namespace {
// User dictionary keys.
const char kKeyUsername[] = "username";
const char kKeyDisplayName[] = "displayName";
const char kKeyEmailAddress[] = "emailAddress";
const char kKeyEnterpriseDomain[] = "enterpriseDomain";
const char kKeyPublicAccount[] = "publicAccount";
const char kKeyLocallyManagedUser[] = "locallyManagedUser";
const char kKeySignedIn[] = "signedIn";
const char kKeyCanRemove[] = "canRemove";
const char kKeyIsOwner[] = "isOwner";
const char kKeyInitialAuthType[] = "initialAuthType";
const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed";
const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy";
// Max number of users to show.
const size_t kMaxUsers = 18;
......@@ -234,37 +220,6 @@ void RecordSAMLScrapingVerificationResultInHistogram(bool success) {
UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success);
}
bool ShouldForceOnlineSignIn(const User* user) {
// Public sessions are always allowed to log in offline.
// Supervised user are allowed to log in offline if their OAuth token status
// is unknown or valid.
// For all other users, force online sign in if:
// * The flag to force online sign-in is set for the user.
// * The user's OAuth token is invalid.
// * The user's OAuth token status is unknown (except supervised users,
// see above).
if (user->is_logged_in())
return false;
const User::OAuthTokenStatus token_status = user->oauth_token_status();
const bool is_locally_managed_user =
user->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
const bool is_public_session =
user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT;
if (is_locally_managed_user &&
token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN) {
return false;
}
if (is_public_session)
return false;
return user->force_online_signin() ||
(token_status == User::OAUTH2_TOKEN_STATUS_INVALID) ||
(token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN);
}
} // namespace
// LoginScreenContext implementation ------------------------------------------
......@@ -518,7 +473,7 @@ void SigninScreenHandler::ShowImpl() {
} else {
// Populates account picker. Animation is turned off for now until we
// figure out how to make it fast enough.
SendUserList(false);
delegate_->HandleGetUsers();
// Reset Caps Lock state when login screen is shown.
input_method::InputMethodManager::Get()
......@@ -821,7 +776,8 @@ void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) {
}
void SigninScreenHandler::HandleGetUsers() {
SendUserList(false);
if (delegate_)
delegate_->HandleGetUsers();
}
void SigninScreenHandler::ClearAndEnablePassword() {
......@@ -859,7 +815,8 @@ void SigninScreenHandler::OnPreferencesChanged() {
if (delegate_ && !delegate_->IsShowUsers()) {
HandleShowAddUser(NULL);
} else {
SendUserList(false);
if (delegate_)
delegate_->HandleGetUsers();
UpdateUIState(UI_STATE_ACCOUNT_PICKER, NULL);
}
preferences_changed_delayed_ = false;
......@@ -1001,7 +958,8 @@ void SigninScreenHandler::SetAuthType(
const std::string& username,
ScreenlockBridge::LockHandler::AuthType auth_type,
const std::string& initial_value) {
user_auth_type_map_[username] = auth_type;
delegate_->SetAuthType(username, auth_type);
CallJS("login.AccountPickerScreen.setAuthType",
username,
static_cast<int>(auth_type),
......@@ -1010,9 +968,7 @@ void SigninScreenHandler::SetAuthType(
ScreenlockBridge::LockHandler::AuthType SigninScreenHandler::GetAuthType(
const std::string& username) const {
if (user_auth_type_map_.find(username) == user_auth_type_map_.end())
return OFFLINE_PASSWORD;
return user_auth_type_map_.find(username)->second;
return delegate_->GetAuthType(username);
}
void SigninScreenHandler::Unlock(const std::string& user_email) {
......@@ -1318,122 +1274,12 @@ void SigninScreenHandler::HandleToggleKioskAutolaunchScreen() {
delegate_->ShowKioskAutolaunchScreen();
}
void SigninScreenHandler::FillUserDictionary(
User* user,
bool is_owner,
bool is_signin_to_add,
ScreenlockBridge::LockHandler::AuthType auth_type,
base::DictionaryValue* user_dict) {
const std::string& email = user->email();
const bool is_public_account =
user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT;
const bool is_locally_managed_user =
user->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
user_dict->SetString(kKeyUsername, email);
user_dict->SetString(kKeyEmailAddress, user->display_email());
user_dict->SetString(kKeyDisplayName, user->GetDisplayName());
user_dict->SetBoolean(kKeyPublicAccount, is_public_account);
user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user);
user_dict->SetInteger(kKeyInitialAuthType, auth_type);
user_dict->SetBoolean(kKeySignedIn, user->is_logged_in());
user_dict->SetBoolean(kKeyIsOwner, is_owner);
// Fill in multi-profiles related fields.
if (is_signin_to_add) {
MultiProfileUserController* multi_profile_user_controller =
UserManager::Get()->GetMultiProfileUserController();
std::string behavior = multi_profile_user_controller->
GetCachedValue(user->email());
user_dict->SetBoolean(kKeyMultiProfilesAllowed,
multi_profile_user_controller->IsUserAllowedInSession(email) ==
MultiProfileUserController::ALLOWED);
user_dict->SetString(kKeyMultiProfilesPolicy, behavior);
} else {
user_dict->SetBoolean(kKeyMultiProfilesAllowed, true);
}
if (is_public_account) {
policy::BrowserPolicyConnectorChromeOS* policy_connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
if (policy_connector->IsEnterpriseManaged()) {
user_dict->SetString(kKeyEnterpriseDomain,
policy_connector->GetEnterpriseDomain());
}
}
}
void SigninScreenHandler::SendUserList(bool animated) {
if (!delegate_)
return;
TRACE_EVENT_ASYNC_STEP_INTO0("ui",
"ShowLoginWebUI",
LoginDisplayHostImpl::kShowLoginWebUIid,
"SendUserList");
BootTimesLoader::Get()->RecordCurrentStats("login-send-user-list");
base::ListValue users_list;
const UserList& users = delegate_->GetUsers();
// TODO(nkostylev): Move to a separate method in UserManager.
// http://crbug.com/230852
bool is_signin_to_add = LoginDisplayHostImpl::default_host() &&
UserManager::Get()->IsUserLoggedIn();
user_auth_type_map_.clear();
bool single_user = users.size() == 1;
std::string owner;
chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
bool has_owner = owner.size() > 0;
size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers;
size_t non_owner_count = 0;
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->
browser_policy_connector_chromeos();
bool is_enterprise_managed = connector->IsEnterpriseManaged();
for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
const std::string& email = (*it)->email();
bool is_owner = (email == owner);
bool is_public_account =
((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT);
if ((is_public_account && !is_signin_to_add) ||
is_owner ||
(!is_public_account && non_owner_count < max_non_owner_users)) {
AuthType initial_auth_type =
ShouldForceOnlineSignIn(*it) ? ONLINE_SIGN_IN : OFFLINE_PASSWORD;
user_auth_type_map_[email] = initial_auth_type;
base::DictionaryValue* user_dict = new base::DictionaryValue();
FillUserDictionary(
*it, is_owner, is_signin_to_add, initial_auth_type, user_dict);
bool signed_in = (*it)->is_logged_in();
// Single user check here is necessary because owner info might not be
// available when running into login screen on first boot.
// See http://crosbug.com/12723
bool can_remove_user = ((!single_user || is_enterprise_managed) &&
!email.empty() && !is_owner && !is_public_account &&
!signed_in && !is_signin_to_add);
user_dict->SetBoolean(kKeyCanRemove, can_remove_user);
if (!is_owner)
++non_owner_count;
if (is_owner && users_list.GetSize() > kMaxUsers) {
// Owner is always in the list.
users_list.Insert(kMaxUsers - 1, user_dict);
} else {
users_list.Append(user_dict);
}
}
}
while (users_list.GetSize() > kMaxUsers)
users_list.Remove(kMaxUsers, NULL);
CallJS("login.AccountPickerScreen.loadUsers", users_list, animated,
void SigninScreenHandler::LoadUsers(const base::ListValue& users_list,
bool animated,
bool showGuest) {
CallJS("login.AccountPickerScreen.loadUsers",
users_list,
animated,
delegate_->IsShowGuest());
}
......
......@@ -88,6 +88,10 @@ class LoginDisplayWebUIHandler {
// Show sign-in screen for the given credentials.
virtual void ShowSigninScreenForCreds(const std::string& username,
const std::string& password) = 0;
virtual void LoadUsers(const base::ListValue& users_list,
bool animated,
bool show_guest) = 0;
protected:
virtual ~LoginDisplayWebUIHandler() {}
};
......@@ -166,9 +170,6 @@ class SigninScreenHandlerDelegate {
// Public sessions are always shown.
virtual bool IsShowUsers() const = 0;
// Whether new user pod is available.
virtual bool IsShowNewUser() const = 0;
// Returns true if sign in is in progress.
virtual bool IsSigninInProgress() const = 0;
......@@ -186,6 +187,18 @@ class SigninScreenHandlerDelegate {
virtual void LoginAsKioskApp(const std::string& app_id,
bool diagnostic_mode) = 0;
// Request to (re)load user list.
virtual void HandleGetUsers() = 0;
// Set authentication type (for easier unlocking).
virtual void SetAuthType(
const std::string& username,
ScreenlockBridge::LockHandler::AuthType auth_type) = 0;
// Get authentication type (for easier unlocking).
virtual ScreenlockBridge::LockHandler::AuthType GetAuthType(
const std::string& username) const = 0;
protected:
virtual ~SigninScreenHandlerDelegate() {}
};
......@@ -282,6 +295,9 @@ class SigninScreenHandler
virtual void ShowErrorScreen(LoginDisplay::SigninError error_id) OVERRIDE;
virtual void ShowSigninScreenForCreds(const std::string& username,
const std::string& password) OVERRIDE;
virtual void LoadUsers(const base::ListValue& users_list,
bool animated,
bool show_guest) OVERRIDE;
// ui::EventHandler implementation:
virtual void OnKeyEvent(ui::KeyEvent* key) OVERRIDE;
......@@ -370,17 +386,6 @@ class SigninScreenHandler
void HandleLaunchKioskApp(const std::string& app_id, bool diagnostic_mode);
void HandleRetrieveAuthenticatedUserEmail(double attempt_token);
// Fills |user_dict| with information about |user|.
static void FillUserDictionary(
User* user,
bool is_owner,
bool is_signin_to_add,
ScreenlockBridge::LockHandler::AuthType auth_type,
base::DictionaryValue* user_dict);
// Sends user list to account picker.
void SendUserList(bool animated);
// Kick off cookie / local storage cleanup.
void StartClearingCookies(const base::Closure& on_clear_callback);
void OnCookiesCleared(base::Closure on_clear_callback);
......@@ -529,11 +534,6 @@ class SigninScreenHandler
base::Closure kiosk_enable_flow_aborted_callback_for_test_;
// Map of usernames to their current authentication type. If a user is not
// contained in the map, it is using the default authentication type.
std::map<std::string, ScreenlockBridge::LockHandler::AuthType>
user_auth_type_map_;
// Non-owning ptr.
// TODO (ygorshenin@): remove this dependency.
GaiaScreenHandler* gaia_screen_handler_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment