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

Side by Side Diff: components/user_manager/known_user.cc

Issue 2711113003: Track whether a given user session has completed initialization, and use (Closed)
Patch Set: Only expose known_user::RemovePrefsForTesting() for tests Created 3 years, 9 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
« no previous file with comments | « components/user_manager/known_user.h ('k') | components/user_manager/user.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 // Key of GAPS cookie. 47 // Key of GAPS cookie.
48 const char kGAPSCookie[] = "gaps_cookie"; 48 const char kGAPSCookie[] = "gaps_cookie";
49 49
50 // Key of the reason for re-auth. 50 // Key of the reason for re-auth.
51 const char kReauthReasonKey[] = "reauth_reason"; 51 const char kReauthReasonKey[] = "reauth_reason";
52 52
53 // Key for the GaiaId migration status. 53 // Key for the GaiaId migration status.
54 const char kGaiaIdMigration[] = "gaia_id_migration"; 54 const char kGaiaIdMigration[] = "gaia_id_migration";
55 55
56 // Key of the boolean flag telling if user session has finished init yet.
57 const char kProfileEverInitialized[] = "profile_ever_initialized";
58
56 PrefService* GetLocalState() { 59 PrefService* GetLocalState() {
57 if (!UserManager::IsInitialized()) 60 if (!UserManager::IsInitialized())
58 return nullptr; 61 return nullptr;
59 62
60 return UserManager::Get()->GetLocalState(); 63 return UserManager::Get()->GetLocalState();
61 } 64 }
62 65
63 // Checks if values in |dict| correspond with |account_id| identity. 66 // Checks if values in |dict| correspond with |account_id| identity.
64 bool UserMatches(const AccountId& account_id, 67 bool UserMatches(const AccountId& account_id,
65 const base::DictionaryValue& dict) { 68 const base::DictionaryValue& dict) {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 SetBooleanPref(account_id, kUsingSAMLKey, using_saml); 447 SetBooleanPref(account_id, kUsingSAMLKey, using_saml);
445 } 448 }
446 449
447 bool IsUsingSAML(const AccountId& account_id) { 450 bool IsUsingSAML(const AccountId& account_id) {
448 bool using_saml; 451 bool using_saml;
449 if (GetBooleanPref(account_id, kUsingSAMLKey, &using_saml)) 452 if (GetBooleanPref(account_id, kUsingSAMLKey, &using_saml))
450 return using_saml; 453 return using_saml;
451 return false; 454 return false;
452 } 455 }
453 456
457 bool WasProfileEverInitialized(const AccountId& account_id) {
458 bool profile_ever_initialized;
459 if (GetBooleanPref(account_id, kProfileEverInitialized,
460 &profile_ever_initialized))
461 return profile_ever_initialized;
462
463 // Sessions created before we started setting the session_initialized flag
464 // should default to "initialized = true".
465 LOG(WARNING) << "Treating unmigrated user as profile_ever_initialized=true";
466 return true;
467 }
468
469 void SetProfileEverInitialized(const AccountId& account_id, bool initialized) {
470 SetBooleanPref(account_id, kProfileEverInitialized, initialized);
471 }
472
454 void UpdateReauthReason(const AccountId& account_id, const int reauth_reason) { 473 void UpdateReauthReason(const AccountId& account_id, const int reauth_reason) {
455 SetIntegerPref(account_id, kReauthReasonKey, reauth_reason); 474 SetIntegerPref(account_id, kReauthReasonKey, reauth_reason);
456 } 475 }
457 476
458 bool FindReauthReason(const AccountId& account_id, int* out_value) { 477 bool FindReauthReason(const AccountId& account_id, int* out_value) {
459 return GetIntegerPref(account_id, kReauthReasonKey, out_value); 478 return GetIntegerPref(account_id, kReauthReasonKey, out_value);
460 } 479 }
461 480
462 void RemovePrefs(const AccountId& account_id) { 481 void RemovePrefs(const AccountId& account_id) {
463 PrefService* local_state = GetLocalState(); 482 PrefService* local_state = GetLocalState();
464 483
465 // Local State may not be initialized in tests. 484 // Local State may not be initialized in tests.
466 if (!local_state) 485 if (!local_state)
467 return; 486 return;
468 487
469 ListPrefUpdate update(local_state, kKnownUsers); 488 ListPrefUpdate update(local_state, kKnownUsers);
470 for (size_t i = 0; i < update->GetSize(); ++i) { 489 for (size_t i = 0; i < update->GetSize(); ++i) {
471 base::DictionaryValue* element = nullptr; 490 base::DictionaryValue* element = nullptr;
472 if (update->GetDictionary(i, &element)) { 491 if (update->GetDictionary(i, &element)) {
473 if (UserMatches(account_id, *element)) { 492 if (UserMatches(account_id, *element)) {
474 update->Remove(i, nullptr); 493 update->Remove(i, nullptr);
475 break; 494 break;
476 } 495 }
477 } 496 }
478 } 497 }
479 } 498 }
480 499
500 // Exported so tests can call this from other components.
501 void RemovePrefsForTesting(const AccountId& account_id) {
502 RemovePrefs(account_id);
503 }
504
481 void RegisterPrefs(PrefRegistrySimple* registry) { 505 void RegisterPrefs(PrefRegistrySimple* registry) {
482 registry->RegisterListPref(kKnownUsers); 506 registry->RegisterListPref(kKnownUsers);
483 } 507 }
484 508
485 } // namespace known_user 509 } // namespace known_user
486 } // namespace user_manager 510 } // namespace user_manager
OLDNEW
« no previous file with comments | « components/user_manager/known_user.h ('k') | components/user_manager/user.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698