Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 const std::string& account_id) { | 248 const std::string& account_id) { |
| 249 if (ContainsKey(accounts_, account_id)) | 249 if (ContainsKey(accounts_, account_id)) |
| 250 return accounts_[account_id].info; | 250 return accounts_[account_id].info; |
| 251 | 251 |
| 252 return AccountInfo(); | 252 return AccountInfo(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 AccountTrackerService::AccountInfo | 255 AccountTrackerService::AccountInfo |
| 256 AccountTrackerService::FindAccountInfoByGaiaId( | 256 AccountTrackerService::FindAccountInfoByGaiaId( |
| 257 const std::string& gaia_id) { | 257 const std::string& gaia_id) { |
| 258 for (std::map<std::string, AccountState>::const_iterator it = | 258 if (!gaia_id.empty()) { |
|
Mike Lerman
2015/04/24 12:43:09
nit: informal style seems to be that, rather than
Roger Tawa OOO till Jul 10th
2015/04/24 13:00:33
I think I'll leave.it as is.
| |
| 259 accounts_.begin(); | 259 for (std::map<std::string, AccountState>::const_iterator it = |
| 260 it != accounts_.end(); | 260 accounts_.begin(); |
| 261 ++it) { | 261 it != accounts_.end(); |
| 262 const AccountState& state = it->second; | 262 ++it) { |
| 263 if (state.info.gaia == gaia_id) | 263 const AccountState& state = it->second; |
| 264 return state.info; | 264 if (state.info.gaia == gaia_id) |
| 265 return state.info; | |
| 266 } | |
| 265 } | 267 } |
| 266 | 268 |
| 267 return AccountInfo(); | 269 return AccountInfo(); |
| 268 } | 270 } |
| 269 | 271 |
| 270 AccountTrackerService::AccountInfo | 272 AccountTrackerService::AccountInfo |
| 271 AccountTrackerService::FindAccountInfoByEmail( | 273 AccountTrackerService::FindAccountInfoByEmail( |
| 272 const std::string& email) { | 274 const std::string& email) { |
| 273 for (std::map<std::string, AccountState>::const_iterator it = | 275 if (!email.empty()) { |
| 274 accounts_.begin(); | 276 for (std::map<std::string, AccountState>::const_iterator it = |
| 275 it != accounts_.end(); | 277 accounts_.begin(); |
| 276 ++it) { | 278 it != accounts_.end(); |
| 277 const AccountState& state = it->second; | 279 ++it) { |
| 278 if (gaia::AreEmailsSame(state.info.email, email)) | 280 const AccountState& state = it->second; |
| 279 return state.info; | 281 if (gaia::AreEmailsSame(state.info.email, email)) |
| 282 return state.info; | |
| 283 } | |
| 280 } | 284 } |
| 281 | 285 |
| 282 return AccountInfo(); | 286 return AccountInfo(); |
| 283 } | 287 } |
| 284 | 288 |
| 285 AccountTrackerService::AccountIdMigrationState | 289 AccountTrackerService::AccountIdMigrationState |
| 286 AccountTrackerService::GetMigrationState() { | 290 AccountTrackerService::GetMigrationState() { |
| 287 return GetMigrationState(signin_client_->GetPrefs()); | 291 return GetMigrationState(signin_client_->GetPrefs()); |
| 288 } | 292 } |
| 289 | 293 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 const std::string& gaia, | 581 const std::string& gaia, |
| 578 const std::string& email) { | 582 const std::string& email) { |
| 579 return PickAccountIdForAccount(signin_client_->GetPrefs(), gaia, email); | 583 return PickAccountIdForAccount(signin_client_->GetPrefs(), gaia, email); |
| 580 } | 584 } |
| 581 | 585 |
| 582 // static | 586 // static |
| 583 std::string AccountTrackerService::PickAccountIdForAccount( | 587 std::string AccountTrackerService::PickAccountIdForAccount( |
| 584 PrefService* pref_service, | 588 PrefService* pref_service, |
| 585 const std::string& gaia, | 589 const std::string& gaia, |
| 586 const std::string& email) { | 590 const std::string& email) { |
| 587 DCHECK(!gaia.empty()); | 591 DCHECK(!gaia.empty() || |
| 592 GetMigrationState(pref_service) == MIGRATION_NOT_STARTED); | |
| 588 DCHECK(!email.empty()); | 593 DCHECK(!email.empty()); |
| 589 switch(GetMigrationState(pref_service)) { | 594 switch(GetMigrationState(pref_service)) { |
| 590 case MIGRATION_NOT_STARTED: | 595 case MIGRATION_NOT_STARTED: |
| 591 case MIGRATION_IN_PROGRESS: | 596 case MIGRATION_IN_PROGRESS: |
| 592 // Some tests don't use a real email address. To support these cases, | 597 // Some tests don't use a real email address. To support these cases, |
| 593 // don't try to canonicalize these strings. | 598 // don't try to canonicalize these strings. |
| 594 return (email.find('@') == std::string::npos) ? email : | 599 return (email.find('@') == std::string::npos) ? email : |
| 595 gaia::CanonicalizeEmail(email); | 600 gaia::CanonicalizeEmail(email); |
| 596 case MIGRATION_DONE: | 601 case MIGRATION_DONE: |
| 597 return gaia; | 602 return gaia; |
| 598 default: | 603 default: |
| 599 NOTREACHED(); | 604 NOTREACHED(); |
| 600 return email; | 605 return email; |
| 601 } | 606 } |
| 602 } | 607 } |
| 603 | 608 |
| 604 std::string AccountTrackerService::SeedAccountInfo(const std::string& gaia, | 609 std::string AccountTrackerService::SeedAccountInfo(const std::string& gaia, |
| 605 const std::string& email) { | 610 const std::string& email) { |
| 606 DCHECK(!gaia.empty()); | |
| 607 DCHECK(!email.empty()); | |
| 608 const std::string account_id = PickAccountIdForAccount(gaia, email); | 611 const std::string account_id = PickAccountIdForAccount(gaia, email); |
| 609 const bool already_exists = ContainsKey(accounts_, account_id); | 612 const bool already_exists = ContainsKey(accounts_, account_id); |
| 610 StartTrackingAccount(account_id); | 613 StartTrackingAccount(account_id); |
| 611 AccountState& state = accounts_[account_id]; | 614 AccountState& state = accounts_[account_id]; |
| 612 DCHECK(!already_exists || state.info.gaia == gaia); | 615 DCHECK(!already_exists || state.info.gaia.empty() || state.info.gaia == gaia); |
| 613 state.info.gaia = gaia; | 616 state.info.gaia = gaia; |
| 614 state.info.email = email; | 617 state.info.email = email; |
| 615 SaveToPrefs(state); | 618 SaveToPrefs(state); |
| 616 | 619 |
| 617 DVLOG(1) << "AccountTrackerService::SeedAccountInfo" | 620 DVLOG(1) << "AccountTrackerService::SeedAccountInfo" |
| 618 << " account_id=" << account_id | 621 << " account_id=" << account_id |
| 619 << " gaia_id=" << gaia | 622 << " gaia_id=" << gaia |
| 620 << " email=" << email; | 623 << " email=" << email; |
| 621 | 624 |
| 622 return account_id; | 625 return account_id; |
| 623 } | 626 } |
| OLD | NEW |