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

Side by Side Diff: components/signin/core/browser/signin_manager_base.cc

Issue 1086073006: Fix DCHECK when upgrading from an old profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redo migration Created 5 years, 8 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
OLDNEW
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/signin/core/browser/signin_manager_base.h" 5 #include "components/signin/core/browser/signin_manager_base.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId); 55 client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId);
56 56
57 // Handle backward compatibility: if kGoogleServicesAccountId is empty, but 57 // Handle backward compatibility: if kGoogleServicesAccountId is empty, but
58 // kGoogleServicesUsername is not, then this is an old profile that needs to 58 // kGoogleServicesUsername is not, then this is an old profile that needs to
59 // be updated. kGoogleServicesUserAccountId should not be empty, and contains 59 // be updated. kGoogleServicesUserAccountId should not be empty, and contains
60 // the gaia_id. Use both properties to prime the account tracker before 60 // the gaia_id. Use both properties to prime the account tracker before
61 // proceeding. 61 // proceeding.
62 if (account_id.empty()) { 62 if (account_id.empty()) {
63 std::string pref_account_username = 63 std::string pref_account_username =
64 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); 64 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername);
65 std::string pref_gaia_id = 65 if (!pref_account_username.empty()) {
66 client_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId); 66 // This is an old profile connected to a google account. Migrate from
67 // kGoogleServicesUsername to kGoogleServicesAccountId.
68 std::string pref_gaia_id =
69 client_->GetPrefs()->GetString(prefs::kGoogleServicesUserAccountId);
67 70
68 // If kGoogleServicesUserAccountId is empty, then this is either a chromeos 71 // If kGoogleServicesUserAccountId is empty, then this is either a cros
69 // machine or a really old profile on one of the other platforms. However 72 // machine or a really old profile on one of the other platforms. However
70 // in this case the account tracker should have the gaia_id so fetch it 73 // in this case the account tracker should have the gaia_id so fetch it
71 // from there. 74 // from there.
72 if (!pref_account_username.empty() && pref_gaia_id.empty()) { 75 if (pref_gaia_id.empty()) {
73 AccountTrackerService::AccountInfo info = 76 AccountTrackerService::AccountInfo info =
74 account_tracker_service_->GetAccountInfo(pref_account_username); 77 account_tracker_service_->GetAccountInfo(pref_account_username);
75 DCHECK(!info.gaia.empty()); 78 pref_gaia_id = info.gaia;
76 pref_gaia_id = info.gaia; 79 }
77 }
78 80
79 if (!pref_account_username.empty() && !pref_gaia_id.empty()) { 81 // If |pref_gaia_id| is still empty, this means the profile has been in
82 // an auth error state for some time (since M39). It could also mean
83 // a profile that has not been used since M33. Before migration to gaia
84 // id is complete, the returned value will be the normalized email, which
85 // is correct. After the migration, the returned value will be empty,
86 // which means the user is essentially signed out.
87 // TODO(rogerta): may want to show a toast or something.
80 account_id = account_tracker_service_->SeedAccountInfo( 88 account_id = account_tracker_service_->SeedAccountInfo(
81 pref_gaia_id, pref_account_username); 89 pref_gaia_id, pref_account_username);
82 90
83 // Now remove obsolete preferences. 91 // Now remove obsolete preferences.
84 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); 92 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
93 }
85 94
86 // TODO(rogerta): once migration to gaia id is complete, remove 95 // TODO(rogerta): once migration to gaia id is complete, remove
87 // kGoogleServicesUserAccountId and change all uses of that pref to 96 // kGoogleServicesUserAccountId and change all uses of that pref to
88 // kGoogleServicesAccountId. 97 // kGoogleServicesAccountId.
89 }
90 } 98 }
91 99
92 if (!account_id.empty()) 100 if (!account_id.empty())
93 SetAuthenticatedAccountId(account_id); 101 SetAuthenticatedAccountId(account_id);
94 } 102 }
95 103
96 bool SigninManagerBase::IsInitialized() const { return initialized_; } 104 bool SigninManagerBase::IsInitialized() const { return initialized_; }
97 105
98 bool SigninManagerBase::IsSigninAllowed() const { 106 bool SigninManagerBase::IsSigninAllowed() const {
99 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed); 107 return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed);
100 } 108 }
101 109
102 std::string SigninManagerBase::GetAuthenticatedUsername() const { 110 std::string SigninManagerBase::GetAuthenticatedUsername() const {
103 return account_tracker_service_->GetAccountInfo( 111 return account_tracker_service_->GetAccountInfo(
104 GetAuthenticatedAccountId()).email; 112 GetAuthenticatedAccountId()).email;
105 } 113 }
106 114
107 const std::string& SigninManagerBase::GetAuthenticatedAccountId() const { 115 const std::string& SigninManagerBase::GetAuthenticatedAccountId() const {
108 return authenticated_account_id_; 116 return authenticated_account_id_;
109 } 117 }
110 118
111 void SigninManagerBase::SetAuthenticatedAccountInfo(const std::string& gaia_id, 119 void SigninManagerBase::SetAuthenticatedAccountInfo(const std::string& gaia_id,
112 const std::string& email) { 120 const std::string& email) {
121 DCHECK(!gaia_id.empty());
122 DCHECK(!email.empty());
123
113 std::string account_id = 124 std::string account_id =
114 account_tracker_service_->SeedAccountInfo(gaia_id, email); 125 account_tracker_service_->SeedAccountInfo(gaia_id, email);
Mike Lerman 2015/04/24 12:43:09 Since we're making the assumption now that the ATS
Roger Tawa OOO till Jul 10th 2015/04/24 13:00:33 There is a dcheck in seed by virtue of the call to
115 SetAuthenticatedAccountId(account_id); 126 SetAuthenticatedAccountId(account_id);
116 } 127 }
117 128
118 void SigninManagerBase::SetAuthenticatedAccountId( 129 void SigninManagerBase::SetAuthenticatedAccountId(
119 const std::string& account_id) { 130 const std::string& account_id) {
120 DCHECK(!account_id.empty()); 131 DCHECK(!account_id.empty());
121 if (!authenticated_account_id_.empty()) { 132 if (!authenticated_account_id_.empty()) {
122 DLOG_IF(ERROR, account_id != authenticated_account_id_) 133 DLOG_IF(ERROR, account_id != authenticated_account_id_)
123 << "Tried to change the authenticated id to something different: " 134 << "Tried to change the authenticated id to something different: "
124 << "Current: " << authenticated_account_id_ << ", New: " << account_id; 135 << "Current: " << authenticated_account_id_ << ", New: " << account_id;
125 return; 136 return;
126 } 137 }
127 138
128 std::string pref_account_id = 139 std::string pref_account_id =
129 client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId); 140 client_->GetPrefs()->GetString(prefs::kGoogleServicesAccountId);
130 141
131 DCHECK(pref_account_id.empty() || pref_account_id == account_id) 142 DCHECK(pref_account_id.empty() || pref_account_id == account_id)
132 << "account_id=" << account_id 143 << "account_id=" << account_id
133 << " pref_account_id=" << pref_account_id; 144 << " pref_account_id=" << pref_account_id;
134 authenticated_account_id_ = account_id; 145 authenticated_account_id_ = account_id;
135 client_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id); 146 client_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId, account_id);
136 147
137 // This preference is set so that code on I/O thread has access to the 148 // This preference is set so that code on I/O thread has access to the
138 // Gaia id of the signed in user. 149 // Gaia id of the signed in user.
139 AccountTrackerService::AccountInfo info = 150 AccountTrackerService::AccountInfo info =
140 account_tracker_service_->GetAccountInfo(account_id); 151 account_tracker_service_->GetAccountInfo(account_id);
141 DCHECK(!info.gaia.empty()); 152
142 client_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, 153 // When this function is called from Initialize(), it's possible for
143 info.gaia); 154 // |info.gaia| to be empty when migrating from a really old profile.
155 if (!info.gaia.empty()) {
156 client_->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId,
157 info.gaia);
158 }
144 159
145 // Go ahead and update the last signed in account info here as well. Once a 160 // Go ahead and update the last signed in account info here as well. Once a
146 // user is signed in the two preferences should match. Doing it here as 161 // user is signed in the two preferences should match. Doing it here as
147 // opposed to on signin allows us to catch the upgrade scenario. 162 // opposed to on signin allows us to catch the upgrade scenario.
148 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, 163 client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername,
149 info.email); 164 info.email);
150 } 165 }
151 166
152 bool SigninManagerBase::IsAuthenticated() const { 167 bool SigninManagerBase::IsAuthenticated() const {
153 return !authenticated_account_id_.empty(); 168 return !authenticated_account_id_.empty();
(...skipping 24 matching lines...) Expand all
178 signin_diagnostics_observers_.RemoveObserver(observer); 193 signin_diagnostics_observers_.RemoveObserver(observer);
179 } 194 }
180 195
181 void SigninManagerBase::NotifyDiagnosticsObservers( 196 void SigninManagerBase::NotifyDiagnosticsObservers(
182 const TimedSigninStatusField& field, 197 const TimedSigninStatusField& field,
183 const std::string& value) { 198 const std::string& value) {
184 FOR_EACH_OBSERVER(SigninDiagnosticsObserver, 199 FOR_EACH_OBSERVER(SigninDiagnosticsObserver,
185 signin_diagnostics_observers_, 200 signin_diagnostics_observers_,
186 NotifySigninValueChanged(field, value)); 201 NotifySigninValueChanged(field, value));
187 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698