| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; | 353 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; |
| 354 gaia_fetcher_.reset(); | 354 gaia_fetcher_.reset(); |
| 355 get_gaia_accounts_callbacks_.clear(); | 355 get_gaia_accounts_callbacks_.clear(); |
| 356 AbortReconcile(); | 356 AbortReconcile(); |
| 357 UnregisterWithTokenService(); | 357 UnregisterWithTokenService(); |
| 358 UnregisterForCookieChanges(); | 358 UnregisterForCookieChanges(); |
| 359 PerformLogoutAllAccountsAction(); | 359 PerformLogoutAllAccountsAction(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { | 362 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { |
| 363 if (!switches::IsNewProfileManagement()) { | 363 if (!switches::IsEnableAccountConsistency()) { |
| 364 MarkAccountAsAddedToCookie(account_id); | 364 MarkAccountAsAddedToCookie(account_id); |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; | 367 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; |
| 368 merge_session_helper_.LogIn(account_id); | 368 merge_session_helper_.LogIn(account_id); |
| 369 } | 369 } |
| 370 | 370 |
| 371 void AccountReconcilor::PerformStartRemoveAction( | 371 void AccountReconcilor::PerformStartRemoveAction( |
| 372 const std::string& account_id) { | 372 const std::string& account_id) { |
| 373 VLOG(1) << "AccountReconcilor::PerformStartRemoveAction: " << account_id; | 373 VLOG(1) << "AccountReconcilor::PerformStartRemoveAction: " << account_id; |
| 374 GetAccountsFromCookie(base::Bind( | 374 GetAccountsFromCookie(base::Bind( |
| 375 &AccountReconcilor::PerformFinishRemoveAction, | 375 &AccountReconcilor::PerformFinishRemoveAction, |
| 376 base::Unretained(this), | 376 base::Unretained(this), |
| 377 account_id)); | 377 account_id)); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void AccountReconcilor::PerformFinishRemoveAction( | 380 void AccountReconcilor::PerformFinishRemoveAction( |
| 381 const std::string& account_id, | 381 const std::string& account_id, |
| 382 const GoogleServiceAuthError& error, | 382 const GoogleServiceAuthError& error, |
| 383 const std::vector<std::pair<std::string, bool> >& accounts) { | 383 const std::vector<std::pair<std::string, bool> >& accounts) { |
| 384 if (!switches::IsNewProfileManagement()) | 384 if (!switches::IsEnableAccountConsistency()) |
| 385 return; | 385 return; |
| 386 VLOG(1) << "AccountReconcilor::PerformFinishRemoveAction:" | 386 VLOG(1) << "AccountReconcilor::PerformFinishRemoveAction:" |
| 387 << " account=" << account_id << " error=" << error.ToString(); | 387 << " account=" << account_id << " error=" << error.ToString(); |
| 388 if (error.state() == GoogleServiceAuthError::NONE) { | 388 if (error.state() == GoogleServiceAuthError::NONE) { |
| 389 AbortReconcile(); | 389 AbortReconcile(); |
| 390 std::vector<std::string> accounts_only; | 390 std::vector<std::string> accounts_only; |
| 391 for (std::vector<std::pair<std::string, bool> >::const_iterator i = | 391 for (std::vector<std::pair<std::string, bool> >::const_iterator i = |
| 392 accounts.begin(); | 392 accounts.begin(); |
| 393 i != accounts.end(); | 393 i != accounts.end(); |
| 394 ++i) { | 394 ++i) { |
| 395 accounts_only.push_back(i->first); | 395 accounts_only.push_back(i->first); |
| 396 } | 396 } |
| 397 merge_session_helper_.LogOut(account_id, accounts_only); | 397 merge_session_helper_.LogOut(account_id, accounts_only); |
| 398 } | 398 } |
| 399 // Wait for the next ReconcileAction if there is an error. | 399 // Wait for the next ReconcileAction if there is an error. |
| 400 } | 400 } |
| 401 | 401 |
| 402 void AccountReconcilor::PerformAddToChromeAction( | 402 void AccountReconcilor::PerformAddToChromeAction( |
| 403 const std::string& account_id, | 403 const std::string& account_id, |
| 404 int session_index, | 404 int session_index, |
| 405 const std::string& signin_scoped_device_id) { | 405 const std::string& signin_scoped_device_id) { |
| 406 if (!switches::IsNewProfileManagement()) { | 406 if (!switches::IsEnableAccountConsistency()) { |
| 407 MarkAccountAsAddedToChrome(account_id); | 407 MarkAccountAsAddedToChrome(account_id); |
| 408 return; | 408 return; |
| 409 } | 409 } |
| 410 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" | 410 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" |
| 411 << " account=" << account_id << " session_index=" << session_index; | 411 << " account=" << account_id << " session_index=" << session_index; |
| 412 | 412 |
| 413 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 413 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 414 refresh_token_fetchers_.push_back(new RefreshTokenFetcher( | 414 refresh_token_fetchers_.push_back(new RefreshTokenFetcher( |
| 415 this, account_id, session_index, signin_scoped_device_id)); | 415 this, account_id, session_index, signin_scoped_device_id)); |
| 416 #endif | 416 #endif |
| 417 } | 417 } |
| 418 | 418 |
| 419 void AccountReconcilor::PerformLogoutAllAccountsAction() { | 419 void AccountReconcilor::PerformLogoutAllAccountsAction() { |
| 420 if (!switches::IsNewProfileManagement()) | 420 if (!switches::IsEnableAccountConsistency()) |
| 421 return; | 421 return; |
| 422 VLOG(1) << "AccountReconcilor::PerformLogoutAllAccountsAction"; | 422 VLOG(1) << "AccountReconcilor::PerformLogoutAllAccountsAction"; |
| 423 merge_session_helper_.LogOutAllAccounts(); | 423 merge_session_helper_.LogOutAllAccounts(); |
| 424 } | 424 } |
| 425 | 425 |
| 426 void AccountReconcilor::StartReconcile() { | 426 void AccountReconcilor::StartReconcile() { |
| 427 if (!IsProfileConnected() || is_reconcile_started_ || | 427 if (!IsProfileConnected() || is_reconcile_started_ || |
| 428 get_gaia_accounts_callbacks_.size() > 0 || | 428 get_gaia_accounts_callbacks_.size() > 0 || |
| 429 merge_session_helper_.is_running()) | 429 merge_session_helper_.is_running()) |
| 430 return; | 430 return; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 const std::string& account_id) { | 756 const std::string& account_id) { |
| 757 invalid_chrome_accounts_.insert(account_id); | 757 invalid_chrome_accounts_.insert(account_id); |
| 758 FinishReconcile(); | 758 FinishReconcile(); |
| 759 } | 759 } |
| 760 | 760 |
| 761 void AccountReconcilor::PerformAddAccountToTokenService( | 761 void AccountReconcilor::PerformAddAccountToTokenService( |
| 762 const std::string& account_id, | 762 const std::string& account_id, |
| 763 const std::string& refresh_token) { | 763 const std::string& refresh_token) { |
| 764 // The flow should never get to this method if new_profile_management is | 764 // The flow should never get to this method if new_profile_management is |
| 765 // false, but better safe than sorry. | 765 // false, but better safe than sorry. |
| 766 if (!switches::IsNewProfileManagement()) | 766 if (!switches::IsEnableAccountConsistency()) |
| 767 return; | 767 return; |
| 768 token_service_->UpdateCredentials(account_id, refresh_token); | 768 token_service_->UpdateCredentials(account_id, refresh_token); |
| 769 } | 769 } |
| 770 | 770 |
| 771 // Remove the account from the list that is being updated. | 771 // Remove the account from the list that is being updated. |
| 772 void AccountReconcilor::MarkAccountAsAddedToChrome( | 772 void AccountReconcilor::MarkAccountAsAddedToChrome( |
| 773 const std::string& account_id) { | 773 const std::string& account_id) { |
| 774 for (std::vector<std::pair<std::string, int> >::iterator i = | 774 for (std::vector<std::pair<std::string, int> >::iterator i = |
| 775 add_to_chrome_.begin(); | 775 add_to_chrome_.begin(); |
| 776 i != add_to_chrome_.end(); | 776 i != add_to_chrome_.end(); |
| 777 ++i) { | 777 ++i) { |
| 778 if (gaia::AreEmailsSame(account_id, i->first)) { | 778 if (gaia::AreEmailsSame(account_id, i->first)) { |
| 779 add_to_chrome_.erase(i); | 779 add_to_chrome_.erase(i); |
| 780 break; | 780 break; |
| 781 } | 781 } |
| 782 } | 782 } |
| 783 } | 783 } |
| 784 | 784 |
| 785 void AccountReconcilor::HandleRefreshTokenFetched( | 785 void AccountReconcilor::HandleRefreshTokenFetched( |
| 786 const std::string& account_id, | 786 const std::string& account_id, |
| 787 const std::string& refresh_token) { | 787 const std::string& refresh_token) { |
| 788 if (!refresh_token.empty()) | 788 if (!refresh_token.empty()) |
| 789 PerformAddAccountToTokenService(account_id, refresh_token); | 789 PerformAddAccountToTokenService(account_id, refresh_token); |
| 790 | 790 |
| 791 MarkAccountAsAddedToChrome(account_id); | 791 MarkAccountAsAddedToChrome(account_id); |
| 792 CalculateIfReconcileIsDone(); | 792 CalculateIfReconcileIsDone(); |
| 793 } | 793 } |
| OLD | NEW |