| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/driver/glue/sync_backend_host_core.h" | 5 #include "components/sync/driver/glue/sync_backend_host_core.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // which we initialize below to ensure that we don't perform any downloads if | 134 // which we initialize below to ensure that we don't perform any downloads if |
| 135 // all control types have already completed their initial sync. | 135 // all control types have already completed their initial sync. |
| 136 registrar_->SetInitialTypes(restored_types); | 136 registrar_->SetInitialTypes(restored_types); |
| 137 | 137 |
| 138 ConfigureReason reason = restored_types.Empty() | 138 ConfigureReason reason = restored_types.Empty() |
| 139 ? CONFIGURE_REASON_NEW_CLIENT | 139 ? CONFIGURE_REASON_NEW_CLIENT |
| 140 : CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; | 140 : CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE; |
| 141 | 141 |
| 142 ModelTypeSet new_control_types = | 142 ModelTypeSet new_control_types = |
| 143 registrar_->ConfigureDataTypes(ControlTypes(), ModelTypeSet()); | 143 registrar_->ConfigureDataTypes(ControlTypes(), ModelTypeSet()); |
| 144 |
| 145 // Control types don't have DataTypeControllers, but they need to have |
| 146 // update handlers registered in ModelTypeRegistry. Register them here. |
| 147 ModelTypeConnector* model_type_connector = |
| 148 sync_manager_->GetModelTypeConnector(); |
| 149 ModelTypeSet control_types = ControlTypes(); |
| 150 for (auto it = control_types.First(); it.Good(); it.Inc()) { |
| 151 model_type_connector->RegisterDirectoryType(it.Get(), GROUP_PASSIVE); |
| 152 } |
| 153 |
| 144 ModelSafeRoutingInfo routing_info; | 154 ModelSafeRoutingInfo routing_info; |
| 145 registrar_->GetModelSafeRoutingInfo(&routing_info); | 155 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 146 SDVLOG(1) << "Control Types " << ModelTypeSetToString(new_control_types) | 156 SDVLOG(1) << "Control Types " << ModelTypeSetToString(new_control_types) |
| 147 << " added; calling ConfigureSyncer"; | 157 << " added; calling ConfigureSyncer"; |
| 148 | 158 |
| 149 ModelTypeSet types_to_purge = | 159 ModelTypeSet types_to_purge = |
| 150 Difference(ModelTypeSet::All(), GetRoutingInfoTypes(routing_info)); | 160 Difference(ModelTypeSet::All(), GetRoutingInfoTypes(routing_info)); |
| 151 | 161 |
| 152 sync_manager_->PurgeDisabledTypes(types_to_purge, ModelTypeSet(), | 162 sync_manager_->PurgeDisabledTypes(types_to_purge, ModelTypeSet(), |
| 153 ModelTypeSet()); | 163 ModelTypeSet()); |
| 154 sync_manager_->ConfigureSyncer( | 164 sync_manager_->ConfigureSyncer( |
| 155 reason, new_control_types, routing_info, | 165 reason, new_control_types, |
| 156 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, | 166 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, |
| 157 weak_ptr_factory_.GetWeakPtr()), | 167 weak_ptr_factory_.GetWeakPtr()), |
| 158 base::Closure()); | 168 base::Closure()); |
| 159 } | 169 } |
| 160 | 170 |
| 161 void SyncBackendHostCore::OnConnectionStatusChange(ConnectionStatus status) { | 171 void SyncBackendHostCore::OnConnectionStatusChange(ConnectionStatus status) { |
| 162 DCHECK(thread_checker_.CalledOnValidThread()); | 172 DCHECK(thread_checker_.CalledOnValidThread()); |
| 163 host_.Call(FROM_HERE, | 173 host_.Call(FROM_HERE, |
| 164 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, | 174 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, |
| 165 status); | 175 status); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 DCHECK(thread_checker_.CalledOnValidThread()); | 392 DCHECK(thread_checker_.CalledOnValidThread()); |
| 383 // UpdateCredentials can be called during backend initialization, possibly | 393 // UpdateCredentials can be called during backend initialization, possibly |
| 384 // when backend initialization has failed but hasn't notified the UI thread | 394 // when backend initialization has failed but hasn't notified the UI thread |
| 385 // yet. In that case, the sync manager may have been destroyed on the sync | 395 // yet. In that case, the sync manager may have been destroyed on the sync |
| 386 // thread before this task was executed, so we do nothing. | 396 // thread before this task was executed, so we do nothing. |
| 387 if (sync_manager_) { | 397 if (sync_manager_) { |
| 388 sync_manager_->UpdateCredentials(credentials); | 398 sync_manager_->UpdateCredentials(credentials); |
| 389 } | 399 } |
| 390 } | 400 } |
| 391 | 401 |
| 392 void SyncBackendHostCore::DoStartSyncing( | 402 void SyncBackendHostCore::DoStartConfiguration() { |
| 393 const ModelSafeRoutingInfo& routing_info, | 403 sync_manager_->StartConfiguration(); |
| 394 base::Time last_poll_time) { | 404 } |
| 405 |
| 406 void SyncBackendHostCore::DoStartSyncing(base::Time last_poll_time) { |
| 395 DCHECK(thread_checker_.CalledOnValidThread()); | 407 DCHECK(thread_checker_.CalledOnValidThread()); |
| 396 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); | 408 sync_manager_->StartSyncingNormally(last_poll_time); |
| 397 } | 409 } |
| 398 | 410 |
| 399 void SyncBackendHostCore::DoSetEncryptionPassphrase( | 411 void SyncBackendHostCore::DoSetEncryptionPassphrase( |
| 400 const std::string& passphrase, | 412 const std::string& passphrase, |
| 401 bool is_explicit) { | 413 bool is_explicit) { |
| 402 DCHECK(thread_checker_.CalledOnValidThread()); | 414 DCHECK(thread_checker_.CalledOnValidThread()); |
| 403 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 415 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 404 is_explicit); | 416 is_explicit); |
| 405 } | 417 } |
| 406 | 418 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 520 } |
| 509 | 521 |
| 510 void SyncBackendHostCore::DoConfigureSyncer( | 522 void SyncBackendHostCore::DoConfigureSyncer( |
| 511 ModelTypeConfigurer::ConfigureParams params) { | 523 ModelTypeConfigurer::ConfigureParams params) { |
| 512 DCHECK(thread_checker_.CalledOnValidThread()); | 524 DCHECK(thread_checker_.CalledOnValidThread()); |
| 513 DCHECK(!params.ready_task.is_null()); | 525 DCHECK(!params.ready_task.is_null()); |
| 514 DCHECK(!params.retry_callback.is_null()); | 526 DCHECK(!params.retry_callback.is_null()); |
| 515 | 527 |
| 516 registrar_->ConfigureDataTypes(params.enabled_types, params.disabled_types); | 528 registrar_->ConfigureDataTypes(params.enabled_types, params.disabled_types); |
| 517 | 529 |
| 518 ModelSafeRoutingInfo routing_info; | |
| 519 registrar_->GetModelSafeRoutingInfo(&routing_info); | |
| 520 | |
| 521 base::Closure chained_ready_task(base::Bind( | 530 base::Closure chained_ready_task(base::Bind( |
| 522 &SyncBackendHostCore::DoFinishConfigureDataTypes, | 531 &SyncBackendHostCore::DoFinishConfigureDataTypes, |
| 523 weak_ptr_factory_.GetWeakPtr(), params.to_download, params.ready_task)); | 532 weak_ptr_factory_.GetWeakPtr(), params.to_download, params.ready_task)); |
| 524 base::Closure chained_retry_task( | 533 base::Closure chained_retry_task( |
| 525 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, | 534 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, |
| 526 weak_ptr_factory_.GetWeakPtr(), params.retry_callback)); | 535 weak_ptr_factory_.GetWeakPtr(), params.retry_callback)); |
| 527 | 536 |
| 528 sync_manager_->ConfigureSyncer(params.reason, params.to_download, | 537 sync_manager_->ConfigureSyncer(params.reason, params.to_download, |
| 529 routing_info, chained_ready_task, | 538 chained_ready_task, chained_retry_task); |
| 530 chained_retry_task); | |
| 531 } | 539 } |
| 532 | 540 |
| 533 void SyncBackendHostCore::DoFinishConfigureDataTypes( | 541 void SyncBackendHostCore::DoFinishConfigureDataTypes( |
| 534 ModelTypeSet types_to_config, | 542 ModelTypeSet types_to_config, |
| 535 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { | 543 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { |
| 536 DCHECK(thread_checker_.CalledOnValidThread()); | 544 DCHECK(thread_checker_.CalledOnValidThread()); |
| 537 | 545 |
| 538 // Update the enabled types for the bridge and sync manager. | 546 // Update the enabled types for the bridge and sync manager. |
| 539 ModelSafeRoutingInfo routing_info; | 547 ModelSafeRoutingInfo routing_info; |
| 540 registrar_->GetModelSafeRoutingInfo(&routing_info); | 548 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 644 } |
| 637 | 645 |
| 638 void SyncBackendHostCore::ClearServerDataDone( | 646 void SyncBackendHostCore::ClearServerDataDone( |
| 639 const base::Closure& frontend_callback) { | 647 const base::Closure& frontend_callback) { |
| 640 DCHECK(thread_checker_.CalledOnValidThread()); | 648 DCHECK(thread_checker_.CalledOnValidThread()); |
| 641 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, | 649 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, |
| 642 frontend_callback); | 650 frontend_callback); |
| 643 } | 651 } |
| 644 | 652 |
| 645 } // namespace syncer | 653 } // namespace syncer |
| OLD | NEW |