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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc

Issue 168813002: Refactor user pods to use authType property for distinct authentication modes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" 5 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // User dictionary keys. 80 // User dictionary keys.
81 const char kKeyUsername[] = "username"; 81 const char kKeyUsername[] = "username";
82 const char kKeyDisplayName[] = "displayName"; 82 const char kKeyDisplayName[] = "displayName";
83 const char kKeyEmailAddress[] = "emailAddress"; 83 const char kKeyEmailAddress[] = "emailAddress";
84 const char kKeyEnterpriseDomain[] = "enterpriseDomain"; 84 const char kKeyEnterpriseDomain[] = "enterpriseDomain";
85 const char kKeyPublicAccount[] = "publicAccount"; 85 const char kKeyPublicAccount[] = "publicAccount";
86 const char kKeyLocallyManagedUser[] = "locallyManagedUser"; 86 const char kKeyLocallyManagedUser[] = "locallyManagedUser";
87 const char kKeySignedIn[] = "signedIn"; 87 const char kKeySignedIn[] = "signedIn";
88 const char kKeyCanRemove[] = "canRemove"; 88 const char kKeyCanRemove[] = "canRemove";
89 const char kKeyIsOwner[] = "isOwner"; 89 const char kKeyIsOwner[] = "isOwner";
90 const char kKeyForceOnlineSignin[] = "forceOnlineSignin"; 90 const char kKeyInitialAuthType[] = "initialAuthType";
91 const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed"; 91 const char kKeyMultiProfilesAllowed[] = "isMultiProfilesAllowed";
92 const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy"; 92 const char kKeyMultiProfilesPolicy[] = "multiProfilesPolicy";
93 93
94 // Max number of users to show. 94 // Max number of users to show.
95 const size_t kMaxUsers = 18; 95 const size_t kMaxUsers = 18;
96 96
97 // Timeout to delay first notification about offline state for a 97 // Timeout to delay first notification about offline state for a
98 // current network. 98 // current network.
99 const int kOfflineTimeoutSec = 5; 99 const int kOfflineTimeoutSec = 5;
100 100
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 manager->ChangeInputMethod(input_method); 223 manager->ChangeInputMethod(input_method);
224 224
225 return true; 225 return true;
226 } 226 }
227 227
228 void RecordSAMLScrapingVerificationResultInHistogram(bool success) { 228 void RecordSAMLScrapingVerificationResultInHistogram(bool success) {
229 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success); 229 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success);
230 } 230 }
231 231
232 bool ShouldForceOnlineSignIn(const User* user) {
233 // Force online sign-in if at least one of the following is true:
234 // * The flag to force online sign-in is set for the user.
235 // * The user's oauth token is invalid.
236 // * The user's oauth token status is unknown. This condition does not apply
237 // to supervised users: A supervised user whose oauth token status is
238 // unknown may still log in offline. The token will be invalidated inside
239 // the session in case it has been revoked.
240 const bool is_locally_managed_user =
241 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
242 const User::OAuthTokenStatus token_status = user->oauth_token_status();
243 return user->force_online_signin() ||
244 (token_status == User::OAUTH2_TOKEN_STATUS_INVALID) ||
245 (!is_locally_managed_user &&
246 token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN);
247 }
248
232 } // namespace 249 } // namespace
233 250
234 // LoginScreenContext implementation ------------------------------------------ 251 // LoginScreenContext implementation ------------------------------------------
235 252
236 LoginScreenContext::LoginScreenContext() { 253 LoginScreenContext::LoginScreenContext() {
237 Init(); 254 Init();
238 } 255 }
239 256
240 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { 257 LoginScreenContext::LoginScreenContext(const base::ListValue* args) {
241 Init(); 258 Init();
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 } 849 }
833 850
834 void SigninScreenHandler::ShowUserPodButton( 851 void SigninScreenHandler::ShowUserPodButton(
835 const std::string& username, 852 const std::string& username,
836 const std::string& iconURL, 853 const std::string& iconURL,
837 const base::Closure& click_callback) { 854 const base::Closure& click_callback) {
838 user_pod_button_callback_map_[username] = click_callback; 855 user_pod_button_callback_map_[username] = click_callback;
839 CallJS("login.AccountPickerScreen.showUserPodButton", username, iconURL); 856 CallJS("login.AccountPickerScreen.showUserPodButton", username, iconURL);
840 } 857 }
841 858
859 void SigninScreenHandler::HideUserPodButton(const std::string& username) {
860 CallJS("login.AccountPickerScreen.hideUserPodButton", username);
861 }
862
863 void SigninScreenHandler::SetAuthType(const std::string& username,
864 LoginDisplay::AuthType auth_type,
865 const std::string& initial_value) {
866 user_auth_type_map_[username] = auth_type;
867 CallJS("login.AccountPickerScreen.setAuthType",
868 username,
869 static_cast<int>(auth_type),
870 base::StringValue(initial_value));
871 }
872
873 LoginDisplay::AuthType SigninScreenHandler::GetAuthType(
874 const std::string& username) const {
875 if (user_auth_type_map_.find(username) == user_auth_type_map_.end())
876 return LoginDisplay::SYSTEM_PASSWORD;
877 return user_auth_type_map_.find(username)->second;
878 }
879
842 void SigninScreenHandler::ShowError(int login_attempts, 880 void SigninScreenHandler::ShowError(int login_attempts,
843 const std::string& error_text, 881 const std::string& error_text,
844 const std::string& help_link_text, 882 const std::string& help_link_text,
845 HelpAppLauncher::HelpTopic help_topic_id) { 883 HelpAppLauncher::HelpTopic help_topic_id) {
846 core_oobe_actor_->ShowSignInError(login_attempts, error_text, help_link_text, 884 core_oobe_actor_->ShowSignInError(login_attempts, error_text, help_link_text,
847 help_topic_id); 885 help_topic_id);
848 } 886 }
849 887
850 void SigninScreenHandler::ShowErrorScreen(LoginDisplay::SigninError error_id) { 888 void SigninScreenHandler::ShowErrorScreen(LoginDisplay::SigninError error_id) {
851 switch (error_id) { 889 switch (error_id) {
852 case LoginDisplay::TPM_ERROR: 890 case LoginDisplay::TPM_ERROR:
853 core_oobe_actor_->ShowTpmError(); 891 core_oobe_actor_->ShowTpmError();
854 break; 892 break;
855 default: 893 default:
856 NOTREACHED() << "Unknown sign in error"; 894 NOTREACHED() << "Unknown sign in error";
857 break; 895 break;
858 } 896 }
859 } 897 }
860 898
861 void SigninScreenHandler::ShowSigninUI(const std::string& email) { 899 void SigninScreenHandler::ShowSigninUI(const std::string& email) {
862 core_oobe_actor_->ShowSignInUI(email); 900 core_oobe_actor_->ShowSignInUI(email);
863 } 901 }
864 902
865 void SigninScreenHandler::ShowGaiaPasswordChanged(const std::string& username) { 903 void SigninScreenHandler::ShowGaiaPasswordChanged(const std::string& username) {
866 email_ = username; 904 email_ = username;
867 password_changed_for_.insert(email_); 905 password_changed_for_.insert(email_);
868 core_oobe_actor_->ShowSignInUI(email_); 906 core_oobe_actor_->ShowSignInUI(email_);
869 CallJS("login.AccountPickerScreen.forceOnlineSignin", email_); 907 CallJS("login.setAuthType",
908 username,
909 static_cast<int>(LoginDisplay::ONLINE_SIGN_IN),
910 base::StringValue(""));
870 } 911 }
871 912
872 void SigninScreenHandler::ShowPasswordChangedDialog(bool show_password_error) { 913 void SigninScreenHandler::ShowPasswordChangedDialog(bool show_password_error) {
873 core_oobe_actor_->ShowPasswordChangedScreen(show_password_error); 914 core_oobe_actor_->ShowPasswordChangedScreen(show_password_error);
874 } 915 }
875 916
876 void SigninScreenHandler::ShowSigninScreenForCreds( 917 void SigninScreenHandler::ShowSigninScreenForCreds(
877 const std::string& username, 918 const std::string& username,
878 const std::string& password) { 919 const std::string& password) {
879 VLOG(2) << "ShowSigninScreenForCreds for user " << username 920 VLOG(2) << "ShowSigninScreenForCreds for user " << username
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 return; 1259 return;
1219 if (!help_app_.get()) 1260 if (!help_app_.get())
1220 help_app_ = new HelpAppLauncher(GetNativeWindow()); 1261 help_app_ = new HelpAppLauncher(GetNativeWindow());
1221 help_app_->ShowHelpTopic( 1262 help_app_->ShowHelpTopic(
1222 static_cast<HelpAppLauncher::HelpTopic>(help_topic_id)); 1263 static_cast<HelpAppLauncher::HelpTopic>(help_topic_id));
1223 } 1264 }
1224 1265
1225 void SigninScreenHandler::FillUserDictionary(User* user, 1266 void SigninScreenHandler::FillUserDictionary(User* user,
1226 bool is_owner, 1267 bool is_owner,
1227 bool is_signin_to_add, 1268 bool is_signin_to_add,
1269 LoginDisplay::AuthType auth_type,
1228 base::DictionaryValue* user_dict) { 1270 base::DictionaryValue* user_dict) {
1229 const std::string& email = user->email(); 1271 const std::string& email = user->email();
1230 const bool is_public_account = 1272 const bool is_public_account =
1231 user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; 1273 user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT;
1232 const bool is_locally_managed_user = 1274 const bool is_locally_managed_user =
1233 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED; 1275 user->GetType() == User::USER_TYPE_LOCALLY_MANAGED;
1234 const User::OAuthTokenStatus token_status = user->oauth_token_status();
1235
1236 // Force online sign-in if at least one of the following is true:
1237 // * The flag to force online sign-in is set for the user.
1238 // * The user's oauth token is invalid.
1239 // * The user's oauth token status is unknown. This condition does not apply
1240 // to supervised users: A supervised user whose oauth token status is
1241 // unknown may still log in offline. The token will be invalidated inside
1242 // the session in case it has been revoked.
1243 const bool force_online_signin =
1244 user->force_online_signin() ||
1245 (token_status == User::OAUTH2_TOKEN_STATUS_INVALID) ||
1246 (!is_locally_managed_user &&
1247 token_status == User::OAUTH_TOKEN_STATUS_UNKNOWN);
1248 1276
1249 user_dict->SetString(kKeyUsername, email); 1277 user_dict->SetString(kKeyUsername, email);
1250 user_dict->SetString(kKeyEmailAddress, user->display_email()); 1278 user_dict->SetString(kKeyEmailAddress, user->display_email());
1251 user_dict->SetString(kKeyDisplayName, user->GetDisplayName()); 1279 user_dict->SetString(kKeyDisplayName, user->GetDisplayName());
1252 user_dict->SetBoolean(kKeyPublicAccount, is_public_account); 1280 user_dict->SetBoolean(kKeyPublicAccount, is_public_account);
1253 user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user); 1281 user_dict->SetBoolean(kKeyLocallyManagedUser, is_locally_managed_user);
1254 user_dict->SetInteger(kKeyForceOnlineSignin, force_online_signin); 1282 user_dict->SetInteger(kKeyInitialAuthType, auth_type);
1255 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in()); 1283 user_dict->SetBoolean(kKeySignedIn, user->is_logged_in());
1256 user_dict->SetBoolean(kKeyIsOwner, is_owner); 1284 user_dict->SetBoolean(kKeyIsOwner, is_owner);
1257 1285
1258 // Fill in multi-profiles related fields. 1286 // Fill in multi-profiles related fields.
1259 if (is_signin_to_add) { 1287 if (is_signin_to_add) {
1260 MultiProfileUserController* multi_profile_user_controller = 1288 MultiProfileUserController* multi_profile_user_controller =
1261 UserManager::Get()->GetMultiProfileUserController(); 1289 UserManager::Get()->GetMultiProfileUserController();
1262 std::string behavior = multi_profile_user_controller-> 1290 std::string behavior = multi_profile_user_controller->
1263 GetCachedValue(user->email()); 1291 GetCachedValue(user->email());
1264 user_dict->SetBoolean(kKeyMultiProfilesAllowed, 1292 user_dict->SetBoolean(kKeyMultiProfilesAllowed,
(...skipping 26 matching lines...) Expand all
1291 1319
1292 base::ListValue users_list; 1320 base::ListValue users_list;
1293 size_t first_non_public_account_index = 0; 1321 size_t first_non_public_account_index = 0;
1294 const UserList& users = delegate_->GetUsers(); 1322 const UserList& users = delegate_->GetUsers();
1295 1323
1296 // TODO(nkostylev): Move to a separate method in UserManager. 1324 // TODO(nkostylev): Move to a separate method in UserManager.
1297 // http://crbug.com/230852 1325 // http://crbug.com/230852
1298 bool is_signin_to_add = LoginDisplayHostImpl::default_host() && 1326 bool is_signin_to_add = LoginDisplayHostImpl::default_host() &&
1299 UserManager::Get()->IsUserLoggedIn(); 1327 UserManager::Get()->IsUserLoggedIn();
1300 1328
1329 user_pod_button_callback_map_.clear();
1330 user_auth_type_map_.clear();
1331
1301 bool single_user = users.size() == 1; 1332 bool single_user = users.size() == 1;
1302 std::string owner; 1333 std::string owner;
1303 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); 1334 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
1304 bool has_owner = owner.size() > 0; 1335 bool has_owner = owner.size() > 0;
1305 // if public accounts available, that means there's no device owner 1336 // if public accounts available, that means there's no device owner
1306 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers; 1337 size_t max_non_owner_users = has_owner ? kMaxUsers - 1 : kMaxUsers;
1307 size_t non_owner_count = 0; 1338 size_t non_owner_count = 0;
1308 1339
1309 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { 1340 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
1310 const std::string& email = (*it)->email(); 1341 const std::string& email = (*it)->email();
1311 bool is_owner = (email == owner); 1342 bool is_owner = (email == owner);
1312 bool is_public_account = 1343 bool is_public_account =
1313 ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT); 1344 ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT);
1314 1345
1315 if (is_public_account || non_owner_count < max_non_owner_users || 1346 if (is_public_account || non_owner_count < max_non_owner_users ||
1316 is_owner) { 1347 is_owner) {
1348 LoginDisplay::AuthType initial_auth_type =
1349 ShouldForceOnlineSignIn(*it) ? LoginDisplay::ONLINE_SIGN_IN
1350 : LoginDisplay::SYSTEM_PASSWORD;
1351 user_auth_type_map_[email] = initial_auth_type;
1352
1317 base::DictionaryValue* user_dict = new base::DictionaryValue(); 1353 base::DictionaryValue* user_dict = new base::DictionaryValue();
1318 FillUserDictionary(*it, is_owner, is_signin_to_add, user_dict); 1354 FillUserDictionary(
1355 *it, is_owner, is_signin_to_add, initial_auth_type, user_dict);
1319 bool signed_in = (*it)->is_logged_in(); 1356 bool signed_in = (*it)->is_logged_in();
1320 // Single user check here is necessary because owner info might not be 1357 // Single user check here is necessary because owner info might not be
1321 // available when running into login screen on first boot. 1358 // available when running into login screen on first boot.
1322 // See http://crosbug.com/12723 1359 // See http://crosbug.com/12723
1323 bool can_remove_user = !single_user && !email.empty() && !is_owner && 1360 bool can_remove_user = !single_user && !email.empty() && !is_owner &&
1324 !is_public_account && !signed_in && !is_signin_to_add; 1361 !is_public_account && !signed_in && !is_signin_to_add;
1325 user_dict->SetBoolean(kKeyCanRemove, can_remove_user); 1362 user_dict->SetBoolean(kKeyCanRemove, can_remove_user);
1326 1363
1327 if (!is_owner) 1364 if (!is_owner)
1328 ++non_owner_count; 1365 ++non_owner_count;
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 DCHECK(gaia_screen_handler_); 1765 DCHECK(gaia_screen_handler_);
1729 return gaia_screen_handler_->frame_state(); 1766 return gaia_screen_handler_->frame_state();
1730 } 1767 }
1731 1768
1732 net::Error SigninScreenHandler::FrameError() const { 1769 net::Error SigninScreenHandler::FrameError() const {
1733 DCHECK(gaia_screen_handler_); 1770 DCHECK(gaia_screen_handler_);
1734 return gaia_screen_handler_->frame_error(); 1771 return gaia_screen_handler_->frame_error();
1735 } 1772 }
1736 1773
1737 } // namespace chromeos 1774 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698