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

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

Issue 424233002: When the user signs in, make sure to set cookies on all reachable google (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 4 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 | Annotate | Revision Log
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_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
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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 if (*i != primary_account_) 649 if (*i != primary_account_)
644 add_to_cookie_.push_back(*i); 650 add_to_cookie_.push_back(*i);
645 } 651 }
646 652
647 // For each account known to chrome, PerformMergeAction() if the account is 653 // For each account known to chrome, PerformMergeAction() if the account is
648 // not already in the cookie jar or its state is invalid, or signal merge 654 // not already in the cookie jar or its state is invalid, or signal merge
649 // completed otherwise. Make a copy of |add_to_cookie_| since calls to 655 // completed otherwise. Make a copy of |add_to_cookie_| since calls to
650 // SignalComplete() will change the array. 656 // SignalComplete() will change the array.
651 std::vector<std::string> add_to_cookie_copy = add_to_cookie_; 657 std::vector<std::string> add_to_cookie_copy = add_to_cookie_;
652 int added_to_cookie = 0; 658 int added_to_cookie = 0;
659 bool external_cc_result_completed =
660 !merge_session_helper_.StillFetchingExternalCcResult();
653 for (size_t i = 0; i < add_to_cookie_copy.size(); ++i) { 661 for (size_t i = 0; i < add_to_cookie_copy.size(); ++i) {
654 if (gaia_accounts_.end() != 662 if (gaia_accounts_.end() !=
655 std::find_if(gaia_accounts_.begin(), 663 std::find_if(gaia_accounts_.begin(),
656 gaia_accounts_.end(), 664 gaia_accounts_.end(),
657 std::bind1st(EmailEqualToFunc(), 665 std::bind1st(EmailEqualToFunc(),
658 std::make_pair(add_to_cookie_copy[i], 666 std::make_pair(add_to_cookie_copy[i],
659 true)))) { 667 true)))) {
660 merge_session_helper_.SignalComplete( 668 merge_session_helper_.SignalComplete(
661 add_to_cookie_copy[i], 669 add_to_cookie_copy[i],
662 GoogleServiceAuthError::AuthErrorNone()); 670 GoogleServiceAuthError::AuthErrorNone());
663 } else { 671 } else {
664 PerformMergeAction(add_to_cookie_copy[i]); 672 PerformMergeAction(add_to_cookie_copy[i]);
665 added_to_cookie++; 673 added_to_cookie++;
666 } 674 }
667 } 675 }
668 676
677 // Log whether the external connection checks were completed when we tried
678 // to add the accounts to the cookie.
679 if (added_to_cookie > 0)
680 signin_metrics::LogExternalCcResultFetches(external_cc_result_completed);
681
669 std::string signin_scoped_device_id = client_->GetSigninScopedDeviceId(); 682 std::string signin_scoped_device_id = client_->GetSigninScopedDeviceId();
670 // For each account in the gaia cookie not known to chrome, 683 // For each account in the gaia cookie not known to chrome,
671 // PerformAddToChromeAction. Make a copy of |add_to_chrome| since calls to 684 // PerformAddToChromeAction. Make a copy of |add_to_chrome| since calls to
672 // PerformAddToChromeAction() may modify this array. 685 // PerformAddToChromeAction() may modify this array.
673 std::vector<std::pair<std::string, int> > add_to_chrome_copy = add_to_chrome_; 686 std::vector<std::pair<std::string, int> > add_to_chrome_copy = add_to_chrome_;
674 for (std::vector<std::pair<std::string, int> >::const_iterator i = 687 for (std::vector<std::pair<std::string, int> >::const_iterator i =
675 add_to_chrome_copy.begin(); 688 add_to_chrome_copy.begin();
676 i != add_to_chrome_copy.end(); 689 i != add_to_chrome_copy.end();
677 ++i) { 690 ++i) {
678 PerformAddToChromeAction(i->first, i->second, signin_scoped_device_id); 691 PerformAddToChromeAction(i->first, i->second, signin_scoped_device_id);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 797
785 void AccountReconcilor::HandleRefreshTokenFetched( 798 void AccountReconcilor::HandleRefreshTokenFetched(
786 const std::string& account_id, 799 const std::string& account_id,
787 const std::string& refresh_token) { 800 const std::string& refresh_token) {
788 if (!refresh_token.empty()) 801 if (!refresh_token.empty())
789 PerformAddAccountToTokenService(account_id, refresh_token); 802 PerformAddAccountToTokenService(account_id, refresh_token);
790 803
791 MarkAccountAsAddedToChrome(account_id); 804 MarkAccountAsAddedToChrome(account_id);
792 CalculateIfReconcileIsDone(); 805 CalculateIfReconcileIsDone();
793 } 806 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698