| Index: chrome/browser/sync/credential_cache_service_win.cc
|
| diff --git a/chrome/browser/sync/credential_cache_service_win.cc b/chrome/browser/sync/credential_cache_service_win.cc
|
| index 30cb29c1536289a4118086cbd3be75d40e5763c0..e969aa3f823647d590e152b61a41b7602b5f67e6 100644
|
| --- a/chrome/browser/sync/credential_cache_service_win.cc
|
| +++ b/chrome/browser/sync/credential_cache_service_win.cc
|
| @@ -135,6 +135,15 @@ void CredentialCacheService::Observe(
|
| break;
|
| }
|
|
|
| + case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: {
|
| + // Local sync configuration is done. The sync service is now ready to
|
| + // be reconfigured. Immediately look for any unconsumed config changes in
|
| + // the alternate profile. If all changes have been consumed, this is a
|
| + // no-op.
|
| + ScheduleNextReadFromAlternateCredentialCache(0);
|
| + break;
|
| + }
|
| +
|
| case chrome::NOTIFICATION_SYNC_CONFIGURE_START: {
|
| // We have detected a sync sign in, auto-start or reconfigure. Write the
|
| // latest sync preferences to the local cache.
|
| @@ -204,7 +213,8 @@ void CredentialCacheService::ReadCachedCredentialsFromAlternateProfile() {
|
| !HasPref(alternate_store_, prefs::kSyncKeepEverythingSynced)) {
|
| VLOG(1) << "Could not find cached credentials in \""
|
| << GetCredentialPathInAlternateProfile().value() << "\".";
|
| - ScheduleNextReadFromAlternateCredentialCache();
|
| + ScheduleNextReadFromAlternateCredentialCache(
|
| + kCredentialCachePollIntervalSecs);
|
| return;
|
| }
|
|
|
| @@ -310,7 +320,8 @@ void CredentialCacheService::ReadCachedCredentialsFromAlternateProfile() {
|
|
|
| // Schedule the next read from the alternate credential cache so that we can
|
| // detect future reconfigures or sign outs.
|
| - ScheduleNextReadFromAlternateCredentialCache();
|
| + ScheduleNextReadFromAlternateCredentialCache(
|
| + kCredentialCachePollIntervalSecs);
|
| }
|
|
|
| void CredentialCacheService::WriteSyncPrefsToLocalCache() {
|
| @@ -330,7 +341,9 @@ void CredentialCacheService::WriteSyncPrefsToLocalCache() {
|
| }
|
| }
|
|
|
| -void CredentialCacheService::ScheduleNextReadFromAlternateCredentialCache() {
|
| +void CredentialCacheService::ScheduleNextReadFromAlternateCredentialCache(
|
| + int delay_secs) {
|
| + DCHECK_LE(0, delay_secs);
|
| // We must reinitialize |alternate_store_| here because the underlying
|
| // credential file in the alternate profile might have changed, and we must
|
| // re-read it afresh.
|
| @@ -342,7 +355,7 @@ void CredentialCacheService::ScheduleNextReadFromAlternateCredentialCache() {
|
| MessageLoop::current()->PostDelayedTask(
|
| FROM_HERE,
|
| next_read_.callback(),
|
| - TimeDelta::FromSeconds(kCredentialCachePollIntervalSecs));
|
| + TimeDelta::FromSeconds(delay_secs));
|
| }
|
|
|
| bool CredentialCacheService::HasPref(scoped_refptr<JsonPrefStore> store,
|
| @@ -584,7 +597,8 @@ void CredentialCacheService::AlternateStoreObserver::OnInitializationCompleted(
|
| alternate_store_->GetReadError() == JsonPrefStore::PREF_READ_ERROR_NONE) {
|
| service_->ReadCachedCredentialsFromAlternateProfile();
|
| } else {
|
| - service_->ScheduleNextReadFromAlternateCredentialCache();
|
| + service_->ScheduleNextReadFromAlternateCredentialCache(
|
| + kCredentialCachePollIntervalSecs);
|
| }
|
| }
|
|
|
| @@ -634,6 +648,9 @@ void CredentialCacheService::StartListeningForSyncConfigChanges() {
|
| ProfileSyncService* service =
|
| ProfileSyncServiceFactory::GetForProfile(profile_);
|
| registrar_.Add(this,
|
| + chrome::NOTIFICATION_SYNC_CONFIGURE_DONE,
|
| + content::Source<ProfileSyncService>(service));
|
| + registrar_.Add(this,
|
| chrome::NOTIFICATION_SYNC_CONFIGURE_START,
|
| content::Source<ProfileSyncService>(service));
|
|
|
| @@ -738,6 +755,10 @@ void CredentialCacheService::InitiateSignOut() {
|
| bool CredentialCacheService::HaveSyncPrefsChanged(
|
| bool alternate_keep_everything_synced,
|
| ModelTypeSet alternate_preferred_types) const {
|
| + if (alternate_keep_everything_synced &&
|
| + sync_prefs_.HasKeepEverythingSynced()) {
|
| + return false;
|
| + }
|
| ProfileSyncService* service =
|
| ProfileSyncServiceFactory::GetForProfile(profile_);
|
| ModelTypeSet local_preferred_types =
|
| @@ -804,6 +825,7 @@ bool CredentialCacheService::MayReconfigureSync(
|
| // 3) The user is signed in to the alternate profile with the same account.
|
| // 4) The user is not already in the process of configuring sync.
|
| // 5) The alternate cache was updated more recently than the local cache.
|
| + // 6) The sync backend is initialized and ready to consume config changes.
|
| ProfileSyncService* service =
|
| ProfileSyncServiceFactory::GetForProfile(profile_);
|
| return !service->signin()->GetAuthenticatedUsername().empty() &&
|
| @@ -811,7 +833,8 @@ bool CredentialCacheService::MayReconfigureSync(
|
| (alternate_google_services_username ==
|
| service->signin()->GetAuthenticatedUsername()) &&
|
| !service->setup_in_progress() &&
|
| - AlternateCacheIsMoreRecent();
|
| + AlternateCacheIsMoreRecent() &&
|
| + service->ShouldPushChanges();
|
| }
|
|
|
| bool CredentialCacheService::ShouldSignInToSync(
|
|
|