Index: components/signin/core/browser/account_reconcilor.cc |
diff --git a/components/signin/core/browser/account_reconcilor.cc b/components/signin/core/browser/account_reconcilor.cc |
index efe594db0e528b9791250382726747f2b511f1e3..aecbe9b19ad2e548582749410a6d16acc6b53ee8 100644 |
--- a/components/signin/core/browser/account_reconcilor.cc |
+++ b/components/signin/core/browser/account_reconcilor.cc |
@@ -16,12 +16,9 @@ |
#include "components/signin/core/browser/signin_client.h" |
#include "components/signin/core/browser/signin_metrics.h" |
#include "components/signin/core/common/profile_management_switches.h" |
-#include "google_apis/gaia/gaia_auth_fetcher.h" |
#include "google_apis/gaia/gaia_auth_util.h" |
-#include "google_apis/gaia/gaia_constants.h" |
#include "google_apis/gaia/gaia_oauth_client.h" |
#include "google_apis/gaia/gaia_urls.h" |
-#include "net/cookies/canonical_cookie.h" |
namespace { |
@@ -67,7 +64,6 @@ AccountReconcilor::AccountReconcilor( |
registered_with_content_settings_(false), |
is_reconcile_started_(false), |
first_execution_(true), |
- are_gaia_accounts_set_(false), |
chrome_accounts_changed_(false) { |
VLOG(1) << "AccountReconcilor::AccountReconcilor"; |
} |
@@ -87,7 +83,6 @@ void AccountReconcilor::Initialize(bool start_reconcile_if_tokens_available) { |
// wait for signin. |
if (IsProfileConnected()) { |
RegisterWithCookieManagerService(); |
- RegisterForCookieChanges(); |
RegisterWithContentSettings(); |
RegisterWithTokenService(); |
@@ -101,29 +96,12 @@ void AccountReconcilor::Initialize(bool start_reconcile_if_tokens_available) { |
void AccountReconcilor::Shutdown() { |
VLOG(1) << "AccountReconcilor::Shutdown"; |
- gaia_fetcher_.reset(); |
- get_gaia_accounts_callbacks_.clear(); |
UnregisterWithCookieManagerService(); |
UnregisterWithSigninManager(); |
UnregisterWithTokenService(); |
- UnregisterForCookieChanges(); |
UnregisterWithContentSettings(); |
} |
-void AccountReconcilor::RegisterForCookieChanges() { |
- // First clear any existing registration to avoid DCHECKs that can otherwise |
- // go off in some embedders on reauth (e.g., ChromeSigninClient). |
- UnregisterForCookieChanges(); |
- cookie_changed_subscription_ = client_->AddCookieChangedCallback( |
- GaiaUrls::GetInstance()->gaia_url(), |
- "LSID", |
- base::Bind(&AccountReconcilor::OnCookieChanged, base::Unretained(this))); |
-} |
- |
-void AccountReconcilor::UnregisterForCookieChanges() { |
- cookie_changed_subscription_.reset(); |
-} |
- |
void AccountReconcilor::RegisterWithSigninManager() { |
signin_manager_->AddObserver(this); |
} |
@@ -198,24 +176,6 @@ bool AccountReconcilor::IsProfileConnected() { |
return signin_manager_->IsAuthenticated(); |
} |
-void AccountReconcilor::OnCookieChanged(const net::CanonicalCookie& cookie, |
- bool removed) { |
- DCHECK_EQ("LSID", cookie.Name()); |
- DCHECK_EQ(GaiaUrls::GetInstance()->gaia_url().host(), cookie.Domain()); |
- if (cookie.IsSecure() && cookie.IsHttpOnly()) { |
- VLOG(1) << "AccountReconcilor::OnCookieChanged: LSID changed"; |
- |
- // It is possible that O2RT is not available at this moment. |
- if (!token_service_->GetAccounts().size()) { |
- VLOG(1) << "AccountReconcilor::OnCookieChanged: cookie change is ingored" |
- "because O2RT is not available yet."; |
- return; |
- } |
- |
- StartReconcile(); |
- } |
-} |
- |
void AccountReconcilor::OnContentSettingChanged( |
const ContentSettingsPattern& primary_pattern, |
const ContentSettingsPattern& secondary_pattern, |
@@ -249,7 +209,6 @@ void AccountReconcilor::GoogleSigninSucceeded(const std::string& account_id, |
const std::string& password) { |
VLOG(1) << "AccountReconcilor::GoogleSigninSucceeded: signed in"; |
RegisterWithCookieManagerService(); |
- RegisterForCookieChanges(); |
RegisterWithContentSettings(); |
RegisterWithTokenService(); |
} |
@@ -257,12 +216,9 @@ void AccountReconcilor::GoogleSigninSucceeded(const std::string& account_id, |
void AccountReconcilor::GoogleSignedOut(const std::string& account_id, |
const std::string& username) { |
VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; |
- gaia_fetcher_.reset(); |
- get_gaia_accounts_callbacks_.clear(); |
AbortReconcile(); |
UnregisterWithCookieManagerService(); |
UnregisterWithTokenService(); |
- UnregisterForCookieChanges(); |
UnregisterWithContentSettings(); |
PerformLogoutAllAccountsAction(); |
} |
@@ -289,13 +245,12 @@ void AccountReconcilor::StartReconcile() { |
return; |
} |
- if (is_reconcile_started_ || get_gaia_accounts_callbacks_.size() > 0) |
+ if (is_reconcile_started_) |
return; |
is_reconcile_started_ = true; |
// Reset state for validating gaia cookie. |
- are_gaia_accounts_set_ = false; |
gaia_accounts_.clear(); |
// Reset state for validating oauth2 tokens. |
@@ -304,78 +259,24 @@ void AccountReconcilor::StartReconcile() { |
add_to_cookie_.clear(); |
ValidateAccountsFromTokenService(); |
- GetAccountsFromCookie(base::Bind( |
- &AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts, |
- base::Unretained(this))); |
-} |
- |
-void AccountReconcilor::GetAccountsFromCookie( |
- GetAccountsFromCookieCallback callback) { |
- get_gaia_accounts_callbacks_.push_back(callback); |
- if (!gaia_fetcher_) |
- MayBeDoNextListAccounts(); |
-} |
- |
-void AccountReconcilor::OnListAccountsSuccess(const std::string& data) { |
- gaia_fetcher_.reset(); |
- |
- // Get account information from response data. |
- std::vector<std::pair<std::string, bool> > gaia_accounts; |
- bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); |
- if (!valid_json) { |
- VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: parsing error"; |
- } else if (gaia_accounts.size() > 0) { |
- VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: " |
- << "Gaia " << gaia_accounts.size() << " accounts, " |
- << "Primary is '" << gaia_accounts[0].first << "'"; |
- } else { |
- VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: No accounts"; |
+ // Rely on the GCMS to manage calls to and responses from ListAccounts. |
+ if (cookie_manager_service_->ListAccounts(&gaia_accounts_)) { |
+ OnGaiaAccountsInCookieUpdated( |
+ gaia_accounts_, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
} |
- |
- // There must be at least one callback waiting for result. |
- DCHECK(!get_gaia_accounts_callbacks_.empty()); |
- |
- GoogleServiceAuthError error = |
- !valid_json ? GoogleServiceAuthError( |
- GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE) |
- : GoogleServiceAuthError::AuthErrorNone(); |
- get_gaia_accounts_callbacks_.front().Run(error, gaia_accounts); |
- get_gaia_accounts_callbacks_.pop_front(); |
- |
- MayBeDoNextListAccounts(); |
} |
-void AccountReconcilor::OnListAccountsFailure( |
- const GoogleServiceAuthError& error) { |
- gaia_fetcher_.reset(); |
- VLOG(1) << "AccountReconcilor::OnListAccountsFailure: " << error.ToString(); |
- std::vector<std::pair<std::string, bool> > empty_accounts; |
- |
- // There must be at least one callback waiting for result. |
- DCHECK(!get_gaia_accounts_callbacks_.empty()); |
- |
- get_gaia_accounts_callbacks_.front().Run(error, empty_accounts); |
- get_gaia_accounts_callbacks_.pop_front(); |
- |
- MayBeDoNextListAccounts(); |
-} |
- |
-void AccountReconcilor::MayBeDoNextListAccounts() { |
- if (!get_gaia_accounts_callbacks_.empty()) { |
- gaia_fetcher_.reset(new GaiaAuthFetcher( |
- this, GaiaConstants::kReconcilorSource, |
- client_->GetURLRequestContext())); |
- gaia_fetcher_->StartListAccounts(); |
- } |
-} |
- |
-void AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts( |
- const GoogleServiceAuthError& error, |
- const std::vector<std::pair<std::string, bool> >& accounts) { |
+void AccountReconcilor::OnGaiaAccountsInCookieUpdated( |
+ const std::vector<std::pair<std::string, bool> >& accounts, |
+ const GoogleServiceAuthError& error) { |
if (error.state() == GoogleServiceAuthError::NONE) { |
gaia_accounts_ = accounts; |
- are_gaia_accounts_set_ = true; |
- FinishReconcile(); |
+ |
+ // It is possible that O2RT is not available at this moment. |
+ if (token_service_->GetAccounts().empty()) |
+ return; |
+ |
+ is_reconcile_started_ ? FinishReconcile() : StartReconcile(); |
} else { |
AbortReconcile(); |
} |
@@ -407,7 +308,6 @@ void AccountReconcilor::OnNewProfileManagementFlagChanged( |
void AccountReconcilor::FinishReconcile() { |
VLOG(1) << "AccountReconcilor::FinishReconcile"; |
- DCHECK(are_gaia_accounts_set_); |
DCHECK(add_to_cookie_.empty()); |
int number_gaia_accounts = gaia_accounts_.size(); |
bool are_primaries_equal = number_gaia_accounts > 0 && |