Chromium Code Reviews| Index: sync/internal_api/sync_manager_impl.cc |
| diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc |
| index 6a164d8f0ff2aac4ff56893cfc13914c323e1737..3c87dab52eda089e3689dee656ce6b8b3a5f4dec 100644 |
| --- a/sync/internal_api/sync_manager_impl.cc |
| +++ b/sync/internal_api/sync_manager_impl.cc |
| @@ -344,6 +344,17 @@ void SyncManagerImpl::ConfigureSyncer( |
| DCHECK(!ready_task.is_null()); |
| DCHECK(!retry_task.is_null()); |
| + // Cleanup any types that might have just been disabled. |
| + if (!CleanupDisabledTypes( |
| + GetRoutingInfoTypes(session_context_->routing_info()), |
| + GetRoutingInfoTypes(new_routing_info))) { |
| + // We failed to cleanup the types. Invoke the ready task without actually |
| + // configuring any types. The caller should detect this as a configuration |
| + // failure and act appropriately. |
| + ready_task.Run(); |
| + return; |
| + } |
| + |
| // TODO(zea): set this based on whether cryptographer has keystore |
| // encryption key or not (requires opening a transaction). crbug.com/129665. |
| ConfigurationParams::KeystoreKeyStatus keystore_key_status = |
| @@ -462,7 +473,16 @@ bool SyncManagerImpl::Init( |
| // trigger the migration logic before the backend is initialized, resulting |
| // in crashes. We therefore detect and purge any partially synced types as |
| // part of initialization. |
| - if (!PurgePartiallySyncedTypes()) |
| + // |
| + // Similarly, a type may have been disabled previously, but we didn't |
| + // manage to purge. Ensure we cleanup any disabled types before starting up. |
| + // |
| + // Note: If either of these methods fail, we have directory corruption and |
| + // cannot continue. |
| + if (!PurgePartiallySyncedTypes() || |
| + !CleanupDisabledTypes( |
|
tim (not reviewing)
2012/07/26 21:39:45
nit - lets use the same verb (Purge/Cleanup) here,
Nicolas Zea
2012/07/26 23:29:59
Done.
|
| + ModelTypeSet::All(), |
| + GetRoutingInfoTypes(session_context_->routing_info()))) |
| success = false; |
| // Cryptographer should only be accessed while holding a |
| @@ -710,6 +730,19 @@ bool SyncManagerImpl::PurgePartiallySyncedTypes() { |
| return directory()->PurgeEntriesWithTypeIn(partially_synced_types); |
| } |
| +bool SyncManagerImpl::CleanupDisabledTypes( |
| + ModelTypeSet previously_enabled_types, |
| + ModelTypeSet currently_enabled_types) { |
| + ModelTypeSet disabled_types = Difference(previously_enabled_types, |
| + currently_enabled_types); |
| + if (disabled_types.Empty()) |
| + return true; |
| + |
| + DVLOG(1) << "Purging disabled types " |
| + << ModelTypeSetToString(disabled_types); |
| + return directory()->PurgeEntriesWithTypeIn(disabled_types); |
| +} |
| + |
| void SyncManagerImpl::UpdateCredentials( |
| const SyncCredentials& credentials) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |