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_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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 17 #include "components/signin/core/browser/signin_client.h" | 17 #include "components/signin/core/browser/signin_client.h" |
| 18 #include "components/signin/core/browser/signin_metrics.h" | |
| 18 #include "components/signin/core/browser/signin_oauth_helper.h" | 19 #include "components/signin/core/browser/signin_oauth_helper.h" |
| 19 #include "google_apis/gaia/gaia_auth_fetcher.h" | 20 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 20 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 21 #include "google_apis/gaia/gaia_constants.h" | 22 #include "google_apis/gaia/gaia_constants.h" |
| 22 #include "google_apis/gaia/gaia_oauth_client.h" | 23 #include "google_apis/gaia/gaia_oauth_client.h" |
| 23 #include "google_apis/gaia/gaia_urls.h" | 24 #include "google_apis/gaia/gaia_urls.h" |
| 24 #include "net/cookies/canonical_cookie.h" | 25 #include "net/cookies/canonical_cookie.h" |
| 25 | 26 |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 : OAuth2TokenService::Consumer("account_reconcilor"), | 193 : OAuth2TokenService::Consumer("account_reconcilor"), |
| 193 token_service_(token_service), | 194 token_service_(token_service), |
| 194 signin_manager_(signin_manager), | 195 signin_manager_(signin_manager), |
| 195 client_(client), | 196 client_(client), |
| 196 merge_session_helper_(token_service_, | 197 merge_session_helper_(token_service_, |
| 197 client->GetURLRequestContext(), | 198 client->GetURLRequestContext(), |
| 198 this), | 199 this), |
| 199 registered_with_token_service_(false), | 200 registered_with_token_service_(false), |
| 200 is_reconcile_started_(false), | 201 is_reconcile_started_(false), |
| 201 are_gaia_accounts_set_(false), | 202 are_gaia_accounts_set_(false), |
| 202 requests_(NULL) { | 203 requests_(NULL), |
| 204 first_execution_(true) { | |
| 203 VLOG(1) << "AccountReconcilor::AccountReconcilor"; | 205 VLOG(1) << "AccountReconcilor::AccountReconcilor"; |
| 204 } | 206 } |
| 205 | 207 |
| 206 AccountReconcilor::~AccountReconcilor() { | 208 AccountReconcilor::~AccountReconcilor() { |
| 207 VLOG(1) << "AccountReconcilor::~AccountReconcilor"; | 209 VLOG(1) << "AccountReconcilor::~AccountReconcilor"; |
| 208 // Make sure shutdown was called first. | 210 // Make sure shutdown was called first. |
| 209 DCHECK(!registered_with_token_service_); | 211 DCHECK(!registered_with_token_service_); |
| 210 DCHECK(!reconciliation_timer_.IsRunning()); | 212 DCHECK(!reconciliation_timer_.IsRunning()); |
| 211 DCHECK(!requests_); | 213 DCHECK(!requests_); |
| 212 DCHECK_EQ(0u, user_id_fetchers_.size()); | 214 DCHECK_EQ(0u, user_id_fetchers_.size()); |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 ++i) { | 628 ++i) { |
| 627 if (*i != primary_account_) | 629 if (*i != primary_account_) |
| 628 add_to_cookie_.push_back(*i); | 630 add_to_cookie_.push_back(*i); |
| 629 } | 631 } |
| 630 | 632 |
| 631 // For each account known to chrome, PerformMergeAction() if the account is | 633 // For each account known to chrome, PerformMergeAction() if the account is |
| 632 // not already in the cookie jar or its state is invalid, or signal merge | 634 // not already in the cookie jar or its state is invalid, or signal merge |
| 633 // completed otherwise. Make a copy of |add_to_cookie_| since calls to | 635 // completed otherwise. Make a copy of |add_to_cookie_| since calls to |
| 634 // SignalComplete() will change the array. | 636 // SignalComplete() will change the array. |
| 635 std::vector<std::string> add_to_cookie_copy = add_to_cookie_; | 637 std::vector<std::string> add_to_cookie_copy = add_to_cookie_; |
| 638 int added_to_cookie = 0; | |
| 636 for (size_t i = 0; i < add_to_cookie_copy.size(); ++i) { | 639 for (size_t i = 0; i < add_to_cookie_copy.size(); ++i) { |
| 637 if (gaia_accounts_.end() != | 640 if (gaia_accounts_.end() != |
| 638 std::find_if(gaia_accounts_.begin(), | 641 std::find_if(gaia_accounts_.begin(), |
| 639 gaia_accounts_.end(), | 642 gaia_accounts_.end(), |
| 640 std::bind1st(EmailEqualToFunc(), | 643 std::bind1st(EmailEqualToFunc(), |
| 641 std::make_pair(add_to_cookie_copy[i], | 644 std::make_pair(add_to_cookie_copy[i], |
| 642 true)))) { | 645 true)))) { |
| 643 merge_session_helper_.SignalComplete( | 646 merge_session_helper_.SignalComplete( |
| 644 add_to_cookie_copy[i], | 647 add_to_cookie_copy[i], |
| 645 GoogleServiceAuthError::AuthErrorNone()); | 648 GoogleServiceAuthError::AuthErrorNone()); |
| 646 } else { | 649 } else { |
| 647 PerformMergeAction(add_to_cookie_copy[i]); | 650 PerformMergeAction(add_to_cookie_copy[i]); |
| 651 added_to_cookie++; | |
| 648 } | 652 } |
| 649 } | 653 } |
| 650 | 654 |
| 651 // For each account in the gaia cookie not known to chrome, | 655 // For each account in the gaia cookie not known to chrome, |
| 652 // PerformAddToChromeAction. | 656 // PerformAddToChromeAction. |
| 653 for (std::vector<std::pair<std::string, int> >::const_iterator i = | 657 for (std::vector<std::pair<std::string, int> >::const_iterator i = |
| 654 add_to_chrome_.begin(); | 658 add_to_chrome_.begin(); |
| 655 i != add_to_chrome_.end(); | 659 i != add_to_chrome_.end(); |
| 656 ++i) { | 660 ++i) { |
| 657 PerformAddToChromeAction(i->first, i->second); | 661 PerformAddToChromeAction(i->first, i->second); |
| 658 } | 662 } |
| 659 | 663 |
| 664 SigninMetrics::LogSigninAccountReconciliation(valid_chrome_accounts_.size(), | |
| 665 added_to_cookie, add_to_chrome_.size(), | |
| 666 are_primaries_equal, first_execution_); | |
|
Roger Tawa OOO till Jul 10th
2014/05/07 17:05:38
Spacing is off. Line up all subsequent args under
Mike Lerman
2014/05/07 18:49:37
Done.
| |
| 667 | |
| 668 first_execution_ = false; | |
| 660 CalculateIfReconcileIsDone(); | 669 CalculateIfReconcileIsDone(); |
| 661 ScheduleStartReconcileIfChromeAccountsChanged(); | 670 ScheduleStartReconcileIfChromeAccountsChanged(); |
| 662 } | 671 } |
| 663 | 672 |
| 664 void AccountReconcilor::AbortReconcile() { | 673 void AccountReconcilor::AbortReconcile() { |
| 665 VLOG(1) << "AccountReconcilor::AbortReconcile: we'll try again later"; | 674 VLOG(1) << "AccountReconcilor::AbortReconcile: we'll try again later"; |
| 666 DeleteFetchers(); | 675 DeleteFetchers(); |
| 667 add_to_cookie_.clear(); | 676 add_to_cookie_.clear(); |
| 668 add_to_chrome_.clear(); | 677 add_to_chrome_.clear(); |
| 669 CalculateIfReconcileIsDone(); | 678 CalculateIfReconcileIsDone(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 i != add_to_chrome_.end(); | 746 i != add_to_chrome_.end(); |
| 738 ++i) { | 747 ++i) { |
| 739 if (gaia::AreEmailsSame(account_id, i->first)) { | 748 if (gaia::AreEmailsSame(account_id, i->first)) { |
| 740 add_to_chrome_.erase(i); | 749 add_to_chrome_.erase(i); |
| 741 break; | 750 break; |
| 742 } | 751 } |
| 743 } | 752 } |
| 744 | 753 |
| 745 CalculateIfReconcileIsDone(); | 754 CalculateIfReconcileIsDone(); |
| 746 } | 755 } |
| OLD | NEW |