| 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_reconcilor.h" | 5 #include "components/signin/core/browser/account_reconcilor.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; | 352 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; |
| 353 gaia_fetcher_.reset(); | 353 gaia_fetcher_.reset(); |
| 354 get_gaia_accounts_callbacks_.clear(); | 354 get_gaia_accounts_callbacks_.clear(); |
| 355 AbortReconcile(); | 355 AbortReconcile(); |
| 356 UnregisterWithTokenService(); | 356 UnregisterWithTokenService(); |
| 357 UnregisterForCookieChanges(); | 357 UnregisterForCookieChanges(); |
| 358 PerformLogoutAllAccountsAction(); | 358 PerformLogoutAllAccountsAction(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { | 361 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { |
| 362 if (!switches::IsNewProfileManagement()) { | 362 if (!switches::IsNewProfileManagement()) |
| 363 MarkAccountAsAddedToCookie(account_id); | |
| 364 return; | 363 return; |
| 365 } | |
| 366 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; | 364 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; |
| 367 merge_session_helper_.LogIn(account_id); | 365 merge_session_helper_.LogIn(account_id); |
| 368 } | 366 } |
| 369 | 367 |
| 370 void AccountReconcilor::PerformStartRemoveAction( | 368 void AccountReconcilor::PerformStartRemoveAction( |
| 371 const std::string& account_id) { | 369 const std::string& account_id) { |
| 372 VLOG(1) << "AccountReconcilor::PerformStartRemoveAction: " << account_id; | 370 VLOG(1) << "AccountReconcilor::PerformStartRemoveAction: " << account_id; |
| 373 GetAccountsFromCookie(base::Bind( | 371 GetAccountsFromCookie(base::Bind( |
| 374 &AccountReconcilor::PerformFinishRemoveAction, | 372 &AccountReconcilor::PerformFinishRemoveAction, |
| 375 base::Unretained(this), | 373 base::Unretained(this), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 393 ++i) { | 391 ++i) { |
| 394 accounts_only.push_back(i->first); | 392 accounts_only.push_back(i->first); |
| 395 } | 393 } |
| 396 merge_session_helper_.LogOut(account_id, accounts_only); | 394 merge_session_helper_.LogOut(account_id, accounts_only); |
| 397 } | 395 } |
| 398 // Wait for the next ReconcileAction if there is an error. | 396 // Wait for the next ReconcileAction if there is an error. |
| 399 } | 397 } |
| 400 | 398 |
| 401 void AccountReconcilor::PerformAddToChromeAction(const std::string& account_id, | 399 void AccountReconcilor::PerformAddToChromeAction(const std::string& account_id, |
| 402 int session_index) { | 400 int session_index) { |
| 403 if (!switches::IsNewProfileManagement()) { | 401 if (!switches::IsNewProfileManagement()) |
| 404 MarkAccountAsAddedToChrome(account_id); | |
| 405 return; | 402 return; |
| 406 } | |
| 407 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" | 403 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" |
| 408 << " account=" << account_id << " session_index=" << session_index; | 404 << " account=" << account_id << " session_index=" << session_index; |
| 409 | 405 |
| 410 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 406 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 411 refresh_token_fetchers_.push_back( | 407 refresh_token_fetchers_.push_back( |
| 412 new RefreshTokenFetcher(this, account_id, session_index)); | 408 new RefreshTokenFetcher(this, account_id, session_index)); |
| 413 #endif | 409 #endif |
| 414 } | 410 } |
| 415 | 411 |
| 416 void AccountReconcilor::PerformLogoutAllAccountsAction() { | 412 void AccountReconcilor::PerformLogoutAllAccountsAction() { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 std::vector<std::string> new_chrome_accounts(token_service_->GetAccounts()); | 699 std::vector<std::string> new_chrome_accounts(token_service_->GetAccounts()); |
| 704 std::sort(reconciled_accounts.begin(), reconciled_accounts.end()); | 700 std::sort(reconciled_accounts.begin(), reconciled_accounts.end()); |
| 705 std::sort(new_chrome_accounts.begin(), new_chrome_accounts.end()); | 701 std::sort(new_chrome_accounts.begin(), new_chrome_accounts.end()); |
| 706 if (reconciled_accounts != new_chrome_accounts) { | 702 if (reconciled_accounts != new_chrome_accounts) { |
| 707 base::MessageLoop::current()->PostTask( | 703 base::MessageLoop::current()->PostTask( |
| 708 FROM_HERE, | 704 FROM_HERE, |
| 709 base::Bind(&AccountReconcilor::StartReconcile, base::Unretained(this))); | 705 base::Bind(&AccountReconcilor::StartReconcile, base::Unretained(this))); |
| 710 } | 706 } |
| 711 } | 707 } |
| 712 | 708 |
| 713 // Remove the account from the list that is being merged. | 709 void AccountReconcilor::MergeSessionCompleted( |
| 714 void AccountReconcilor::MarkAccountAsAddedToCookie( | 710 const std::string& account_id, |
| 715 const std::string& account_id) { | 711 const GoogleServiceAuthError& error) { |
| 712 VLOG(1) << "AccountReconcilor::MergeSessionCompleted: account_id=" |
| 713 << account_id; |
| 714 |
| 715 // Remove the account from the list that is being merged. |
| 716 for (std::vector<std::string>::iterator i = add_to_cookie_.begin(); | 716 for (std::vector<std::string>::iterator i = add_to_cookie_.begin(); |
| 717 i != add_to_cookie_.end(); | 717 i != add_to_cookie_.end(); |
| 718 ++i) { | 718 ++i) { |
| 719 if (account_id == *i) { | 719 if (account_id == *i) { |
| 720 add_to_cookie_.erase(i); | 720 add_to_cookie_.erase(i); |
| 721 break; | 721 break; |
| 722 } | 722 } |
| 723 } | 723 } |
| 724 } | |
| 725 | 724 |
| 726 void AccountReconcilor::MergeSessionCompleted( | |
| 727 const std::string& account_id, | |
| 728 const GoogleServiceAuthError& error) { | |
| 729 VLOG(1) << "AccountReconcilor::MergeSessionCompleted: account_id=" | |
| 730 << account_id; | |
| 731 | |
| 732 MarkAccountAsAddedToCookie(account_id); | |
| 733 CalculateIfReconcileIsDone(); | 725 CalculateIfReconcileIsDone(); |
| 734 ScheduleStartReconcileIfChromeAccountsChanged(); | 726 ScheduleStartReconcileIfChromeAccountsChanged(); |
| 735 } | 727 } |
| 736 | 728 |
| 737 void AccountReconcilor::HandleSuccessfulAccountIdCheck( | 729 void AccountReconcilor::HandleSuccessfulAccountIdCheck( |
| 738 const std::string& account_id) { | 730 const std::string& account_id) { |
| 739 valid_chrome_accounts_.insert(account_id); | 731 valid_chrome_accounts_.insert(account_id); |
| 740 FinishReconcile(); | 732 FinishReconcile(); |
| 741 } | 733 } |
| 742 | 734 |
| 743 void AccountReconcilor::HandleFailedAccountIdCheck( | 735 void AccountReconcilor::HandleFailedAccountIdCheck( |
| 744 const std::string& account_id) { | 736 const std::string& account_id) { |
| 745 invalid_chrome_accounts_.insert(account_id); | 737 invalid_chrome_accounts_.insert(account_id); |
| 746 FinishReconcile(); | 738 FinishReconcile(); |
| 747 } | 739 } |
| 748 | 740 |
| 749 void AccountReconcilor::PerformAddAccountToTokenService( | 741 void AccountReconcilor::PerformAddAccountToTokenService( |
| 750 const std::string& account_id, | 742 const std::string& account_id, |
| 751 const std::string& refresh_token) { | 743 const std::string& refresh_token) { |
| 752 // The flow should never get to this method if new_profile_management is | 744 // The flow should never get to this method if new_profile_management is |
| 753 // false, but better safe than sorry. | 745 // false, but better safe than sorry. |
| 754 if (!switches::IsNewProfileManagement()) | 746 if (!switches::IsNewProfileManagement()) |
| 755 return; | 747 return; |
| 756 token_service_->UpdateCredentials(account_id, refresh_token); | 748 token_service_->UpdateCredentials(account_id, refresh_token); |
| 757 } | 749 } |
| 758 | 750 |
| 759 // Remove the account from the list that is being updated. | 751 void AccountReconcilor::HandleRefreshTokenFetched( |
| 760 void AccountReconcilor::MarkAccountAsAddedToChrome( | 752 const std::string& account_id, |
| 761 const std::string& account_id) { | 753 const std::string& refresh_token) { |
| 754 if (!refresh_token.empty()) { |
| 755 PerformAddAccountToTokenService(account_id, refresh_token); |
| 756 } |
| 757 // Remove the account from the list that is being updated. |
| 762 for (std::vector<std::pair<std::string, int> >::iterator i = | 758 for (std::vector<std::pair<std::string, int> >::iterator i = |
| 763 add_to_chrome_.begin(); | 759 add_to_chrome_.begin(); |
| 764 i != add_to_chrome_.end(); | 760 i != add_to_chrome_.end(); |
| 765 ++i) { | 761 ++i) { |
| 766 if (gaia::AreEmailsSame(account_id, i->first)) { | 762 if (gaia::AreEmailsSame(account_id, i->first)) { |
| 767 add_to_chrome_.erase(i); | 763 add_to_chrome_.erase(i); |
| 768 break; | 764 break; |
| 769 } | 765 } |
| 770 } | 766 } |
| 771 } | |
| 772 | 767 |
| 773 void AccountReconcilor::HandleRefreshTokenFetched( | |
| 774 const std::string& account_id, | |
| 775 const std::string& refresh_token) { | |
| 776 if (!refresh_token.empty()) | |
| 777 PerformAddAccountToTokenService(account_id, refresh_token); | |
| 778 | |
| 779 MarkAccountAsAddedToChrome(account_id); | |
| 780 CalculateIfReconcileIsDone(); | 768 CalculateIfReconcileIsDone(); |
| 781 } | 769 } |
| OLD | NEW |