| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 SyncBackendHostCore::~SyncBackendHostCore() { | 128 SyncBackendHostCore::~SyncBackendHostCore() { |
| 129 DCHECK(!sync_manager_.get()); | 129 DCHECK(!sync_manager_.get()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void SyncBackendHostCore::OnSyncCycleCompleted( | 132 void SyncBackendHostCore::OnSyncCycleCompleted( |
| 133 const syncer::sessions::SyncSessionSnapshot& snapshot) { | 133 const syncer::sessions::SyncSessionSnapshot& snapshot) { |
| 134 if (!sync_loop_) | 134 if (!sync_loop_) |
| 135 return; | 135 return; |
| 136 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 136 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 137 | 137 |
| 138 host_.Call( | 138 host_.Call( |
| 139 FROM_HERE, | 139 FROM_HERE, |
| 140 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop, | 140 &SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop, |
| 141 snapshot); | 141 snapshot); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SyncBackendHostCore::DoRefreshTypes(syncer::ModelTypeSet types) { | 144 void SyncBackendHostCore::DoRefreshTypes(syncer::ModelTypeSet types) { |
| 145 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 145 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 146 sync_manager_->RefreshTypes(types); | 146 sync_manager_->RefreshTypes(types); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void SyncBackendHostCore::OnInitializationComplete( | 149 void SyncBackendHostCore::OnInitializationComplete( |
| 150 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 150 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 151 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 151 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 152 debug_info_listener, | 152 debug_info_listener, |
| 153 bool success, | 153 bool success, |
| 154 const syncer::ModelTypeSet restored_types) { | 154 const syncer::ModelTypeSet restored_types) { |
| 155 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 155 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 156 | 156 |
| 157 if (!success) { | 157 if (!success) { |
| 158 DoDestroySyncManager(syncer::STOP_SYNC); | 158 DoDestroySyncManager(syncer::STOP_SYNC); |
| 159 host_.Call(FROM_HERE, | 159 host_.Call(FROM_HERE, |
| 160 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); | 160 &SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop); |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Register for encryption related changes now. We have to do this before | 164 // Register for encryption related changes now. We have to do this before |
| 165 // the initializing downloading control types or initializing the encryption | 165 // the initializing downloading control types or initializing the encryption |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 routing_info, | 212 routing_info, |
| 213 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, | 213 base::Bind(&SyncBackendHostCore::DoInitialProcessControlTypes, |
| 214 weak_ptr_factory_.GetWeakPtr()), | 214 weak_ptr_factory_.GetWeakPtr()), |
| 215 base::Closure()); | 215 base::Closure()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void SyncBackendHostCore::OnConnectionStatusChange( | 218 void SyncBackendHostCore::OnConnectionStatusChange( |
| 219 syncer::ConnectionStatus status) { | 219 syncer::ConnectionStatus status) { |
| 220 if (!sync_loop_) | 220 if (!sync_loop_) |
| 221 return; | 221 return; |
| 222 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 222 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 223 host_.Call( | 223 host_.Call( |
| 224 FROM_HERE, | 224 FROM_HERE, |
| 225 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, status); | 225 &SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop, status); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void SyncBackendHostCore::OnPassphraseRequired( | 228 void SyncBackendHostCore::OnPassphraseRequired( |
| 229 syncer::PassphraseRequiredReason reason, | 229 syncer::PassphraseRequiredReason reason, |
| 230 const sync_pb::EncryptedData& pending_keys) { | 230 const sync_pb::EncryptedData& pending_keys) { |
| 231 if (!sync_loop_) | 231 if (!sync_loop_) |
| 232 return; | 232 return; |
| 233 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 233 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 234 host_.Call( | 234 host_.Call( |
| 235 FROM_HERE, | 235 FROM_HERE, |
| 236 &SyncBackendHostImpl::NotifyPassphraseRequired, reason, pending_keys); | 236 &SyncBackendHostImpl::NotifyPassphraseRequired, reason, pending_keys); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void SyncBackendHostCore::OnPassphraseAccepted() { | 239 void SyncBackendHostCore::OnPassphraseAccepted() { |
| 240 if (!sync_loop_) | 240 if (!sync_loop_) |
| 241 return; | 241 return; |
| 242 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 242 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 243 host_.Call( | 243 host_.Call( |
| 244 FROM_HERE, | 244 FROM_HERE, |
| 245 &SyncBackendHostImpl::NotifyPassphraseAccepted); | 245 &SyncBackendHostImpl::NotifyPassphraseAccepted); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void SyncBackendHostCore::OnBootstrapTokenUpdated( | 248 void SyncBackendHostCore::OnBootstrapTokenUpdated( |
| 249 const std::string& bootstrap_token, | 249 const std::string& bootstrap_token, |
| 250 syncer::BootstrapTokenType type) { | 250 syncer::BootstrapTokenType type) { |
| 251 if (!sync_loop_) | 251 if (!sync_loop_) |
| 252 return; | 252 return; |
| 253 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 253 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 254 host_.Call(FROM_HERE, | 254 host_.Call(FROM_HERE, |
| 255 &SyncBackendHostImpl::PersistEncryptionBootstrapToken, | 255 &SyncBackendHostImpl::PersistEncryptionBootstrapToken, |
| 256 bootstrap_token, | 256 bootstrap_token, |
| 257 type); | 257 type); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void SyncBackendHostCore::OnEncryptedTypesChanged( | 260 void SyncBackendHostCore::OnEncryptedTypesChanged( |
| 261 syncer::ModelTypeSet encrypted_types, | 261 syncer::ModelTypeSet encrypted_types, |
| 262 bool encrypt_everything) { | 262 bool encrypt_everything) { |
| 263 if (!sync_loop_) | 263 if (!sync_loop_) |
| 264 return; | 264 return; |
| 265 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 265 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 266 // NOTE: We're in a transaction. | 266 // NOTE: We're in a transaction. |
| 267 host_.Call( | 267 host_.Call( |
| 268 FROM_HERE, | 268 FROM_HERE, |
| 269 &SyncBackendHostImpl::NotifyEncryptedTypesChanged, | 269 &SyncBackendHostImpl::NotifyEncryptedTypesChanged, |
| 270 encrypted_types, encrypt_everything); | 270 encrypted_types, encrypt_everything); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void SyncBackendHostCore::OnEncryptionComplete() { | 273 void SyncBackendHostCore::OnEncryptionComplete() { |
| 274 if (!sync_loop_) | 274 if (!sync_loop_) |
| 275 return; | 275 return; |
| 276 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 276 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 277 // NOTE: We're in a transaction. | 277 // NOTE: We're in a transaction. |
| 278 host_.Call( | 278 host_.Call( |
| 279 FROM_HERE, | 279 FROM_HERE, |
| 280 &SyncBackendHostImpl::NotifyEncryptionComplete); | 280 &SyncBackendHostImpl::NotifyEncryptionComplete); |
| 281 } | 281 } |
| 282 | 282 |
| 283 void SyncBackendHostCore::OnCryptographerStateChanged( | 283 void SyncBackendHostCore::OnCryptographerStateChanged( |
| 284 syncer::Cryptographer* cryptographer) { | 284 syncer::Cryptographer* cryptographer) { |
| 285 // Do nothing. | 285 // Do nothing. |
| 286 } | 286 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 host_.Call( | 325 host_.Call( |
| 326 FROM_HERE, | 326 FROM_HERE, |
| 327 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop, | 327 &SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop, |
| 328 type, counters); | 328 type, counters); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void SyncBackendHostCore::OnActionableError( | 331 void SyncBackendHostCore::OnActionableError( |
| 332 const syncer::SyncProtocolError& sync_error) { | 332 const syncer::SyncProtocolError& sync_error) { |
| 333 if (!sync_loop_) | 333 if (!sync_loop_) |
| 334 return; | 334 return; |
| 335 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 335 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 336 host_.Call( | 336 host_.Call( |
| 337 FROM_HERE, | 337 FROM_HERE, |
| 338 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop, | 338 &SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop, |
| 339 sync_error); | 339 sync_error); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void SyncBackendHostCore::OnMigrationRequested(syncer::ModelTypeSet types) { | 342 void SyncBackendHostCore::OnMigrationRequested(syncer::ModelTypeSet types) { |
| 343 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 343 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 344 host_.Call( | 344 host_.Call( |
| 345 FROM_HERE, | 345 FROM_HERE, |
| 346 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop, | 346 &SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop, |
| 347 types); | 347 types); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void SyncBackendHostCore::OnProtocolEvent( | 350 void SyncBackendHostCore::OnProtocolEvent( |
| 351 const syncer::ProtocolEvent& event) { | 351 const syncer::ProtocolEvent& event) { |
| 352 // TODO(rlarocque): Find a way to pass event_clone as a scoped_ptr. | 352 // TODO(rlarocque): Find a way to pass event_clone as a scoped_ptr. |
| 353 if (forward_protocol_events_) { | 353 if (forward_protocol_events_) { |
| 354 std::unique_ptr<syncer::ProtocolEvent> event_clone(event.Clone()); | 354 std::unique_ptr<syncer::ProtocolEvent> event_clone(event.Clone()); |
| 355 host_.Call( | 355 host_.Call( |
| 356 FROM_HERE, | 356 FROM_HERE, |
| 357 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, | 357 &SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop, |
| 358 event_clone.release()); | 358 event_clone.release()); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 void SyncBackendHostCore::DoOnInvalidatorStateChange( | 362 void SyncBackendHostCore::DoOnInvalidatorStateChange( |
| 363 syncer::InvalidatorState state) { | 363 syncer::InvalidatorState state) { |
| 364 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 364 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 365 sync_manager_->SetInvalidatorEnabled(state == syncer::INVALIDATIONS_ENABLED); | 365 sync_manager_->SetInvalidatorEnabled(state == syncer::INVALIDATIONS_ENABLED); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void SyncBackendHostCore::DoOnIncomingInvalidation( | 368 void SyncBackendHostCore::DoOnIncomingInvalidation( |
| 369 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 369 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| 370 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 370 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 371 | 371 |
| 372 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); | 372 syncer::ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 373 for (const invalidation::ObjectId& object_id : ids) { | 373 for (const invalidation::ObjectId& object_id : ids) { |
| 374 syncer::ModelType type; | 374 syncer::ModelType type; |
| 375 if (!NotificationTypeToRealModelType(object_id.name(), &type)) { | 375 if (!NotificationTypeToRealModelType(object_id.name(), &type)) { |
| 376 DLOG(WARNING) << "Notification has invalid id: " | 376 DLOG(WARNING) << "Notification has invalid id: " |
| 377 << syncer::ObjectIdToString(object_id); | 377 << syncer::ObjectIdToString(object_id); |
| 378 } else { | 378 } else { |
| 379 syncer::SingleObjectInvalidationSet invalidation_set = | 379 syncer::SingleObjectInvalidationSet invalidation_set = |
| 380 invalidation_map.ForObject(object_id); | 380 invalidation_map.ForObject(object_id); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 args.unrecoverable_error_handler = options->unrecoverable_error_handler; | 456 args.unrecoverable_error_handler = options->unrecoverable_error_handler; |
| 457 args.report_unrecoverable_error_function = | 457 args.report_unrecoverable_error_function = |
| 458 options->report_unrecoverable_error_function; | 458 options->report_unrecoverable_error_function; |
| 459 args.cancelation_signal = &stop_syncing_signal_; | 459 args.cancelation_signal = &stop_syncing_signal_; |
| 460 args.saved_nigori_state = std::move(options->saved_nigori_state); | 460 args.saved_nigori_state = std::move(options->saved_nigori_state); |
| 461 sync_manager_->Init(&args); | 461 sync_manager_->Init(&args); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void SyncBackendHostCore::DoUpdateCredentials( | 464 void SyncBackendHostCore::DoUpdateCredentials( |
| 465 const syncer::SyncCredentials& credentials) { | 465 const syncer::SyncCredentials& credentials) { |
| 466 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 466 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 467 // UpdateCredentials can be called during backend initialization, possibly | 467 // UpdateCredentials can be called during backend initialization, possibly |
| 468 // when backend initialization has failed but hasn't notified the UI thread | 468 // when backend initialization has failed but hasn't notified the UI thread |
| 469 // yet. In that case, the sync manager may have been destroyed on the sync | 469 // yet. In that case, the sync manager may have been destroyed on the sync |
| 470 // thread before this task was executed, so we do nothing. | 470 // thread before this task was executed, so we do nothing. |
| 471 if (sync_manager_) { | 471 if (sync_manager_) { |
| 472 sync_manager_->UpdateCredentials(credentials); | 472 sync_manager_->UpdateCredentials(credentials); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 | 475 |
| 476 void SyncBackendHostCore::DoStartSyncing( | 476 void SyncBackendHostCore::DoStartSyncing( |
| 477 const syncer::ModelSafeRoutingInfo& routing_info, | 477 const syncer::ModelSafeRoutingInfo& routing_info, |
| 478 base::Time last_poll_time) { | 478 base::Time last_poll_time) { |
| 479 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 479 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 480 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); | 480 sync_manager_->StartSyncingNormally(routing_info, last_poll_time); |
| 481 } | 481 } |
| 482 | 482 |
| 483 void SyncBackendHostCore::DoSetEncryptionPassphrase( | 483 void SyncBackendHostCore::DoSetEncryptionPassphrase( |
| 484 const std::string& passphrase, | 484 const std::string& passphrase, |
| 485 bool is_explicit) { | 485 bool is_explicit) { |
| 486 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 486 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 487 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( | 487 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( |
| 488 passphrase, is_explicit); | 488 passphrase, is_explicit); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void SyncBackendHostCore::DoInitialProcessControlTypes() { | 491 void SyncBackendHostCore::DoInitialProcessControlTypes() { |
| 492 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 492 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 493 | 493 |
| 494 DVLOG(1) << "Initilalizing Control Types"; | 494 DVLOG(1) << "Initilalizing Control Types"; |
| 495 | 495 |
| 496 // Initialize encryption. | 496 // Initialize encryption. |
| 497 sync_manager_->GetEncryptionHandler()->Init(); | 497 sync_manager_->GetEncryptionHandler()->Init(); |
| 498 | 498 |
| 499 // Note: experiments are currently handled via SBH::AddExperimentalTypes, | 499 // Note: experiments are currently handled via SBH::AddExperimentalTypes, |
| 500 // which is called at the end of every sync cycle. | 500 // which is called at the end of every sync cycle. |
| 501 // TODO(zea): eventually add an experiment handler and initialize it here. | 501 // TODO(zea): eventually add an experiment handler and initialize it here. |
| 502 | 502 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 521 js_backend_, debug_info_listener_, | 521 js_backend_, debug_info_listener_, |
| 522 base::Passed(sync_manager_->GetModelTypeConnectorProxy()), | 522 base::Passed(sync_manager_->GetModelTypeConnectorProxy()), |
| 523 sync_manager_->cache_guid()); | 523 sync_manager_->cache_guid()); |
| 524 | 524 |
| 525 js_backend_.Reset(); | 525 js_backend_.Reset(); |
| 526 debug_info_listener_.Reset(); | 526 debug_info_listener_.Reset(); |
| 527 } | 527 } |
| 528 | 528 |
| 529 void SyncBackendHostCore::DoSetDecryptionPassphrase( | 529 void SyncBackendHostCore::DoSetDecryptionPassphrase( |
| 530 const std::string& passphrase) { | 530 const std::string& passphrase) { |
| 531 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 531 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 532 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( | 532 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
| 533 passphrase); | 533 passphrase); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void SyncBackendHostCore::DoEnableEncryptEverything() { | 536 void SyncBackendHostCore::DoEnableEncryptEverything() { |
| 537 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 537 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 538 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 538 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
| 539 } | 539 } |
| 540 | 540 |
| 541 void SyncBackendHostCore::ShutdownOnUIThread() { | 541 void SyncBackendHostCore::ShutdownOnUIThread() { |
| 542 // This will cut short any blocking network tasks, cut short any in-progress | 542 // This will cut short any blocking network tasks, cut short any in-progress |
| 543 // sync cycles, and prevent the creation of new blocking network tasks and new | 543 // sync cycles, and prevent the creation of new blocking network tasks and new |
| 544 // sync cycles. If there was an in-progress network request, it would have | 544 // sync cycles. If there was an in-progress network request, it would have |
| 545 // had a reference to the RequestContextGetter. This reference will be | 545 // had a reference to the RequestContextGetter. This reference will be |
| 546 // dropped by the time this function returns. | 546 // dropped by the time this function returns. |
| 547 // | 547 // |
| 548 // It is safe to call this even if Sync's backend classes have not been | 548 // It is safe to call this even if Sync's backend classes have not been |
| 549 // initialized yet. Those classes will receive the message when the sync | 549 // initialized yet. Those classes will receive the message when the sync |
| 550 // thread finally getes around to constructing them. | 550 // thread finally getes around to constructing them. |
| 551 stop_syncing_signal_.Signal(); | 551 stop_syncing_signal_.Signal(); |
| 552 | 552 |
| 553 // This will drop the HttpBridgeFactory's reference to the | 553 // This will drop the HttpBridgeFactory's reference to the |
| 554 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can | 554 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can |
| 555 // no longer be used to create new HttpBridge instances. We can get away with | 555 // no longer be used to create new HttpBridge instances. We can get away with |
| 556 // this because the stop_syncing_signal_ has already been signalled, which | 556 // this because the stop_syncing_signal_ has already been signalled, which |
| 557 // guarantees that the ServerConnectionManager will no longer attempt to | 557 // guarantees that the ServerConnectionManager will no longer attempt to |
| 558 // create new connections. | 558 // create new connections. |
| 559 release_request_context_signal_.Signal(); | 559 release_request_context_signal_.Signal(); |
| 560 } | 560 } |
| 561 | 561 |
| 562 void SyncBackendHostCore::DoShutdown(syncer::ShutdownReason reason) { | 562 void SyncBackendHostCore::DoShutdown(syncer::ShutdownReason reason) { |
| 563 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 563 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 564 | 564 |
| 565 DoDestroySyncManager(reason); | 565 DoDestroySyncManager(reason); |
| 566 | 566 |
| 567 registrar_ = NULL; | 567 registrar_ = NULL; |
| 568 | 568 |
| 569 if (reason == syncer::DISABLE_SYNC) | 569 if (reason == syncer::DISABLE_SYNC) |
| 570 DeleteSyncDataFolder(); | 570 DeleteSyncDataFolder(); |
| 571 | 571 |
| 572 host_.Reset(); | 572 host_.Reset(); |
| 573 weak_ptr_factory_.InvalidateWeakPtrs(); | 573 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 574 } | 574 } |
| 575 | 575 |
| 576 void SyncBackendHostCore::DoDestroySyncManager(syncer::ShutdownReason reason) { | 576 void SyncBackendHostCore::DoDestroySyncManager(syncer::ShutdownReason reason) { |
| 577 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 577 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 578 if (sync_manager_) { | 578 if (sync_manager_) { |
| 579 DisableDirectoryTypeDebugInfoForwarding(); | 579 DisableDirectoryTypeDebugInfoForwarding(); |
| 580 save_changes_timer_.reset(); | 580 save_changes_timer_.reset(); |
| 581 sync_manager_->RemoveObserver(this); | 581 sync_manager_->RemoveObserver(this); |
| 582 sync_manager_->ShutdownOnSyncThread(reason); | 582 sync_manager_->ShutdownOnSyncThread(reason); |
| 583 sync_manager_.reset(); | 583 sync_manager_.reset(); |
| 584 } | 584 } |
| 585 } | 585 } |
| 586 | 586 |
| 587 void SyncBackendHostCore::DoConfigureSyncer( | 587 void SyncBackendHostCore::DoConfigureSyncer( |
| 588 syncer::ConfigureReason reason, | 588 syncer::ConfigureReason reason, |
| 589 const DoConfigureSyncerTypes& config_types, | 589 const DoConfigureSyncerTypes& config_types, |
| 590 const syncer::ModelSafeRoutingInfo routing_info, | 590 const syncer::ModelSafeRoutingInfo routing_info, |
| 591 const base::Callback<void(syncer::ModelTypeSet, | 591 const base::Callback<void(syncer::ModelTypeSet, |
| 592 syncer::ModelTypeSet)>& ready_task, | 592 syncer::ModelTypeSet)>& ready_task, |
| 593 const base::Closure& retry_callback) { | 593 const base::Closure& retry_callback) { |
| 594 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 594 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 595 DCHECK(!ready_task.is_null()); | 595 DCHECK(!ready_task.is_null()); |
| 596 DCHECK(!retry_callback.is_null()); | 596 DCHECK(!retry_callback.is_null()); |
| 597 base::Closure chained_ready_task( | 597 base::Closure chained_ready_task( |
| 598 base::Bind(&SyncBackendHostCore::DoFinishConfigureDataTypes, | 598 base::Bind(&SyncBackendHostCore::DoFinishConfigureDataTypes, |
| 599 weak_ptr_factory_.GetWeakPtr(), | 599 weak_ptr_factory_.GetWeakPtr(), |
| 600 config_types.to_download, | 600 config_types.to_download, |
| 601 ready_task)); | 601 ready_task)); |
| 602 base::Closure chained_retry_task( | 602 base::Closure chained_retry_task( |
| 603 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, | 603 base::Bind(&SyncBackendHostCore::DoRetryConfiguration, |
| 604 weak_ptr_factory_.GetWeakPtr(), | 604 weak_ptr_factory_.GetWeakPtr(), |
| 605 retry_callback)); | 605 retry_callback)); |
| 606 sync_manager_->ConfigureSyncer(reason, | 606 sync_manager_->ConfigureSyncer(reason, |
| 607 config_types.to_download, | 607 config_types.to_download, |
| 608 config_types.to_purge, | 608 config_types.to_purge, |
| 609 config_types.to_journal, | 609 config_types.to_journal, |
| 610 config_types.to_unapply, | 610 config_types.to_unapply, |
| 611 routing_info, | 611 routing_info, |
| 612 chained_ready_task, | 612 chained_ready_task, |
| 613 chained_retry_task); | 613 chained_retry_task); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void SyncBackendHostCore::DoFinishConfigureDataTypes( | 616 void SyncBackendHostCore::DoFinishConfigureDataTypes( |
| 617 syncer::ModelTypeSet types_to_config, | 617 syncer::ModelTypeSet types_to_config, |
| 618 const base::Callback<void(syncer::ModelTypeSet, | 618 const base::Callback<void(syncer::ModelTypeSet, |
| 619 syncer::ModelTypeSet)>& ready_task) { | 619 syncer::ModelTypeSet)>& ready_task) { |
| 620 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 620 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 621 | 621 |
| 622 // Update the enabled types for the bridge and sync manager. | 622 // Update the enabled types for the bridge and sync manager. |
| 623 syncer::ModelSafeRoutingInfo routing_info; | 623 syncer::ModelSafeRoutingInfo routing_info; |
| 624 registrar_->GetModelSafeRoutingInfo(&routing_info); | 624 registrar_->GetModelSafeRoutingInfo(&routing_info); |
| 625 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); | 625 syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); |
| 626 enabled_types.RemoveAll(syncer::ProxyTypes()); | 626 enabled_types.RemoveAll(syncer::ProxyTypes()); |
| 627 | 627 |
| 628 const syncer::ModelTypeSet failed_configuration_types = | 628 const syncer::ModelTypeSet failed_configuration_types = |
| 629 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); | 629 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); |
| 630 const syncer::ModelTypeSet succeeded_configuration_types = | 630 const syncer::ModelTypeSet succeeded_configuration_types = |
| 631 Difference(types_to_config, failed_configuration_types); | 631 Difference(types_to_config, failed_configuration_types); |
| 632 host_.Call(FROM_HERE, | 632 host_.Call(FROM_HERE, |
| 633 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop, | 633 &SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop, |
| 634 enabled_types, | 634 enabled_types, |
| 635 succeeded_configuration_types, | 635 succeeded_configuration_types, |
| 636 failed_configuration_types, | 636 failed_configuration_types, |
| 637 ready_task); | 637 ready_task); |
| 638 } | 638 } |
| 639 | 639 |
| 640 void SyncBackendHostCore::DoRetryConfiguration( | 640 void SyncBackendHostCore::DoRetryConfiguration( |
| 641 const base::Closure& retry_callback) { | 641 const base::Closure& retry_callback) { |
| 642 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 642 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 643 host_.Call(FROM_HERE, | 643 host_.Call(FROM_HERE, |
| 644 &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, | 644 &SyncBackendHostImpl::RetryConfigurationOnFrontendLoop, |
| 645 retry_callback); | 645 retry_callback); |
| 646 } | 646 } |
| 647 | 647 |
| 648 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { | 648 void SyncBackendHostCore::SendBufferedProtocolEventsAndEnableForwarding() { |
| 649 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 649 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 650 forward_protocol_events_ = true; | 650 forward_protocol_events_ = true; |
| 651 | 651 |
| 652 if (sync_manager_) { | 652 if (sync_manager_) { |
| 653 // Grab our own copy of the buffered events. | 653 // Grab our own copy of the buffered events. |
| 654 // The buffer is not modified by this operation. | 654 // The buffer is not modified by this operation. |
| 655 std::vector<syncer::ProtocolEvent*> buffered_events; | 655 std::vector<syncer::ProtocolEvent*> buffered_events; |
| 656 sync_manager_->GetBufferedProtocolEvents().release(&buffered_events); | 656 sync_manager_->GetBufferedProtocolEvents().release(&buffered_events); |
| 657 | 657 |
| 658 // Send them all over the fence to the host. | 658 // Send them all over the fence to the host. |
| 659 for (std::vector<syncer::ProtocolEvent*>::iterator it = | 659 for (std::vector<syncer::ProtocolEvent*>::iterator it = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 687 if (!forward_type_info_) | 687 if (!forward_type_info_) |
| 688 return; | 688 return; |
| 689 | 689 |
| 690 forward_type_info_ = false; | 690 forward_type_info_ = false; |
| 691 | 691 |
| 692 if (sync_manager_->HasDirectoryTypeDebugInfoObserver(this)) | 692 if (sync_manager_->HasDirectoryTypeDebugInfoObserver(this)) |
| 693 sync_manager_->UnregisterDirectoryTypeDebugInfoObserver(this); | 693 sync_manager_->UnregisterDirectoryTypeDebugInfoObserver(this); |
| 694 } | 694 } |
| 695 | 695 |
| 696 void SyncBackendHostCore::DeleteSyncDataFolder() { | 696 void SyncBackendHostCore::DeleteSyncDataFolder() { |
| 697 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 697 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 698 if (base::DirectoryExists(sync_data_folder_path_)) { | 698 if (base::DirectoryExists(sync_data_folder_path_)) { |
| 699 if (!base::DeleteFile(sync_data_folder_path_, true)) | 699 if (!base::DeleteFile(sync_data_folder_path_, true)) |
| 700 SLOG(DFATAL) << "Could not delete the Sync Data folder."; | 700 SLOG(DFATAL) << "Could not delete the Sync Data folder."; |
| 701 } | 701 } |
| 702 } | 702 } |
| 703 | 703 |
| 704 void SyncBackendHostCore::GetAllNodesForTypes( | 704 void SyncBackendHostCore::GetAllNodesForTypes( |
| 705 syncer::ModelTypeSet types, | 705 syncer::ModelTypeSet types, |
| 706 scoped_refptr<base::SequencedTaskRunner> task_runner, | 706 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 707 base::Callback<void(const std::vector<syncer::ModelType>& type, | 707 base::Callback<void(const std::vector<syncer::ModelType>& type, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 725 | 725 |
| 726 task_runner->PostTask( | 726 task_runner->PostTask( |
| 727 FROM_HERE, | 727 FROM_HERE, |
| 728 base::Bind(callback, types_vector, base::Passed(&node_lists))); | 728 base::Bind(callback, types_vector, base::Passed(&node_lists))); |
| 729 } | 729 } |
| 730 | 730 |
| 731 void SyncBackendHostCore::StartSavingChanges() { | 731 void SyncBackendHostCore::StartSavingChanges() { |
| 732 // We may already be shut down. | 732 // We may already be shut down. |
| 733 if (!sync_loop_) | 733 if (!sync_loop_) |
| 734 return; | 734 return; |
| 735 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 735 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 736 DCHECK(!save_changes_timer_.get()); | 736 DCHECK(!save_changes_timer_.get()); |
| 737 save_changes_timer_.reset(new base::RepeatingTimer()); | 737 save_changes_timer_.reset(new base::RepeatingTimer()); |
| 738 save_changes_timer_->Start(FROM_HERE, | 738 save_changes_timer_->Start(FROM_HERE, |
| 739 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), | 739 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), |
| 740 this, &SyncBackendHostCore::SaveChanges); | 740 this, &SyncBackendHostCore::SaveChanges); |
| 741 } | 741 } |
| 742 | 742 |
| 743 void SyncBackendHostCore::SaveChanges() { | 743 void SyncBackendHostCore::SaveChanges() { |
| 744 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 744 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 745 sync_manager_->SaveChanges(); | 745 sync_manager_->SaveChanges(); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void SyncBackendHostCore::DoClearServerData( | 748 void SyncBackendHostCore::DoClearServerData( |
| 749 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { | 749 const syncer::SyncManager::ClearServerDataCallback& frontend_callback) { |
| 750 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 750 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 751 const syncer::SyncManager::ClearServerDataCallback callback = | 751 const syncer::SyncManager::ClearServerDataCallback callback = |
| 752 base::Bind(&SyncBackendHostCore::ClearServerDataDone, | 752 base::Bind(&SyncBackendHostCore::ClearServerDataDone, |
| 753 weak_ptr_factory_.GetWeakPtr(), frontend_callback); | 753 weak_ptr_factory_.GetWeakPtr(), frontend_callback); |
| 754 sync_manager_->ClearServerData(callback); | 754 sync_manager_->ClearServerData(callback); |
| 755 } | 755 } |
| 756 | 756 |
| 757 void SyncBackendHostCore::DoOnCookieJarChanged(bool account_mismatch, | 757 void SyncBackendHostCore::DoOnCookieJarChanged(bool account_mismatch, |
| 758 bool empty_jar) { | 758 bool empty_jar) { |
| 759 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 759 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 760 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar); | 760 sync_manager_->OnCookieJarChanged(account_mismatch, empty_jar); |
| 761 } | 761 } |
| 762 | 762 |
| 763 void SyncBackendHostCore::ClearServerDataDone( | 763 void SyncBackendHostCore::ClearServerDataDone( |
| 764 const base::Closure& frontend_callback) { | 764 const base::Closure& frontend_callback) { |
| 765 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 765 DCHECK(sync_loop_->task_runner()->BelongsToCurrentThread()); |
| 766 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, | 766 host_.Call(FROM_HERE, &SyncBackendHostImpl::ClearServerDataDoneOnFrontendLoop, |
| 767 frontend_callback); | 767 frontend_callback); |
| 768 } | 768 } |
| 769 | 769 |
| 770 | 770 |
| 771 } // namespace browser_sync | 771 } // namespace browser_sync |
| OLD | NEW |