| 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 431 | 431 |
| 432 is_reconcile_started_ = true; | 432 is_reconcile_started_ = true; |
| 433 | 433 |
| 434 StartFetchingExternalCcResult(); |
| 435 |
| 434 // Reset state for validating gaia cookie. | 436 // Reset state for validating gaia cookie. |
| 435 are_gaia_accounts_set_ = false; | 437 are_gaia_accounts_set_ = false; |
| 436 gaia_accounts_.clear(); | 438 gaia_accounts_.clear(); |
| 437 GetAccountsFromCookie(base::Bind( | 439 GetAccountsFromCookie(base::Bind( |
| 438 &AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts, | 440 &AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts, |
| 439 base::Unretained(this))); | 441 base::Unretained(this))); |
| 440 | 442 |
| 441 // Reset state for validating oauth2 tokens. | 443 // Reset state for validating oauth2 tokens. |
| 442 primary_account_.clear(); | 444 primary_account_.clear(); |
| 443 chrome_accounts_.clear(); | 445 chrome_accounts_.clear(); |
| 444 DeleteFetchers(); | 446 DeleteFetchers(); |
| 445 valid_chrome_accounts_.clear(); | 447 valid_chrome_accounts_.clear(); |
| 446 invalid_chrome_accounts_.clear(); | 448 invalid_chrome_accounts_.clear(); |
| 447 add_to_cookie_.clear(); | 449 add_to_cookie_.clear(); |
| 448 add_to_chrome_.clear(); | 450 add_to_chrome_.clear(); |
| 449 ValidateAccountsFromTokenService(); | 451 ValidateAccountsFromTokenService(); |
| 450 } | 452 } |
| 451 | 453 |
| 452 void AccountReconcilor::GetAccountsFromCookie( | 454 void AccountReconcilor::GetAccountsFromCookie( |
| 453 GetAccountsFromCookieCallback callback) { | 455 GetAccountsFromCookieCallback callback) { |
| 454 get_gaia_accounts_callbacks_.push_back(callback); | 456 get_gaia_accounts_callbacks_.push_back(callback); |
| 455 if (!gaia_fetcher_) { | 457 if (!gaia_fetcher_) { |
| 456 // There is no list account request in flight. | 458 // There is no list account request in flight. |
| 457 gaia_fetcher_.reset(new GaiaAuthFetcher( | 459 gaia_fetcher_.reset(new GaiaAuthFetcher( |
| 458 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); | 460 this, GaiaConstants::kChromeSource, client_->GetURLRequestContext())); |
| 459 gaia_fetcher_->StartListAccounts(); | 461 gaia_fetcher_->StartListAccounts(); |
| 460 } | 462 } |
| 461 } | 463 } |
| 462 | 464 |
| 465 void AccountReconcilor::StartFetchingExternalCcResult() { |
| 466 merge_session_helper_.StartFetchingExternalCcResult(); |
| 467 } |
| 468 |
| 463 void AccountReconcilor::OnListAccountsSuccess(const std::string& data) { | 469 void AccountReconcilor::OnListAccountsSuccess(const std::string& data) { |
| 464 gaia_fetcher_.reset(); | 470 gaia_fetcher_.reset(); |
| 465 | 471 |
| 466 // Get account information from response data. | 472 // Get account information from response data. |
| 467 std::vector<std::pair<std::string, bool> > gaia_accounts; | 473 std::vector<std::pair<std::string, bool> > gaia_accounts; |
| 468 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); | 474 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); |
| 469 if (!valid_json) { | 475 if (!valid_json) { |
| 470 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: parsing error"; | 476 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: parsing error"; |
| 471 } else if (gaia_accounts.size() > 0) { | 477 } else if (gaia_accounts.size() > 0) { |
| 472 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: " | 478 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: " |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 790 |
| 785 void AccountReconcilor::HandleRefreshTokenFetched( | 791 void AccountReconcilor::HandleRefreshTokenFetched( |
| 786 const std::string& account_id, | 792 const std::string& account_id, |
| 787 const std::string& refresh_token) { | 793 const std::string& refresh_token) { |
| 788 if (!refresh_token.empty()) | 794 if (!refresh_token.empty()) |
| 789 PerformAddAccountToTokenService(account_id, refresh_token); | 795 PerformAddAccountToTokenService(account_id, refresh_token); |
| 790 | 796 |
| 791 MarkAccountAsAddedToChrome(account_id); | 797 MarkAccountAsAddedToChrome(account_id); |
| 792 CalculateIfReconcileIsDone(); | 798 CalculateIfReconcileIsDone(); |
| 793 } | 799 } |
| OLD | NEW |