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

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

Issue 1380103004: Delay fetching account info until OnRefreshTokensLoaded(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/account_tracker_service.h" 5 #include "components/signin/core/browser/account_tracker_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ++it) { 134 ++it) {
135 const AccountState& state = it->second; 135 const AccountState& state = it->second;
136 if (gaia::AreEmailsSame(state.info.email, email)) 136 if (gaia::AreEmailsSame(state.info.email, email))
137 return state.info; 137 return state.info;
138 } 138 }
139 } 139 }
140 140
141 return AccountInfo(); 141 return AccountInfo();
142 } 142 }
143 143
144 bool AccountTrackerService::IsTrackingAccount(
145 const std::string& account_id) const {
146 return ContainsKey(accounts_, account_id);
147 }
148
149 bool AccountTrackerService::HasIdNameMappingForAccount(
150 const std::string& account_id) const {
151 return !GetAccountInfo(account_id).email.empty();
Roger Tawa OOO till Jul 10th 2015/10/13 12:40:56 This should check if both gaiaid and email are not
knn 2015/10/13 13:15:42 Done.
152 }
153
154 bool AccountTrackerService::HasIdNameMappingForAllAccounts() const {
155 for (const auto& account : accounts_) {
156 if (account.second.info.email.empty())
Roger Tawa OOO till Jul 10th 2015/10/13 12:40:56 Same as previous comment.
knn 2015/10/13 13:15:41 Done.
157 return false;
158 }
159 return true;
160 }
Roger Tawa OOO till Jul 10th 2015/10/13 12:40:56 Seems like this function is the same as IsMigratab
knn 2015/10/13 13:15:42 My bad. Do you think it makes sense to call this f
161
144 AccountTrackerService::AccountIdMigrationState 162 AccountTrackerService::AccountIdMigrationState
145 AccountTrackerService::GetMigrationState() const { 163 AccountTrackerService::GetMigrationState() const {
146 return GetMigrationState(signin_client_->GetPrefs()); 164 return GetMigrationState(signin_client_->GetPrefs());
147 } 165 }
148 166
149 void AccountTrackerService::SetMigrationState(AccountIdMigrationState state) { 167 void AccountTrackerService::SetMigrationState(AccountIdMigrationState state) {
150 signin_client_->GetPrefs()->SetInteger(prefs::kAccountIdMigrationState, 168 signin_client_->GetPrefs()->SetInteger(prefs::kAccountIdMigrationState,
151 state); 169 state);
152 } 170 }
153 171
(...skipping 21 matching lines...) Expand all
175 } 193 }
176 194
177 void AccountTrackerService::NotifyAccountRemoved(const AccountState& state) { 195 void AccountTrackerService::NotifyAccountRemoved(const AccountState& state) {
178 DCHECK(!state.info.gaia.empty()); 196 DCHECK(!state.info.gaia.empty());
179 FOR_EACH_OBSERVER( 197 FOR_EACH_OBSERVER(
180 Observer, observer_list_, OnAccountRemoved(state.info)); 198 Observer, observer_list_, OnAccountRemoved(state.info));
181 } 199 }
182 200
183 void AccountTrackerService::StartTrackingAccount( 201 void AccountTrackerService::StartTrackingAccount(
184 const std::string& account_id) { 202 const std::string& account_id) {
185 if (!ContainsKey(accounts_, account_id)) { 203 if (!IsTrackingAccount(account_id)) {
186 DVLOG(1) << "StartTracking " << account_id; 204 DVLOG(1) << "StartTracking " << account_id;
187 AccountState state; 205 AccountState state;
188 state.info.account_id = account_id; 206 state.info.account_id = account_id;
189 state.info.is_child_account = false; 207 state.info.is_child_account = false;
190 accounts_.insert(make_pair(account_id, state)); 208 accounts_.insert(make_pair(account_id, state));
191 } 209 }
192 } 210 }
193 211
194 void AccountTrackerService::StopTrackingAccount(const std::string& account_id) { 212 void AccountTrackerService::StopTrackingAccount(const std::string& account_id) {
195 DVLOG(1) << "StopTracking " << account_id; 213 DVLOG(1) << "StopTracking " << account_id;
196 if (ContainsKey(accounts_, account_id)) { 214 if (IsTrackingAccount(account_id)) {
197 AccountState& state = accounts_[account_id]; 215 AccountState& state = accounts_[account_id];
198 RemoveFromPrefs(state); 216 RemoveFromPrefs(state);
199 if (!state.info.gaia.empty()) 217 if (!state.info.gaia.empty())
200 NotifyAccountRemoved(state); 218 NotifyAccountRemoved(state);
201 219
202 accounts_.erase(account_id); 220 accounts_.erase(account_id);
203 } 221 }
204 } 222 }
205 223
206 void AccountTrackerService::SetAccountStateFromUserInfo( 224 void AccountTrackerService::SetAccountStateFromUserInfo(
207 const std::string& account_id, 225 const std::string& account_id,
208 const base::DictionaryValue* user_info) { 226 const base::DictionaryValue* user_info) {
209 DCHECK(ContainsKey(accounts_, account_id)); 227 DCHECK(IsTrackingAccount(account_id));
210 AccountState& state = accounts_[account_id]; 228 AccountState& state = accounts_[account_id];
211 229
212 std::string gaia_id; 230 std::string gaia_id;
213 std::string email; 231 std::string email;
214 if (user_info->GetString("id", &gaia_id) && 232 if (user_info->GetString("id", &gaia_id) &&
215 user_info->GetString("email", &email)) { 233 user_info->GetString("email", &email)) {
216 state.info.gaia = gaia_id; 234 state.info.gaia = gaia_id;
217 state.info.email = email; 235 state.info.email = email;
218 236
219 std::string hosted_domain; 237 std::string hosted_domain;
(...skipping 14 matching lines...) Expand all
234 state.info.picture_url = kNoPictureURLFound; 252 state.info.picture_url = kNoPictureURLFound;
235 } 253 }
236 } 254 }
237 if (state.info.IsValid()) 255 if (state.info.IsValid())
238 NotifyAccountUpdated(state); 256 NotifyAccountUpdated(state);
239 SaveToPrefs(state); 257 SaveToPrefs(state);
240 } 258 }
241 259
242 void AccountTrackerService::SetIsChildAccount(const std::string& account_id, 260 void AccountTrackerService::SetIsChildAccount(const std::string& account_id,
243 const bool& is_child_account) { 261 const bool& is_child_account) {
244 DCHECK(ContainsKey(accounts_, account_id)); 262 DCHECK(IsTrackingAccount(account_id));
245 AccountState& state = accounts_[account_id]; 263 AccountState& state = accounts_[account_id];
246 if (state.info.is_child_account == is_child_account) 264 if (state.info.is_child_account == is_child_account)
247 return; 265 return;
248 state.info.is_child_account = is_child_account; 266 state.info.is_child_account = is_child_account;
249 if (state.info.IsValid()) 267 if (state.info.IsValid())
250 NotifyAccountUpdated(state); 268 NotifyAccountUpdated(state);
251 SaveToPrefs(state); 269 SaveToPrefs(state);
252 } 270 }
253 271
254 bool AccountTrackerService::IsMigratable() const { 272 bool AccountTrackerService::IsMigratable() const {
(...skipping 14 matching lines...) Expand all
269 void AccountTrackerService::MigrateToGaiaId() { 287 void AccountTrackerService::MigrateToGaiaId() {
270 std::set<std::string> to_remove; 288 std::set<std::string> to_remove;
271 std::map<std::string, AccountState> migrated_accounts; 289 std::map<std::string, AccountState> migrated_accounts;
272 for (std::map<std::string, AccountState>::const_iterator it = 290 for (std::map<std::string, AccountState>::const_iterator it =
273 accounts_.begin(); 291 accounts_.begin();
274 it != accounts_.end(); ++it) { 292 it != accounts_.end(); ++it) {
275 const AccountState& state = it->second; 293 const AccountState& state = it->second;
276 std::string account_id = it->first; 294 std::string account_id = it->first;
277 if (account_id != state.info.gaia) { 295 if (account_id != state.info.gaia) {
278 std::string new_account_id = state.info.gaia; 296 std::string new_account_id = state.info.gaia;
279 if (!ContainsKey(accounts_, new_account_id)) { 297 if (!IsTrackingAccount(new_account_id)) {
280 AccountState new_state = state; 298 AccountState new_state = state;
281 new_state.info.account_id = new_account_id; 299 new_state.info.account_id = new_account_id;
282 migrated_accounts.insert(make_pair(new_account_id, new_state)); 300 migrated_accounts.insert(make_pair(new_account_id, new_state));
283 SaveToPrefs(new_state); 301 SaveToPrefs(new_state);
284 } 302 }
285 to_remove.insert(account_id); 303 to_remove.insert(account_id);
286 } 304 }
287 } 305 }
288 306
289 // Remove any obsolete account. 307 // Remove any obsolete account.
290 for (auto account_id : to_remove) { 308 for (auto account_id : to_remove) {
291 if (ContainsKey(accounts_, account_id)) { 309 if (IsTrackingAccount(account_id)) {
292 AccountState& state = accounts_[account_id]; 310 AccountState& state = accounts_[account_id];
293 RemoveFromPrefs(state); 311 RemoveFromPrefs(state);
294 accounts_.erase(account_id); 312 accounts_.erase(account_id);
295 } 313 }
296 } 314 }
297 315
298 for (std::map<std::string, AccountState>::const_iterator it = 316 for (std::map<std::string, AccountState>::const_iterator it =
299 migrated_accounts.begin(); 317 migrated_accounts.begin();
300 it != migrated_accounts.end(); ++it) { 318 it != migrated_accounts.end(); ++it) {
301 accounts_.insert(*it); 319 accounts_.insert(*it);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return gaia; 477 return gaia;
460 default: 478 default:
461 NOTREACHED(); 479 NOTREACHED();
462 return email; 480 return email;
463 } 481 }
464 } 482 }
465 483
466 std::string AccountTrackerService::SeedAccountInfo(const std::string& gaia, 484 std::string AccountTrackerService::SeedAccountInfo(const std::string& gaia,
467 const std::string& email) { 485 const std::string& email) {
468 const std::string account_id = PickAccountIdForAccount(gaia, email); 486 const std::string account_id = PickAccountIdForAccount(gaia, email);
469 const bool already_exists = ContainsKey(accounts_, account_id); 487 const bool already_exists = IsTrackingAccount(account_id);
470 StartTrackingAccount(account_id); 488 StartTrackingAccount(account_id);
471 AccountState& state = accounts_[account_id]; 489 AccountState& state = accounts_[account_id];
472 DCHECK(!already_exists || state.info.gaia.empty() || state.info.gaia == gaia); 490 DCHECK(!already_exists || state.info.gaia.empty() || state.info.gaia == gaia);
473 state.info.gaia = gaia; 491 state.info.gaia = gaia;
474 state.info.email = email; 492 state.info.email = email;
475 SaveToPrefs(state); 493 SaveToPrefs(state);
476 494
477 DVLOG(1) << "AccountTrackerService::SeedAccountInfo" 495 DVLOG(1) << "AccountTrackerService::SeedAccountInfo"
478 << " account_id=" << account_id 496 << " account_id=" << account_id
479 << " gaia_id=" << gaia 497 << " gaia_id=" << gaia
480 << " email=" << email; 498 << " email=" << email;
481 499
482 return account_id; 500 return account_id;
483 } 501 }
484 502
485 void AccountTrackerService::SeedAccountInfo(AccountInfo info) { 503 void AccountTrackerService::SeedAccountInfo(AccountInfo info) {
486 info.account_id = PickAccountIdForAccount(info.gaia, info.email); 504 info.account_id = PickAccountIdForAccount(info.gaia, info.email);
487 if (info.hosted_domain.empty()) { 505 if (info.hosted_domain.empty()) {
488 info.hosted_domain = kNoHostedDomainFound; 506 info.hosted_domain = kNoHostedDomainFound;
489 } 507 }
490 508
491 if(info.IsValid()) { 509 if(info.IsValid()) {
492 if(!ContainsKey(accounts_, info.account_id)) { 510 if (!IsTrackingAccount(info.account_id)) {
493 SeedAccountInfo(info.gaia, info.email); 511 SeedAccountInfo(info.gaia, info.email);
494 } 512 }
495 513
496 AccountState& state = accounts_[info.account_id]; 514 AccountState& state = accounts_[info.account_id];
497 state.info = info; 515 state.info = info;
498 NotifyAccountUpdated(state); 516 NotifyAccountUpdated(state);
499 SaveToPrefs(state); 517 SaveToPrefs(state);
500 } 518 }
501 } 519 }
502 520
503 void AccountTrackerService::RemoveAccount(const std::string& account_id) { 521 void AccountTrackerService::RemoveAccount(const std::string& account_id) {
504 StopTrackingAccount(account_id); 522 StopTrackingAccount(account_id);
505 } 523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698