| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/known_user.h" | 5 #include "components/user_manager/known_user.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 const char kKnownUsers[] = "KnownUsers"; | 25 const char kKnownUsers[] = "KnownUsers"; |
| 26 | 26 |
| 27 // Known user preferences keys (stored in Local State). | 27 // Known user preferences keys (stored in Local State). |
| 28 | 28 |
| 29 // Key of canonical e-mail value. | 29 // Key of canonical e-mail value. |
| 30 const char kCanonicalEmail[] = "email"; | 30 const char kCanonicalEmail[] = "email"; |
| 31 | 31 |
| 32 // Key of obfuscated GAIA id value. | 32 // Key of obfuscated GAIA id value. |
| 33 const char kGAIAIdKey[] = "gaia_id"; | 33 const char kGAIAIdKey[] = "gaia_id"; |
| 34 | 34 |
| 35 // Key of account type. |
| 36 const char kAccountTypeKey[] = "account_type"; |
| 37 |
| 35 // Key of whether this user ID refers to a SAML user. | 38 // Key of whether this user ID refers to a SAML user. |
| 36 const char kUsingSAMLKey[] = "using_saml"; | 39 const char kUsingSAMLKey[] = "using_saml"; |
| 37 | 40 |
| 38 // Key of Device Id. | 41 // Key of Device Id. |
| 39 const char kDeviceId[] = "device_id"; | 42 const char kDeviceId[] = "device_id"; |
| 40 | 43 |
| 41 // Key of GAPS cookie. | 44 // Key of GAPS cookie. |
| 42 const char kGAPSCookie[] = "gaps_cookie"; | 45 const char kGAPSCookie[] = "gaps_cookie"; |
| 43 | 46 |
| 44 // Key of the reason for re-auth. | 47 // Key of the reason for re-auth. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 71 return false; | 74 return false; |
| 72 } | 75 } |
| 73 | 76 |
| 74 // Fills relevant |dict| values based on |account_id|. | 77 // Fills relevant |dict| values based on |account_id|. |
| 75 void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) { | 78 void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) { |
| 76 if (!account_id.GetUserEmail().empty()) | 79 if (!account_id.GetUserEmail().empty()) |
| 77 dict.SetString(kCanonicalEmail, account_id.GetUserEmail()); | 80 dict.SetString(kCanonicalEmail, account_id.GetUserEmail()); |
| 78 | 81 |
| 79 if (!account_id.GetGaiaId().empty()) | 82 if (!account_id.GetGaiaId().empty()) |
| 80 dict.SetString(kGAIAIdKey, account_id.GetGaiaId()); | 83 dict.SetString(kGAIAIdKey, account_id.GetGaiaId()); |
| 84 |
| 85 if (!account_id.GetAccountType().empty()) |
| 86 dict.SetString(kAccountTypeKey, account_id.GetAccountType()); |
| 81 } | 87 } |
| 82 | 88 |
| 83 } // namespace | 89 } // namespace |
| 84 | 90 |
| 85 bool FindPrefs(const AccountId& account_id, | 91 bool FindPrefs(const AccountId& account_id, |
| 86 const base::DictionaryValue** out_value) { | 92 const base::DictionaryValue** out_value) { |
| 87 PrefService* local_state = GetLocalState(); | 93 PrefService* local_state = GetLocalState(); |
| 88 | 94 |
| 89 // Local State may not be initialized in tests. | 95 // Local State may not be initialized in tests. |
| 90 if (!local_state) | 96 if (!local_state) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 user_email.empty() | 242 user_email.empty() |
| 237 ? std::string() | 243 ? std::string() |
| 238 : gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email)); | 244 : gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email)); |
| 239 | 245 |
| 240 if (!sanitized_email.empty() && | 246 if (!sanitized_email.empty() && |
| 241 GetStringPref(AccountId::FromUserEmail(sanitized_email), kGAIAIdKey, | 247 GetStringPref(AccountId::FromUserEmail(sanitized_email), kGAIAIdKey, |
| 242 &stored_gaia_id)) { | 248 &stored_gaia_id)) { |
| 243 if (!gaia_id.empty() && gaia_id != stored_gaia_id) | 249 if (!gaia_id.empty() && gaia_id != stored_gaia_id) |
| 244 LOG(ERROR) << "User gaia id has changed. Sync will not work."; | 250 LOG(ERROR) << "User gaia id has changed. Sync will not work."; |
| 245 | 251 |
| 252 AccountId account_id = |
| 253 AccountId::FromUserEmailGaiaId(sanitized_email, stored_gaia_id); |
| 254 std::string stored_account_type; |
| 255 if (!sanitized_email.empty() && |
| 256 GetStringPref(AccountId::FromUserEmail(sanitized_email), |
| 257 kAccountTypeKey, &stored_account_type)) { |
| 258 account_id.SetAccountType(stored_account_type); |
| 259 } |
| 246 // gaia_id is associated with cryptohome. | 260 // gaia_id is associated with cryptohome. |
| 247 return AccountId::FromUserEmailGaiaId(sanitized_email, stored_gaia_id); | 261 return account_id; |
| 248 } | 262 } |
| 249 | 263 |
| 250 std::string stored_email; | 264 std::string stored_email; |
| 251 // GetStringPref() returns the first user record that matches | 265 // GetStringPref() returns the first user record that matches |
| 252 // given ID. So we will get the first one if there are multiples. | 266 // given ID. So we will get the first one if there are multiples. |
| 253 if (!gaia_id.empty() && GetStringPref(AccountId::FromGaiaId(gaia_id), | 267 if (!gaia_id.empty() && GetStringPref(AccountId::FromGaiaId(gaia_id), |
| 254 kCanonicalEmail, &stored_email)) { | 268 kCanonicalEmail, &stored_email)) { |
| 255 return AccountId::FromUserEmailGaiaId(stored_email, gaia_id); | 269 return AccountId::FromUserEmailGaiaId(stored_email, gaia_id); |
| 256 } | 270 } |
| 257 | 271 |
| 258 return (gaia_id.empty() | 272 return (gaia_id.empty() |
| 259 ? AccountId::FromUserEmail(user_email) | 273 ? AccountId::FromUserEmail(user_email) |
| 260 : AccountId::FromUserEmailGaiaId(user_email, gaia_id)); | 274 : AccountId::FromUserEmailGaiaId(user_email, gaia_id)); |
| 261 } | 275 } |
| 262 | 276 |
| 263 std::vector<AccountId> GetKnownAccountIds() { | 277 std::vector<AccountId> GetKnownAccountIds() { |
| 264 std::vector<AccountId> result; | 278 std::vector<AccountId> result; |
| 265 PrefService* local_state = GetLocalState(); | 279 PrefService* local_state = GetLocalState(); |
| 266 | 280 |
| 267 // Local State may not be initialized in tests. | 281 // Local State may not be initialized in tests. |
| 268 if (!local_state) | 282 if (!local_state) |
| 269 return result; | 283 return result; |
| 270 | 284 |
| 271 const base::ListValue* known_users = local_state->GetList(kKnownUsers); | 285 const base::ListValue* known_users = local_state->GetList(kKnownUsers); |
| 272 for (size_t i = 0; i < known_users->GetSize(); ++i) { | 286 for (size_t i = 0; i < known_users->GetSize(); ++i) { |
| 273 const base::DictionaryValue* element = nullptr; | 287 const base::DictionaryValue* element = nullptr; |
| 274 if (known_users->GetDictionary(i, &element)) { | 288 if (known_users->GetDictionary(i, &element)) { |
| 275 std::string email; | 289 std::string email; |
| 276 std::string gaia_id; | 290 std::string gaia_id; |
| 291 std::string account_type; |
| 277 const bool has_email = element->GetString(kCanonicalEmail, &email); | 292 const bool has_email = element->GetString(kCanonicalEmail, &email); |
| 278 const bool has_gaia_id = element->GetString(kGAIAIdKey, &gaia_id); | 293 const bool has_gaia_id = element->GetString(kGAIAIdKey, &gaia_id); |
| 279 if (has_email || has_gaia_id) | 294 const bool has_account_type = |
| 280 result.push_back(AccountId::FromUserEmailGaiaId(email, gaia_id)); | 295 element->GetString(kAccountTypeKey, &account_type); |
| 296 if (has_email || has_gaia_id) { |
| 297 AccountId account_id = AccountId::FromUserEmailGaiaId(email, gaia_id); |
| 298 if (has_account_type) |
| 299 account_id.SetAccountType(account_type); |
| 300 result.push_back(account_id); |
| 301 } |
| 281 } | 302 } |
| 282 } | 303 } |
| 283 return result; | 304 return result; |
| 284 } | 305 } |
| 285 | 306 |
| 286 bool GetGaiaIdMigrationStatus(const AccountId& account_id, | 307 bool GetGaiaIdMigrationStatus(const AccountId& account_id, |
| 287 const std::string& subsystem) { | 308 const std::string& subsystem) { |
| 288 bool migrated = false; | 309 bool migrated = false; |
| 289 | 310 |
| 290 if (GetBooleanPref(account_id, | 311 if (GetBooleanPref(account_id, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 397 } |
| 377 } | 398 } |
| 378 } | 399 } |
| 379 | 400 |
| 380 void RegisterPrefs(PrefRegistrySimple* registry) { | 401 void RegisterPrefs(PrefRegistrySimple* registry) { |
| 381 registry->RegisterListPref(kKnownUsers); | 402 registry->RegisterListPref(kKnownUsers); |
| 382 } | 403 } |
| 383 | 404 |
| 384 } // namespace known_user | 405 } // namespace known_user |
| 385 } // namespace user_manager | 406 } // namespace user_manager |
| OLD | NEW |