| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 1009 |
| 996 std::string last_active_user = GetLocalState()->GetString(kLastActiveUser); | 1010 std::string last_active_user = GetLocalState()->GetString(kLastActiveUser); |
| 997 if (user_id == last_active_user) | 1011 if (user_id == last_active_user) |
| 998 GetLocalState()->SetString(kLastActiveUser, std::string()); | 1012 GetLocalState()->SetString(kLastActiveUser, std::string()); |
| 999 } | 1013 } |
| 1000 | 1014 |
| 1001 bool UserManagerBase::FindKnownUserPrefs( | 1015 bool UserManagerBase::FindKnownUserPrefs( |
| 1002 const UserID& user_id, | 1016 const UserID& user_id, |
| 1003 const base::DictionaryValue** out_value) { | 1017 const base::DictionaryValue** out_value) { |
| 1004 PrefService* local_state = GetLocalState(); | 1018 PrefService* local_state = GetLocalState(); |
| 1019 |
| 1020 // Local State may not be initialized in tests. |
| 1021 if (!local_state) |
| 1022 return false; |
| 1023 |
| 1005 const base::ListValue* known_users = local_state->GetList(kKnownUsers); | 1024 const base::ListValue* known_users = local_state->GetList(kKnownUsers); |
| 1006 for (size_t i = 0; i < known_users->GetSize(); ++i) { | 1025 for (size_t i = 0; i < known_users->GetSize(); ++i) { |
| 1007 const base::DictionaryValue* element = nullptr; | 1026 const base::DictionaryValue* element = nullptr; |
| 1008 if (known_users->GetDictionary(i, &element)) { | 1027 if (known_users->GetDictionary(i, &element)) { |
| 1009 if (UserMatches(user_id, *element)) { | 1028 if (UserMatches(user_id, *element)) { |
| 1010 known_users->GetDictionary(i, out_value); | 1029 known_users->GetDictionary(i, out_value); |
| 1011 return true; | 1030 return true; |
| 1012 } | 1031 } |
| 1013 } | 1032 } |
| 1014 } | 1033 } |
| 1015 return false; | 1034 return false; |
| 1016 } | 1035 } |
| 1017 | 1036 |
| 1018 void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id, | 1037 void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id, |
| 1019 const base::DictionaryValue& values, | 1038 const base::DictionaryValue& values, |
| 1020 bool clear) { | 1039 bool clear) { |
| 1021 ListPrefUpdate update(GetLocalState(), kKnownUsers); | 1040 PrefService* local_state = GetLocalState(); |
| 1041 |
| 1042 // Local State may not be initialized in tests. |
| 1043 if (!local_state) |
| 1044 return; |
| 1045 |
| 1046 ListPrefUpdate update(local_state, kKnownUsers); |
| 1022 for (size_t i = 0; i < update->GetSize(); ++i) { | 1047 for (size_t i = 0; i < update->GetSize(); ++i) { |
| 1023 base::DictionaryValue* element = nullptr; | 1048 base::DictionaryValue* element = nullptr; |
| 1024 if (update->GetDictionary(i, &element)) { | 1049 if (update->GetDictionary(i, &element)) { |
| 1025 if (UserMatches(user_id, *element)) { | 1050 if (UserMatches(user_id, *element)) { |
| 1026 if (clear) | 1051 if (clear) |
| 1027 element->Clear(); | 1052 element->Clear(); |
| 1028 element->MergeDictionary(&values); | 1053 element->MergeDictionary(&values); |
| 1029 UpdateIdentity(user_id, *element); | 1054 UpdateIdentity(user_id, *element); |
| 1030 return; | 1055 return; |
| 1031 } | 1056 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1043 const base::DictionaryValue* user_pref_dict = nullptr; | 1068 const base::DictionaryValue* user_pref_dict = nullptr; |
| 1044 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) | 1069 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) |
| 1045 return false; | 1070 return false; |
| 1046 | 1071 |
| 1047 return user_pref_dict->GetString(path, out_value); | 1072 return user_pref_dict->GetString(path, out_value); |
| 1048 } | 1073 } |
| 1049 | 1074 |
| 1050 void UserManagerBase::SetKnownUserStringPref(const UserID& user_id, | 1075 void UserManagerBase::SetKnownUserStringPref(const UserID& user_id, |
| 1051 const std::string& path, | 1076 const std::string& path, |
| 1052 const std::string& in_value) { | 1077 const std::string& in_value) { |
| 1053 ListPrefUpdate update(GetLocalState(), kKnownUsers); | 1078 PrefService* local_state = GetLocalState(); |
| 1079 |
| 1080 // Local State may not be initialized in tests. |
| 1081 if (!local_state) |
| 1082 return; |
| 1083 |
| 1084 ListPrefUpdate update(local_state, kKnownUsers); |
| 1054 base::DictionaryValue dict; | 1085 base::DictionaryValue dict; |
| 1055 dict.SetString(path, in_value); | 1086 dict.SetString(path, in_value); |
| 1056 UpdateKnownUserPrefs(user_id, dict, false); | 1087 UpdateKnownUserPrefs(user_id, dict, false); |
| 1057 } | 1088 } |
| 1058 | 1089 |
| 1059 bool UserManagerBase::GetKnownUserBooleanPref(const UserID& user_id, | 1090 bool UserManagerBase::GetKnownUserBooleanPref(const UserID& user_id, |
| 1060 const std::string& path, | 1091 const std::string& path, |
| 1061 bool* out_value) { | 1092 bool* out_value) { |
| 1062 const base::DictionaryValue* user_pref_dict = nullptr; | 1093 const base::DictionaryValue* user_pref_dict = nullptr; |
| 1063 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) | 1094 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) |
| 1064 return false; | 1095 return false; |
| 1065 | 1096 |
| 1066 return user_pref_dict->GetBoolean(path, out_value); | 1097 return user_pref_dict->GetBoolean(path, out_value); |
| 1067 } | 1098 } |
| 1068 | 1099 |
| 1069 void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, | 1100 void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, |
| 1070 const std::string& path, | 1101 const std::string& path, |
| 1071 const bool in_value) { | 1102 const bool in_value) { |
| 1072 ListPrefUpdate update(GetLocalState(), kKnownUsers); | 1103 PrefService* local_state = GetLocalState(); |
| 1104 |
| 1105 // Local State may not be initialized in tests. |
| 1106 if (!local_state) |
| 1107 return; |
| 1108 |
| 1109 ListPrefUpdate update(local_state, kKnownUsers); |
| 1073 base::DictionaryValue dict; | 1110 base::DictionaryValue dict; |
| 1074 dict.SetBoolean(path, in_value); | 1111 dict.SetBoolean(path, in_value); |
| 1075 UpdateKnownUserPrefs(user_id, dict, false); | 1112 UpdateKnownUserPrefs(user_id, dict, false); |
| 1076 } | 1113 } |
| 1077 | 1114 |
| 1115 bool UserManagerBase::GetKnownUserIntegerPref(const UserID& user_id, |
| 1116 const std::string& path, |
| 1117 int* out_value) { |
| 1118 const base::DictionaryValue* user_pref_dict = nullptr; |
| 1119 if (!FindKnownUserPrefs(user_id, &user_pref_dict)) |
| 1120 return false; |
| 1121 return user_pref_dict->GetInteger(path, out_value); |
| 1122 } |
| 1123 |
| 1124 void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id, |
| 1125 const std::string& path, |
| 1126 const int in_value) { |
| 1127 PrefService* local_state = GetLocalState(); |
| 1128 |
| 1129 // Local State may not be initialized in tests. |
| 1130 if (!local_state) |
| 1131 return; |
| 1132 |
| 1133 ListPrefUpdate update(local_state, kKnownUsers); |
| 1134 base::DictionaryValue dict; |
| 1135 dict.SetInteger(path, in_value); |
| 1136 UpdateKnownUserPrefs(user_id, dict, false); |
| 1137 } |
| 1138 |
| 1078 void UserManagerBase::UpdateGaiaID(const UserID& user_id, | 1139 void UserManagerBase::UpdateGaiaID(const UserID& user_id, |
| 1079 const std::string& gaia_id) { | 1140 const std::string& gaia_id) { |
| 1080 SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id); | 1141 SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id); |
| 1081 } | 1142 } |
| 1082 | 1143 |
| 1083 bool UserManagerBase::FindGaiaID(const UserID& user_id, | 1144 bool UserManagerBase::FindGaiaID(const UserID& user_id, |
| 1084 std::string* out_value) { | 1145 std::string* out_value) { |
| 1085 return GetKnownUserStringPref(user_id, kGAIAIdKey, out_value); | 1146 return GetKnownUserStringPref(user_id, kGAIAIdKey, out_value); |
| 1086 } | 1147 } |
| 1087 | 1148 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 } | 1319 } |
| 1259 | 1320 |
| 1260 void UserManagerBase::DeleteUser(User* user) { | 1321 void UserManagerBase::DeleteUser(User* user) { |
| 1261 const bool is_active_user = (user == active_user_); | 1322 const bool is_active_user = (user == active_user_); |
| 1262 delete user; | 1323 delete user; |
| 1263 if (is_active_user) | 1324 if (is_active_user) |
| 1264 active_user_ = NULL; | 1325 active_user_ = NULL; |
| 1265 } | 1326 } |
| 1266 | 1327 |
| 1267 } // namespace user_manager | 1328 } // namespace user_manager |
| OLD | NEW |