OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/user_manager/user_manager_base.h" | 5 #include "components/user_manager/user_manager_base.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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 // Key of obfuscated GAIA id value. | 82 // Key of obfuscated GAIA id value. |
83 const char kGAIAIdKey[] = "gaia_id"; | 83 const char kGAIAIdKey[] = "gaia_id"; |
84 | 84 |
85 // Key of whether this user ID refers to a SAML user. | 85 // Key of whether this user ID refers to a SAML user. |
86 const char kUsingSAMLKey[] = "using_saml"; | 86 const char kUsingSAMLKey[] = "using_saml"; |
87 | 87 |
88 // Key of Device Id. | 88 // Key of Device Id. |
89 const char kDeviceId[] = "device_id"; | 89 const char kDeviceId[] = "device_id"; |
90 | 90 |
| 91 // Key of the reason for re-auth. |
| 92 const char kReauthReasonKey[] = "reauth_reason"; |
| 93 |
91 // Upper bound for a histogram metric reporting the amount of time between | 94 // Upper bound for a histogram metric reporting the amount of time between |
92 // one regular user logging out and a different regular user logging in. | 95 // one regular user logging out and a different regular user logging in. |
93 const int kLogoutToLoginDelayMaxSec = 1800; | 96 const int kLogoutToLoginDelayMaxSec = 1800; |
94 | 97 |
95 // Callback that is called after user removal is complete. | 98 // Callback that is called after user removal is complete. |
96 void OnRemoveUserComplete(const std::string& user_email, | 99 void OnRemoveUserComplete(const std::string& user_email, |
97 bool success, | 100 bool success, |
98 cryptohome::MountError return_code) { | 101 cryptohome::MountError return_code) { |
99 // Log the error, but there's not much we can do. | 102 // Log the error, but there's not much we can do. |
100 if (!success) { | 103 if (!success) { |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 SetKnownUserBooleanPref(user_id, kUsingSAMLKey, using_saml); | 545 SetKnownUserBooleanPref(user_id, kUsingSAMLKey, using_saml); |
543 } | 546 } |
544 | 547 |
545 bool UserManagerBase::FindUsingSAML(const std::string& user_id) { | 548 bool UserManagerBase::FindUsingSAML(const std::string& user_id) { |
546 bool using_saml; | 549 bool using_saml; |
547 if (GetKnownUserBooleanPref(user_id, kUsingSAMLKey, &using_saml)) | 550 if (GetKnownUserBooleanPref(user_id, kUsingSAMLKey, &using_saml)) |
548 return using_saml; | 551 return using_saml; |
549 return false; | 552 return false; |
550 } | 553 } |
551 | 554 |
| 555 void UserManagerBase::UpdateReauthReason(const std::string& user_id, |
| 556 const int reauth_reason) { |
| 557 SetKnownUserIntegerPref(user_id, kReauthReasonKey, reauth_reason); |
| 558 } |
| 559 |
| 560 bool UserManagerBase::FindReauthReason(const std::string& user_id, |
| 561 int* out_value) { |
| 562 return GetKnownUserIntegerPref(user_id, kReauthReasonKey, out_value); |
| 563 } |
| 564 |
552 void UserManagerBase::UpdateUserAccountData( | 565 void UserManagerBase::UpdateUserAccountData( |
553 const std::string& user_id, | 566 const std::string& user_id, |
554 const UserAccountData& account_data) { | 567 const UserAccountData& account_data) { |
555 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 568 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
556 | 569 |
557 SaveUserDisplayName(user_id, account_data.display_name()); | 570 SaveUserDisplayName(user_id, account_data.display_name()); |
558 | 571 |
559 if (User* user = FindUserAndModify(user_id)) { | 572 if (User* user = FindUserAndModify(user_id)) { |
560 base::string16 given_name = account_data.given_name(); | 573 base::string16 given_name = account_data.given_name(); |
561 user->set_given_name(given_name); | 574 user->set_given_name(given_name); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 } else { | 843 } else { |
831 user = User::CreateRegularUser(*it); | 844 user = User::CreateRegularUser(*it); |
832 int user_type; | 845 int user_type; |
833 if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) && | 846 if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) && |
834 user_type == USER_TYPE_CHILD) { | 847 user_type == USER_TYPE_CHILD) { |
835 ChangeUserChildStatus(user, true /* is child */); | 848 ChangeUserChildStatus(user, true /* is child */); |
836 } | 849 } |
837 } | 850 } |
838 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | 851 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); |
839 user->set_force_online_signin(LoadForceOnlineSignin(*it)); | 852 user->set_force_online_signin(LoadForceOnlineSignin(*it)); |
| 853 user->set_using_saml(FindUsingSAML(*it)); |
840 users_.push_back(user); | 854 users_.push_back(user); |
841 | 855 |
842 base::string16 display_name; | 856 base::string16 display_name; |
843 if (prefs_display_names->GetStringWithoutPathExpansion(*it, | 857 if (prefs_display_names->GetStringWithoutPathExpansion(*it, |
844 &display_name)) { | 858 &display_name)) { |
845 user->set_display_name(display_name); | 859 user->set_display_name(display_name); |
846 } | 860 } |
847 | 861 |
848 base::string16 given_name; | 862 base::string16 given_name; |
849 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { | 863 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 | 1082 |
1069 void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, | 1083 void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, |
1070 const std::string& path, | 1084 const std::string& path, |
1071 const bool in_value) { | 1085 const bool in_value) { |
1072 ListPrefUpdate update(GetLocalState(), kKnownUsers); | 1086 ListPrefUpdate update(GetLocalState(), kKnownUsers); |
1073 base::DictionaryValue dict; | 1087 base::DictionaryValue dict; |
1074 dict.SetBoolean(path, in_value); | 1088 dict.SetBoolean(path, in_value); |
1075 UpdateKnownUserPrefs(user_id, dict, false); | 1089 UpdateKnownUserPrefs(user_id, dict, false); |
1076 } | 1090 } |
1077 | 1091 |
| 1092 bool UserManagerBase::GetKnownUserIntegerPref(const UserID& user_id, |
| 1093 const std::string& path, |
| 1094 int* out_value) { |
| 1095 const base::DictionaryValue* user_pref_dict = nullptr; |
| 1096 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) |
| 1097 return false; |
| 1098 return user_pref_dict->GetInteger(path, out_value); |
| 1099 } |
| 1100 |
| 1101 void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id, |
| 1102 const std::string& path, |
| 1103 const int in_value) { |
| 1104 ListPrefUpdate update(GetLocalState(), kKnownUsers); |
| 1105 base::DictionaryValue dict; |
| 1106 dict.SetInteger(path, in_value); |
| 1107 UpdateKnownUserPrefs(user_id, dict, false); |
| 1108 } |
| 1109 |
1078 void UserManagerBase::UpdateGaiaID(const UserID& user_id, | 1110 void UserManagerBase::UpdateGaiaID(const UserID& user_id, |
1079 const std::string& gaia_id) { | 1111 const std::string& gaia_id) { |
1080 SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id); | 1112 SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id); |
1081 } | 1113 } |
1082 | 1114 |
1083 bool UserManagerBase::FindGaiaID(const UserID& user_id, | 1115 bool UserManagerBase::FindGaiaID(const UserID& user_id, |
1084 std::string* out_value) { | 1116 std::string* out_value) { |
1085 return GetKnownUserStringPref(user_id, kGAIAIdKey, out_value); | 1117 return GetKnownUserStringPref(user_id, kGAIAIdKey, out_value); |
1086 } | 1118 } |
1087 | 1119 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 } | 1290 } |
1259 | 1291 |
1260 void UserManagerBase::DeleteUser(User* user) { | 1292 void UserManagerBase::DeleteUser(User* user) { |
1261 const bool is_active_user = (user == active_user_); | 1293 const bool is_active_user = (user == active_user_); |
1262 delete user; | 1294 delete user; |
1263 if (is_active_user) | 1295 if (is_active_user) |
1264 active_user_ = NULL; | 1296 active_user_ = NULL; |
1265 } | 1297 } |
1266 | 1298 |
1267 } // namespace user_manager | 1299 } // namespace user_manager |
OLD | NEW |