| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/engine_impl/sync_manager_impl.h" | 5 #include "components/sync/engine_impl/sync_manager_impl.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include <utility> | 9 #include <utility> | 
| 10 | 10 | 
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 177 | 177 | 
| 178     if (marker.token().empty()) | 178     if (marker.token().empty()) | 
| 179       result.Put(i.Get()); | 179       result.Put(i.Get()); | 
| 180   } | 180   } | 
| 181   return result; | 181   return result; | 
| 182 } | 182 } | 
| 183 | 183 | 
| 184 void SyncManagerImpl::ConfigureSyncer( | 184 void SyncManagerImpl::ConfigureSyncer( | 
| 185     ConfigureReason reason, | 185     ConfigureReason reason, | 
| 186     ModelTypeSet to_download, | 186     ModelTypeSet to_download, | 
| 187     ModelTypeSet to_purge, |  | 
| 188     ModelTypeSet to_journal, |  | 
| 189     ModelTypeSet to_unapply, |  | 
| 190     const ModelSafeRoutingInfo& new_routing_info, | 187     const ModelSafeRoutingInfo& new_routing_info, | 
| 191     const base::Closure& ready_task, | 188     const base::Closure& ready_task, | 
| 192     const base::Closure& retry_task) { | 189     const base::Closure& retry_task) { | 
| 193   DCHECK(thread_checker_.CalledOnValidThread()); | 190   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 194   DCHECK(!ready_task.is_null()); | 191   DCHECK(!ready_task.is_null()); | 
| 195   DCHECK(initialized_); | 192   DCHECK(initialized_); | 
| 196 | 193 | 
| 197   // Don't download non-blocking types that have already completed initial sync. | 194   // Don't download non-blocking types that have already completed initial sync. | 
| 198   to_download.RemoveAll( | 195   to_download.RemoveAll( | 
| 199       model_type_registry_->GetInitialSyncDoneNonBlockingTypes()); | 196       model_type_registry_->GetInitialSyncDoneNonBlockingTypes()); | 
| 200 | 197 | 
| 201   DVLOG(1) << "Configuring -" | 198   DVLOG(1) << "Configuring -" | 
| 202            << "\n\t" | 199            << "\n\t" | 
| 203            << "current types: " | 200            << "current types: " | 
| 204            << ModelTypeSetToString(GetRoutingInfoTypes(new_routing_info)) | 201            << ModelTypeSetToString(GetRoutingInfoTypes(new_routing_info)) | 
| 205            << "\n\t" | 202            << "\n\t" | 
| 206            << "types to download: " << ModelTypeSetToString(to_download) | 203            << "types to download: " << ModelTypeSetToString(to_download); | 
| 207            << "\n\t" |  | 
| 208            << "types to purge: " << ModelTypeSetToString(to_purge) << "\n\t" |  | 
| 209            << "types to journal: " << ModelTypeSetToString(to_journal) << "\n\t" |  | 
| 210            << "types to unapply: " << ModelTypeSetToString(to_unapply); |  | 
| 211   if (!PurgeDisabledTypes(to_purge, to_journal, to_unapply)) { |  | 
| 212     // We failed to cleanup the types. Invoke the ready task without actually |  | 
| 213     // configuring any types. The caller should detect this as a configuration |  | 
| 214     // failure and act appropriately. |  | 
| 215     ready_task.Run(); |  | 
| 216     return; |  | 
| 217   } |  | 
| 218 |  | 
| 219   ConfigurationParams params(GetSourceFromReason(reason), to_download, | 204   ConfigurationParams params(GetSourceFromReason(reason), to_download, | 
| 220                              new_routing_info, ready_task, retry_task); | 205                              new_routing_info, ready_task, retry_task); | 
| 221 | 206 | 
| 222   scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); | 207   scheduler_->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); | 
| 223   scheduler_->ScheduleConfiguration(params); | 208   scheduler_->ScheduleConfiguration(params); | 
| 224 } | 209 } | 
| 225 | 210 | 
| 226 void SyncManagerImpl::Init(InitArgs* args) { | 211 void SyncManagerImpl::Init(InitArgs* args) { | 
| 227   CHECK(!initialized_); | 212   CHECK(!initialized_); | 
| 228   DCHECK(thread_checker_.CalledOnValidThread()); | 213   DCHECK(thread_checker_.CalledOnValidThread()); | 
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 453   // re-downloaded during any configuration. But, it's possible for a datatype | 438   // re-downloaded during any configuration. But, it's possible for a datatype | 
| 454   // to have a progress marker but not have initial sync ended yet, making | 439   // to have a progress marker but not have initial sync ended yet, making | 
| 455   // it a candidate for migration. This is a problem, as the DataTypeManager | 440   // it a candidate for migration. This is a problem, as the DataTypeManager | 
| 456   // does not support a migration while it's already in the middle of a | 441   // does not support a migration while it's already in the middle of a | 
| 457   // configuration. As a result, any partially synced datatype can stall the | 442   // configuration. As a result, any partially synced datatype can stall the | 
| 458   // DTM, waiting for the configuration to complete, which it never will due | 443   // DTM, waiting for the configuration to complete, which it never will due | 
| 459   // to the migration error. In addition, a partially synced nigori will | 444   // to the migration error. In addition, a partially synced nigori will | 
| 460   // trigger the migration logic before the backend is initialized, resulting | 445   // trigger the migration logic before the backend is initialized, resulting | 
| 461   // in crashes. We therefore detect and purge any partially synced types as | 446   // in crashes. We therefore detect and purge any partially synced types as | 
| 462   // part of initialization. | 447   // part of initialization. | 
| 463   if (!PurgePartiallySyncedTypes()) | 448   PurgePartiallySyncedTypes(); | 
| 464     return false; |  | 
| 465 |  | 
| 466   return true; | 449   return true; | 
| 467 } | 450 } | 
| 468 | 451 | 
| 469 bool SyncManagerImpl::PurgePartiallySyncedTypes() { | 452 void SyncManagerImpl::PurgePartiallySyncedTypes() { | 
| 470   ModelTypeSet partially_synced_types = ModelTypeSet::All(); | 453   ModelTypeSet partially_synced_types = ModelTypeSet::All(); | 
| 471   partially_synced_types.RemoveAll(directory()->InitialSyncEndedTypes()); | 454   partially_synced_types.RemoveAll(directory()->InitialSyncEndedTypes()); | 
| 472   partially_synced_types.RemoveAll( | 455   partially_synced_types.RemoveAll( | 
| 473       GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())); | 456       GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())); | 
| 474 | 457 | 
| 475   DVLOG(1) << "Purging partially synced types " | 458   DVLOG(1) << "Purging partially synced types " | 
| 476            << ModelTypeSetToString(partially_synced_types); | 459            << ModelTypeSetToString(partially_synced_types); | 
| 477   UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", | 460   UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", | 
| 478                        partially_synced_types.Size()); | 461                        partially_synced_types.Size()); | 
| 479   if (partially_synced_types.Empty()) | 462   directory()->PurgeEntriesWithTypeIn(partially_synced_types, ModelTypeSet(), | 
| 480     return true; | 463                                       ModelTypeSet()); | 
| 481   return directory()->PurgeEntriesWithTypeIn(partially_synced_types, |  | 
| 482                                              ModelTypeSet(), ModelTypeSet()); |  | 
| 483 } | 464 } | 
| 484 | 465 | 
| 485 bool SyncManagerImpl::PurgeDisabledTypes(ModelTypeSet to_purge, | 466 void SyncManagerImpl::PurgeDisabledTypes(ModelTypeSet to_purge, | 
| 486                                          ModelTypeSet to_journal, | 467                                          ModelTypeSet to_journal, | 
| 487                                          ModelTypeSet to_unapply) { | 468                                          ModelTypeSet to_unapply) { | 
| 488   if (to_purge.Empty()) | 469   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 489     return true; | 470   DCHECK(initialized_); | 
| 490   DVLOG(1) << "Purging disabled types " << ModelTypeSetToString(to_purge); | 471   DVLOG(1) << "Purging disabled types:\n\t" | 
|  | 472            << "types to purge: " << ModelTypeSetToString(to_purge) << "\n\t" | 
|  | 473            << "types to journal: " << ModelTypeSetToString(to_journal) << "\n\t" | 
|  | 474            << "types to unapply: " << ModelTypeSetToString(to_unapply); | 
| 491   DCHECK(to_purge.HasAll(to_journal)); | 475   DCHECK(to_purge.HasAll(to_journal)); | 
| 492   DCHECK(to_purge.HasAll(to_unapply)); | 476   DCHECK(to_purge.HasAll(to_unapply)); | 
| 493   return directory()->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply); | 477   directory()->PurgeEntriesWithTypeIn(to_purge, to_journal, to_unapply); | 
| 494 } | 478 } | 
| 495 | 479 | 
| 496 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { | 480 void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { | 
| 497   DCHECK(thread_checker_.CalledOnValidThread()); | 481   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 498   DCHECK(initialized_); | 482   DCHECK(initialized_); | 
| 499   DCHECK(!credentials.account_id.empty()); | 483   DCHECK(!credentials.account_id.empty()); | 
| 500   DCHECK(!credentials.sync_token.empty()); | 484   DCHECK(!credentials.sync_token.empty()); | 
| 501   DCHECK(!credentials.scope_set.empty()); | 485   DCHECK(!credentials.scope_set.empty()); | 
| 502   cycle_context_->set_account_name(credentials.email); | 486   cycle_context_->set_account_name(credentials.email); | 
| 503 | 487 | 
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1022   DCHECK(thread_checker_.CalledOnValidThread()); | 1006   DCHECK(thread_checker_.CalledOnValidThread()); | 
| 1023   cycle_context_->set_cookie_jar_mismatch(account_mismatch); | 1007   cycle_context_->set_cookie_jar_mismatch(account_mismatch); | 
| 1024   cycle_context_->set_cookie_jar_empty(empty_jar); | 1008   cycle_context_->set_cookie_jar_empty(empty_jar); | 
| 1025 } | 1009 } | 
| 1026 | 1010 | 
| 1027 void SyncManagerImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | 1011 void SyncManagerImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | 
| 1028   directory()->OnMemoryDump(pmd); | 1012   directory()->OnMemoryDump(pmd); | 
| 1029 } | 1013 } | 
| 1030 | 1014 | 
| 1031 }  // namespace syncer | 1015 }  // namespace syncer | 
| OLD | NEW | 
|---|