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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 143873012: Add local state flag to force online login for a user (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/chromeos/login/user_manager_impl.h" 5 #include "chrome/browser/chromeos/login/user_manager_impl.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // A vector pref of the public accounts defined on this device. 77 // A vector pref of the public accounts defined on this device.
78 const char kPublicAccounts[] = "PublicAccounts"; 78 const char kPublicAccounts[] = "PublicAccounts";
79 79
80 // A string pref that gets set when a public account is removed but a user is 80 // A string pref that gets set when a public account is removed but a user is
81 // currently logged into that account, requiring the account's data to be 81 // currently logged into that account, requiring the account's data to be
82 // removed after logout. 82 // removed after logout.
83 const char kPublicAccountPendingDataRemoval[] = 83 const char kPublicAccountPendingDataRemoval[] =
84 "PublicAccountPendingDataRemoval"; 84 "PublicAccountPendingDataRemoval";
85 85
86 // A dictionary that maps usernames to the displayed name. 86 // A dictionary that maps user IDs to the displayed name.
87 const char kUserDisplayName[] = "UserDisplayName"; 87 const char kUserDisplayName[] = "UserDisplayName";
88 88
89 // A dictionary that maps usernames to the user's given name. 89 // A dictionary that maps user IDs to the user's given name.
90 const char kUserGivenName[] = "UserGivenName"; 90 const char kUserGivenName[] = "UserGivenName";
91 91
92 // A dictionary that maps usernames to the displayed (non-canonical) emails. 92 // A dictionary that maps user IDs to the displayed (non-canonical) emails.
93 const char kUserDisplayEmail[] = "UserDisplayEmail"; 93 const char kUserDisplayEmail[] = "UserDisplayEmail";
94 94
95 // A dictionary that maps usernames to OAuth token presence flag. 95 // A dictionary that maps user IDs to OAuth token presence flag.
96 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; 96 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus";
97 97
98 // A dictionary that maps user IDs to a flag indicating whether online
99 // authentication against GAIA should be enforced during the next sign-in.
100 const char kUserForceOnlineSignin[] = "UserForceOnlineSiginin";
Nikita (slow) 2014/01/23 16:06:56 nit: UserForceOnlineSignin
bartfab (slow) 2014/01/24 12:08:05 Done.
101
98 // A string pref containing the ID of the last user who logged in if it was 102 // A string pref containing the ID of the last user who logged in if it was
99 // a regular user or an empty string if it was another type of user (guest, 103 // a regular user or an empty string if it was another type of user (guest,
100 // kiosk, public account, etc.). 104 // kiosk, public account, etc.).
101 const char kLastLoggedInRegularUser[] = "LastLoggedInRegularUser"; 105 const char kLastLoggedInRegularUser[] = "LastLoggedInRegularUser";
102 106
103 // Upper bound for a histogram metric reporting the amount of time between 107 // Upper bound for a histogram metric reporting the amount of time between
104 // one regular user logging out and a different regular user logging in. 108 // one regular user logging out and a different regular user logging in.
105 const int kLogoutToLoginDelayMaxSec = 1800; 109 const int kLogoutToLoginDelayMaxSec = 1800;
106 110
107 // Callback that is called after user removal is complete. 111 // Callback that is called after user removal is complete.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 168 }
165 169
166 } // namespace 170 } // namespace
167 171
168 // static 172 // static
169 void UserManager::RegisterPrefs(PrefRegistrySimple* registry) { 173 void UserManager::RegisterPrefs(PrefRegistrySimple* registry) {
170 registry->RegisterListPref(kRegularUsers); 174 registry->RegisterListPref(kRegularUsers);
171 registry->RegisterListPref(kPublicAccounts); 175 registry->RegisterListPref(kPublicAccounts);
172 registry->RegisterStringPref(kPublicAccountPendingDataRemoval, ""); 176 registry->RegisterStringPref(kPublicAccountPendingDataRemoval, "");
173 registry->RegisterStringPref(kLastLoggedInRegularUser, ""); 177 registry->RegisterStringPref(kLastLoggedInRegularUser, "");
174 registry->RegisterDictionaryPref(kUserOAuthTokenStatus);
175 registry->RegisterDictionaryPref(kUserDisplayName); 178 registry->RegisterDictionaryPref(kUserDisplayName);
176 registry->RegisterDictionaryPref(kUserGivenName); 179 registry->RegisterDictionaryPref(kUserGivenName);
177 registry->RegisterDictionaryPref(kUserDisplayEmail); 180 registry->RegisterDictionaryPref(kUserDisplayEmail);
181 registry->RegisterDictionaryPref(kUserOAuthTokenStatus);
182 registry->RegisterDictionaryPref(kUserForceOnlineSignin);
178 SupervisedUserManager::RegisterPrefs(registry); 183 SupervisedUserManager::RegisterPrefs(registry);
179 SessionLengthLimiter::RegisterPrefs(registry); 184 SessionLengthLimiter::RegisterPrefs(registry);
180 } 185 }
181 186
182 UserManagerImpl::UserManagerImpl() 187 UserManagerImpl::UserManagerImpl()
183 : cros_settings_(CrosSettings::Get()), 188 : cros_settings_(CrosSettings::Get()),
184 device_local_account_policy_service_(NULL), 189 device_local_account_policy_service_(NULL),
185 user_loading_stage_(STAGE_NOT_LOADED), 190 user_loading_stage_(STAGE_NOT_LOADED),
186 active_user_(NULL), 191 active_user_(NULL),
187 primary_user_(NULL), 192 primary_user_(NULL),
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 User::OAuthTokenStatus oauth_token_status) { 642 User::OAuthTokenStatus oauth_token_status) {
638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
639 644
640 DVLOG(1) << "Saving user OAuth token status in Local State"; 645 DVLOG(1) << "Saving user OAuth token status in Local State";
641 User* user = FindUserAndModify(user_id); 646 User* user = FindUserAndModify(user_id);
642 if (user) 647 if (user)
643 user->set_oauth_token_status(oauth_token_status); 648 user->set_oauth_token_status(oauth_token_status);
644 649
645 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(oauth_token_status); 650 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(oauth_token_status);
646 651
647 // Do not update local store if data stored or cached outside the user's 652 // Do not update local state if data stored or cached outside the user's
648 // cryptohome is to be treated as ephemeral. 653 // cryptohome is to be treated as ephemeral.
649 if (IsUserNonCryptohomeDataEphemeral(user_id)) 654 if (IsUserNonCryptohomeDataEphemeral(user_id))
650 return; 655 return;
651 656
652 PrefService* local_state = g_browser_process->local_state(); 657 PrefService* local_state = g_browser_process->local_state();
653 658
654 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); 659 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus);
655 oauth_status_update->SetWithoutPathExpansion(user_id, 660 oauth_status_update->SetWithoutPathExpansion(user_id,
656 new base::FundamentalValue(static_cast<int>(oauth_token_status))); 661 new base::FundamentalValue(static_cast<int>(oauth_token_status)));
657 } 662 }
658 663
659 User::OAuthTokenStatus UserManagerImpl::LoadUserOAuthStatus( 664 void UserManagerImpl::SaveForceOnlineSignin(const std::string& user_id,
660 const std::string& user_id) const { 665 bool force_online_signin) {
661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
662 667
663 PrefService* local_state = g_browser_process->local_state(); 668 // Do not update local state if data stored or cached outside the user's
664 const base::DictionaryValue* prefs_oauth_status = 669 // cryptohome is to be treated as ephemeral.
665 local_state->GetDictionary(kUserOAuthTokenStatus); 670 if (IsUserNonCryptohomeDataEphemeral(user_id))
666 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; 671 return;
667 if (prefs_oauth_status && 672
668 prefs_oauth_status->GetIntegerWithoutPathExpansion( 673 DictionaryPrefUpdate force_online_update(g_browser_process->local_state(),
669 user_id, &oauth_token_status)) { 674 kUserForceOnlineSignin);
670 User::OAuthTokenStatus result = 675 force_online_update->SetBooleanWithoutPathExpansion(user_id,
671 static_cast<User::OAuthTokenStatus>(oauth_token_status); 676 force_online_signin);
672 if (result == User::OAUTH2_TOKEN_STATUS_INVALID)
673 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(result);
674 return result;
675 }
676 return User::OAUTH_TOKEN_STATUS_UNKNOWN;
677 } 677 }
678 678
679 void UserManagerImpl::SaveUserDisplayName(const std::string& user_id, 679 void UserManagerImpl::SaveUserDisplayName(const std::string& user_id,
680 const base::string16& display_name) { 680 const base::string16& display_name) {
681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
682 682
683 if (User* user = FindUserAndModify(user_id)) { 683 if (User* user = FindUserAndModify(user_id)) {
684 user->set_display_name(display_name); 684 user->set_display_name(display_name);
685 685
686 // Do not update local store if data stored or cached outside the user's 686 // Do not update local state if data stored or cached outside the user's
687 // cryptohome is to be treated as ephemeral. 687 // cryptohome is to be treated as ephemeral.
688 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { 688 if (!IsUserNonCryptohomeDataEphemeral(user_id)) {
689 PrefService* local_state = g_browser_process->local_state(); 689 PrefService* local_state = g_browser_process->local_state();
690 690
691 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName); 691 DictionaryPrefUpdate display_name_update(local_state, kUserDisplayName);
692 display_name_update->SetWithoutPathExpansion( 692 display_name_update->SetWithoutPathExpansion(
693 user_id, 693 user_id,
694 new base::StringValue(display_name)); 694 new base::StringValue(display_name));
695 695
696 supervised_user_manager_->UpdateManagerName(user_id, display_name); 696 supervised_user_manager_->UpdateManagerName(user_id, display_name);
(...skipping 10 matching lines...) Expand all
707 void UserManagerImpl::SaveUserDisplayEmail(const std::string& user_id, 707 void UserManagerImpl::SaveUserDisplayEmail(const std::string& user_id,
708 const std::string& display_email) { 708 const std::string& display_email) {
709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
710 710
711 User* user = FindUserAndModify(user_id); 711 User* user = FindUserAndModify(user_id);
712 if (!user) 712 if (!user)
713 return; // Ignore if there is no such user. 713 return; // Ignore if there is no such user.
714 714
715 user->set_display_email(display_email); 715 user->set_display_email(display_email);
716 716
717 // Do not update local store if data stored or cached outside the user's 717 // Do not update local state if data stored or cached outside the user's
718 // cryptohome is to be treated as ephemeral. 718 // cryptohome is to be treated as ephemeral.
719 if (IsUserNonCryptohomeDataEphemeral(user_id)) 719 if (IsUserNonCryptohomeDataEphemeral(user_id))
720 return; 720 return;
721 721
722 PrefService* local_state = g_browser_process->local_state(); 722 PrefService* local_state = g_browser_process->local_state();
723 723
724 DictionaryPrefUpdate display_email_update(local_state, kUserDisplayEmail); 724 DictionaryPrefUpdate display_email_update(local_state, kUserDisplayEmail);
725 display_email_update->SetWithoutPathExpansion( 725 display_email_update->SetWithoutPathExpansion(
726 user_id, 726 user_id,
727 new base::StringValue(display_email)); 727 new base::StringValue(display_email));
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 &regular_users, &regular_users_set); 1102 &regular_users, &regular_users_set);
1103 for (std::vector<std::string>::const_iterator it = regular_users.begin(); 1103 for (std::vector<std::string>::const_iterator it = regular_users.begin();
1104 it != regular_users.end(); ++it) { 1104 it != regular_users.end(); ++it) {
1105 User* user = NULL; 1105 User* user = NULL;
1106 const std::string domain = gaia::ExtractDomainName(*it); 1106 const std::string domain = gaia::ExtractDomainName(*it);
1107 if (domain == UserManager::kLocallyManagedUserDomain) 1107 if (domain == UserManager::kLocallyManagedUserDomain)
1108 user = User::CreateLocallyManagedUser(*it); 1108 user = User::CreateLocallyManagedUser(*it);
1109 else 1109 else
1110 user = User::CreateRegularUser(*it); 1110 user = User::CreateRegularUser(*it);
1111 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); 1111 user->set_oauth_token_status(LoadUserOAuthStatus(*it));
1112 user->set_force_online_signin(LoadForceOnlineSignin(*it));
1112 users_.push_back(user); 1113 users_.push_back(user);
1113 1114
1114 base::string16 display_name; 1115 base::string16 display_name;
1115 if (prefs_display_names->GetStringWithoutPathExpansion(*it, 1116 if (prefs_display_names->GetStringWithoutPathExpansion(*it,
1116 &display_name)) { 1117 &display_name)) {
1117 user->set_display_name(display_name); 1118 user->set_display_name(display_name);
1118 } 1119 }
1119 1120
1120 base::string16 given_name; 1121 base::string16 given_name;
1121 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { 1122 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1410
1410 // Owner must be first user in session. DeviceSettingsService can't deal with 1411 // Owner must be first user in session. DeviceSettingsService can't deal with
1411 // multiple user and will mix up ownership, crbug.com/230018. 1412 // multiple user and will mix up ownership, crbug.com/230018.
1412 if (GetLoggedInUsers().size() == 1) { 1413 if (GetLoggedInUsers().size() == 1) {
1413 // Indicate to DeviceSettingsService that the owner key may have become 1414 // Indicate to DeviceSettingsService that the owner key may have become
1414 // available. 1415 // available.
1415 DeviceSettingsService::Get()->SetUsername(active_user_->email()); 1416 DeviceSettingsService::Get()->SetUsername(active_user_->email());
1416 } 1417 }
1417 } 1418 }
1418 1419
1420 User::OAuthTokenStatus UserManagerImpl::LoadUserOAuthStatus(
1421 const std::string& user_id) const {
1422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1423
1424 PrefService* local_state = g_browser_process->local_state();
1425 const base::DictionaryValue* prefs_oauth_status =
1426 local_state->GetDictionary(kUserOAuthTokenStatus);
1427 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN;
1428 if (prefs_oauth_status &&
1429 prefs_oauth_status->GetIntegerWithoutPathExpansion(
1430 user_id, &oauth_token_status)) {
1431 User::OAuthTokenStatus result =
1432 static_cast<User::OAuthTokenStatus>(oauth_token_status);
1433 if (result == User::OAUTH2_TOKEN_STATUS_INVALID)
1434 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(result);
1435 return result;
1436 }
1437 return User::OAUTH_TOKEN_STATUS_UNKNOWN;
1438 }
1439
1440 bool UserManagerImpl::LoadForceOnlineSignin(const std::string& user_id) const {
1441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1442
1443 PrefService* local_state = g_browser_process->local_state();
1444 const base::DictionaryValue* prefs_force_online =
1445 local_state->GetDictionary(kUserForceOnlineSignin);
1446 bool force_online_signin = false;
1447 if (prefs_force_online) {
1448 prefs_force_online->GetBooleanWithoutPathExpansion(user_id,
1449 &force_online_signin);
1450 }
1451 return force_online_signin;
1452 }
1453
1419 void UserManagerImpl::UpdateOwnership() { 1454 void UserManagerImpl::UpdateOwnership() {
1420 bool is_owner = DeviceSettingsService::Get()->HasPrivateOwnerKey(); 1455 bool is_owner = DeviceSettingsService::Get()->HasPrivateOwnerKey();
1421 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner"); 1456 VLOG(1) << "Current user " << (is_owner ? "is owner" : "is not owner");
1422 1457
1423 SetCurrentUserIsOwner(is_owner); 1458 SetCurrentUserIsOwner(is_owner);
1424 } 1459 }
1425 1460
1426 void UserManagerImpl::RemoveNonCryptohomeData(const std::string& user_id) { 1461 void UserManagerImpl::RemoveNonCryptohomeData(const std::string& user_id) {
1427 WallpaperManager::Get()->RemoveUserWallpaperInfo(user_id); 1462 WallpaperManager::Get()->RemoveUserWallpaperInfo(user_id);
1428 GetUserImageManager(user_id)->DeleteUserImage(); 1463 GetUserImageManager(user_id)->DeleteUserImage();
1429 1464
1430 PrefService* prefs = g_browser_process->local_state(); 1465 PrefService* prefs = g_browser_process->local_state();
1431 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus);
1432 int oauth_status;
1433 prefs_oauth_update->GetIntegerWithoutPathExpansion(user_id, &oauth_status);
1434 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL);
1435
1436 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); 1466 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName);
1437 prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL); 1467 prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL);
1438 1468
1439 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); 1469 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName);
1440 prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL); 1470 prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL);
1441 1471
1442 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); 1472 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail);
1443 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); 1473 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL);
1444 1474
1475 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus);
1476 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL);
1477
1478 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin);
1479 prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL);
1480
1445 supervised_user_manager_->RemoveNonCryptohomeData(user_id); 1481 supervised_user_manager_->RemoveNonCryptohomeData(user_id);
1446 1482
1447 multi_profile_user_controller_->RemoveCachedValues(user_id); 1483 multi_profile_user_controller_->RemoveCachedValues(user_id);
1448 } 1484 }
1449 1485
1450 User* UserManagerImpl::RemoveRegularOrLocallyManagedUserFromList( 1486 User* UserManagerImpl::RemoveRegularOrLocallyManagedUserFromList(
1451 const std::string& user_id) { 1487 const std::string& user_id) {
1452 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), 1488 ListPrefUpdate prefs_users_update(g_browser_process->local_state(),
1453 kRegularUsers); 1489 kRegularUsers);
1454 prefs_users_update->Clear(); 1490 prefs_users_update->Clear();
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 if (User* user = FindUserAndModify(user_id)) 1926 if (User* user = FindUserAndModify(user_id))
1891 user->SetAccountLocale(resolved_locale); 1927 user->SetAccountLocale(resolved_locale);
1892 } 1928 }
1893 1929
1894 void UserManagerImpl::UpdateNumberOfUsers() { 1930 void UserManagerImpl::UpdateNumberOfUsers() {
1895 base::debug::SetCrashKeyValue(crash_keys::kNumberOfUsers, 1931 base::debug::SetCrashKeyValue(crash_keys::kNumberOfUsers,
1896 base::StringPrintf("%" PRIuS, GetLoggedInUsers().size())); 1932 base::StringPrintf("%" PRIuS, GetLoggedInUsers().size()));
1897 } 1933 }
1898 1934
1899 } // namespace chromeos 1935 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698