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 "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (!gaia_id.empty() && GetStringPref(AccountId::FromGaiaId(gaia_id), | 249 if (!gaia_id.empty() && GetStringPref(AccountId::FromGaiaId(gaia_id), |
250 kCanonicalEmail, &stored_email)) { | 250 kCanonicalEmail, &stored_email)) { |
251 return AccountId::FromUserEmailGaiaId(stored_email, gaia_id); | 251 return AccountId::FromUserEmailGaiaId(stored_email, gaia_id); |
252 } | 252 } |
253 | 253 |
254 return (gaia_id.empty() | 254 return (gaia_id.empty() |
255 ? AccountId::FromUserEmail(user_email) | 255 ? AccountId::FromUserEmail(user_email) |
256 : AccountId::FromUserEmailGaiaId(user_email, gaia_id)); | 256 : AccountId::FromUserEmailGaiaId(user_email, gaia_id)); |
257 } | 257 } |
258 | 258 |
| 259 std::vector<AccountId> GetKnownAccountIds() { |
| 260 std::vector<AccountId> result; |
| 261 PrefService* local_state = GetLocalState(); |
| 262 |
| 263 // Local State may not be initialized in tests. |
| 264 if (!local_state) |
| 265 return result; |
| 266 |
| 267 const base::ListValue* known_users = local_state->GetList(kKnownUsers); |
| 268 for (size_t i = 0; i < known_users->GetSize(); ++i) { |
| 269 const base::DictionaryValue* element = nullptr; |
| 270 if (known_users->GetDictionary(i, &element)) { |
| 271 std::string email; |
| 272 std::string gaia_id; |
| 273 const bool has_email = element->GetString(kCanonicalEmail, &email); |
| 274 const bool has_gaia_id = element->GetString(kGAIAIdKey, &gaia_id); |
| 275 if (has_email || has_gaia_id) { |
| 276 result.push_back(AccountId::FromUserEmailGaiaId(email, gaia_id)); |
| 277 } |
| 278 } |
| 279 } |
| 280 return result; |
| 281 } |
| 282 |
| 283 AccountId MayBeDeserializeAccountId( |
| 284 const std::string& maybe_serialized_account_id) { |
| 285 AccountId result(EmptyAccountId()); |
| 286 |
| 287 if (AccountId::Deserialize(maybe_serialized_account_id, &result)) |
| 288 return result; |
| 289 |
| 290 return GetAccountId(maybe_serialized_account_id, std::string() /* gaia_id */); |
| 291 } |
| 292 |
259 bool GetGaiaIdMigrationStatus(const AccountId& account_id, | 293 bool GetGaiaIdMigrationStatus(const AccountId& account_id, |
260 const std::string& subsystem) { | 294 const std::string& subsystem) { |
261 bool migrated = false; | 295 bool migrated = false; |
262 | 296 |
263 if (GetBooleanPref(account_id, | 297 if (GetBooleanPref(account_id, |
264 std::string(kGaiaIdMigration) + "." + subsystem, | 298 std::string(kGaiaIdMigration) + "." + subsystem, |
265 &migrated)) { | 299 &migrated)) { |
266 return migrated; | 300 return migrated; |
267 } | 301 } |
268 | 302 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 383 } |
350 } | 384 } |
351 } | 385 } |
352 | 386 |
353 void RegisterPrefs(PrefRegistrySimple* registry) { | 387 void RegisterPrefs(PrefRegistrySimple* registry) { |
354 registry->RegisterListPref(kKnownUsers); | 388 registry->RegisterListPref(kKnownUsers); |
355 } | 389 } |
356 | 390 |
357 } // namespace known_user | 391 } // namespace known_user |
358 } // namespace user_manager | 392 } // namespace user_manager |
OLD | NEW |