Chromium Code Reviews| Index: components/browser_sync/browser/profile_sync_service.cc |
| diff --git a/components/browser_sync/browser/profile_sync_service.cc b/components/browser_sync/browser/profile_sync_service.cc |
| index 4c475cb1b2eb2baffd26665070dedc973027a366..727a35dc40321ca28632212c5288b0b14f3ee707 100644 |
| --- a/components/browser_sync/browser/profile_sync_service.cc |
| +++ b/components/browser_sync/browser/profile_sync_service.cc |
| @@ -180,6 +180,7 @@ ProfileSyncService::InitParams::InitParams(InitParams&& other) // NOLINT |
| : sync_client(std::move(other.sync_client)), |
| signin_wrapper(std::move(other.signin_wrapper)), |
| oauth2_token_service(other.oauth2_token_service), |
| + gaia_cookie_manager_service(other.gaia_cookie_manager_service), |
| start_behavior(other.start_behavior), |
| network_time_update_callback( |
| std::move(other.network_time_update_callback)), |
| @@ -225,6 +226,7 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) |
| request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy), |
| connection_status_(syncer::CONNECTION_NOT_ATTEMPTED), |
| last_get_token_error_(GoogleServiceAuthError::AuthErrorNone()), |
| + gaia_cookie_manager_service_(init_params.gaia_cookie_manager_service), |
| network_resources_(new syncer::HttpBridgeNetworkResources), |
| start_behavior_(init_params.start_behavior), |
| directory_path_( |
| @@ -248,6 +250,7 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) |
| } |
| ProfileSyncService::~ProfileSyncService() { |
| + gaia_cookie_manager_service_->RemoveObserver(this); |
| sync_prefs_.RemoveSyncPrefObserver(this); |
| // Shutdown() should have been called before destruction. |
| CHECK(!backend_initialized_); |
| @@ -309,6 +312,8 @@ void ProfileSyncService::Initialize() { |
| sync_client_->GetSyncApiComponentFactory()->RegisterDataTypes( |
| this, register_platform_types_callback); |
| + gaia_cookie_manager_service_->AddObserver(this); |
| + |
| // We clear this here (vs Shutdown) because we want to remember that an error |
| // happened on shutdown so we can display details (message, location) about it |
| // in about:sync. |
| @@ -975,6 +980,13 @@ void ProfileSyncService::PostBackendInitialization() { |
| ConfigureDataTypeManager(); |
| } |
| + // Check for a cookie jar mismatch. |
| + std::vector<gaia::ListedAccount> accounts; |
| + GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| + if (gaia_cookie_manager_service_->ListAccounts(&accounts)) { |
| + OnGaiaAccountsInCookieUpdated(accounts, error); |
| + } |
| + |
| NotifyObservers(); |
| } |
| @@ -2094,6 +2106,27 @@ void ProfileSyncService::GoogleSignedOut(const std::string& account_id, |
| RequestStop(CLEAR_DATA); |
| } |
| +void ProfileSyncService::OnGaiaAccountsInCookieUpdated( |
| + const std::vector<gaia::ListedAccount>& accounts, |
| + const GoogleServiceAuthError& error) { |
| + if (!IsBackendInitialized()) |
| + return; |
| + |
| + bool cookie_mismatch = true; |
| + std::string account_id = signin_->GetAccountIdToUse(); |
| + |
| + // Iterate through list of accounts, looking for current sync account. |
| + for (auto& iter : accounts) { |
|
maxbogue
2016/04/01 22:30:48
const auto& account? iter doesn't really make sens
Nicolas Zea
2016/04/04 19:57:31
Done.
|
| + if (iter.gaia_id == account_id) { |
| + cookie_mismatch = false; |
| + break; |
| + } |
| + } |
| + |
| + DVLOG(1) << "Cookie jar mismatch: " << cookie_mismatch; |
| + backend_->OnCookieJarChanged(cookie_mismatch); |
| +} |
| + |
| void ProfileSyncService::AddObserver( |
| sync_driver::SyncServiceObserver* observer) { |
| observers_.AddObserver(observer); |