Chromium Code Reviews| 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 "chrome/browser/sync/glue/sync_backend_host_impl.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/invalidation/invalidation_service.h" | 9 #include "chrome/browser/invalidation/invalidation_service.h" |
| 10 #include "chrome/browser/invalidation/invalidation_service_factory.h" | 10 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 | 227 |
| 228 void SyncBackendHostImpl::StopSyncingForShutdown() { | 228 void SyncBackendHostImpl::StopSyncingForShutdown() { |
| 229 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 229 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 230 | 230 |
| 231 // Immediately stop sending messages to the frontend. | 231 // Immediately stop sending messages to the frontend. |
| 232 frontend_ = NULL; | 232 frontend_ = NULL; |
| 233 | 233 |
| 234 // Stop listening for and forwarding locally-triggered sync refresh requests. | 234 // Stop listening for and forwarding locally-triggered sync refresh requests. |
| 235 notification_registrar_.RemoveAll(); | 235 notification_registrar_.RemoveAll(); |
| 236 | 236 |
| 237 // Stop non-blocking sync types from sending any more requests to the syncer. | |
| 238 sync_core_proxy_.reset(); | |
| 239 | |
| 237 DCHECK(registrar_->sync_thread()->IsRunning()); | 240 DCHECK(registrar_->sync_thread()->IsRunning()); |
| 238 | 241 |
| 239 registrar_->RequestWorkerStopOnUIThread(); | 242 registrar_->RequestWorkerStopOnUIThread(); |
| 240 | 243 |
| 241 core_->ShutdownOnUIThread(); | 244 core_->ShutdownOnUIThread(); |
| 242 } | 245 } |
| 243 | 246 |
| 244 scoped_ptr<base::Thread> SyncBackendHostImpl::Shutdown(ShutdownOption option) { | 247 scoped_ptr<base::Thread> SyncBackendHostImpl::Shutdown(ShutdownOption option) { |
| 245 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 248 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| 246 // called first. | 249 // called first. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 } | 284 } |
| 282 | 285 |
| 283 void SyncBackendHostImpl::UnregisterInvalidationIds() { | 286 void SyncBackendHostImpl::UnregisterInvalidationIds() { |
| 284 if (invalidation_handler_registered_) { | 287 if (invalidation_handler_registered_) { |
| 285 invalidator_->UpdateRegisteredInvalidationIds( | 288 invalidator_->UpdateRegisteredInvalidationIds( |
| 286 this, | 289 this, |
| 287 syncer::ObjectIdSet()); | 290 syncer::ObjectIdSet()); |
| 288 } | 291 } |
| 289 } | 292 } |
| 290 | 293 |
| 294 void SyncBackendHostImpl::SetPreferredNonBlockingTypes( | |
| 295 syncer::ModelTypeSet types) { | |
| 296 preferred_non_blocking_types_ = types; | |
| 297 UpdateRegisteredInvalidationTypes(); | |
| 298 } | |
| 299 | |
| 291 void SyncBackendHostImpl::ConfigureDataTypes( | 300 void SyncBackendHostImpl::ConfigureDataTypes( |
| 292 syncer::ConfigureReason reason, | 301 syncer::ConfigureReason reason, |
| 293 const DataTypeConfigStateMap& config_state_map, | 302 const DataTypeConfigStateMap& config_state_map, |
| 294 const base::Callback<void(syncer::ModelTypeSet, | 303 const base::Callback<void(syncer::ModelTypeSet, |
| 295 syncer::ModelTypeSet)>& ready_task, | 304 syncer::ModelTypeSet)>& ready_task, |
| 296 const base::Callback<void()>& retry_callback) { | 305 const base::Callback<void()>& retry_callback) { |
| 297 // Only one configure is allowed at a time. This is guaranteed by our | 306 // Only one configure is allowed at a time. This is guaranteed by our |
| 298 // callers. The SyncBackendHostImpl requests one configure as the backend is | 307 // callers. The SyncBackendHostImpl requests one configure as the backend is |
| 299 // initializing and waits for it to complete. After initialization, all | 308 // initializing and waits for it to complete. After initialization, all |
| 300 // configurations will pass through the DataTypeManager, which is careful to | 309 // configurations will pass through the DataTypeManager, which is careful to |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 } | 429 } |
| 421 | 430 |
| 422 void SyncBackendHostImpl::DeactivateDataType(syncer::ModelType type) { | 431 void SyncBackendHostImpl::DeactivateDataType(syncer::ModelType type) { |
| 423 registrar_->DeactivateDataType(type); | 432 registrar_->DeactivateDataType(type); |
| 424 } | 433 } |
| 425 | 434 |
| 426 syncer::UserShare* SyncBackendHostImpl::GetUserShare() const { | 435 syncer::UserShare* SyncBackendHostImpl::GetUserShare() const { |
| 427 return core_->sync_manager()->GetUserShare(); | 436 return core_->sync_manager()->GetUserShare(); |
| 428 } | 437 } |
| 429 | 438 |
| 439 syncer::SyncCoreProxy SyncBackendHostImpl::GetSyncCoreProxy() { | |
| 440 return *sync_core_proxy_.get(); | |
| 441 } | |
| 442 | |
| 430 SyncBackendHostImpl::Status SyncBackendHostImpl::GetDetailedStatus() { | 443 SyncBackendHostImpl::Status SyncBackendHostImpl::GetDetailedStatus() { |
| 431 DCHECK(initialized()); | 444 DCHECK(initialized()); |
| 432 return core_->sync_manager()->GetDetailedStatus(); | 445 return core_->sync_manager()->GetDetailedStatus(); |
| 433 } | 446 } |
| 434 | 447 |
| 435 syncer::sessions::SyncSessionSnapshot | 448 syncer::sessions::SyncSessionSnapshot |
| 436 SyncBackendHostImpl::GetLastSessionSnapshot() const { | 449 SyncBackendHostImpl::GetLastSessionSnapshot() const { |
| 437 return last_snapshot_; | 450 return last_snapshot_; |
| 438 } | 451 } |
| 439 | 452 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 530 |
| 518 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( | 531 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( |
| 519 const syncer::ModelTypeSet enabled_types, | 532 const syncer::ModelTypeSet enabled_types, |
| 520 const syncer::ModelTypeSet succeeded_configuration_types, | 533 const syncer::ModelTypeSet succeeded_configuration_types, |
| 521 const syncer::ModelTypeSet failed_configuration_types, | 534 const syncer::ModelTypeSet failed_configuration_types, |
| 522 const base::Callback<void(syncer::ModelTypeSet, | 535 const base::Callback<void(syncer::ModelTypeSet, |
| 523 syncer::ModelTypeSet)>& ready_task) { | 536 syncer::ModelTypeSet)>& ready_task) { |
| 524 if (!frontend_) | 537 if (!frontend_) |
| 525 return; | 538 return; |
| 526 | 539 |
| 527 invalidator_->UpdateRegisteredInvalidationIds( | 540 enabled_directory_types_ = enabled_types; |
| 528 this, | 541 UpdateRegisteredInvalidationTypes(); |
| 529 ModelTypeSetToObjectIdSet(enabled_types)); | |
| 530 | 542 |
| 531 if (!ready_task.is_null()) | 543 if (!ready_task.is_null()) |
| 532 ready_task.Run(succeeded_configuration_types, failed_configuration_types); | 544 ready_task.Run(succeeded_configuration_types, failed_configuration_types); |
| 533 } | 545 } |
| 534 | 546 |
| 547 void SyncBackendHostImpl::UpdateRegisteredInvalidationTypes() { | |
|
Nicolas Zea
2014/04/02 23:19:05
How about changing this to UpdateEnabledTypes(dire
rlarocque
2014/04/03 01:03:46
I don't understand this suggestion. We'd still ne
Nicolas Zea
2014/04/03 17:52:15
Yeah, I think I was still thinking of the set of e
| |
| 548 invalidator_->UpdateRegisteredInvalidationIds( | |
| 549 this, | |
| 550 ModelTypeSetToObjectIdSet( | |
| 551 Union(enabled_directory_types_, preferred_non_blocking_types_))); | |
| 552 } | |
| 553 | |
| 535 void SyncBackendHostImpl::Observe( | 554 void SyncBackendHostImpl::Observe( |
| 536 int type, | 555 int type, |
| 537 const content::NotificationSource& source, | 556 const content::NotificationSource& source, |
| 538 const content::NotificationDetails& details) { | 557 const content::NotificationDetails& details) { |
| 539 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 558 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 540 DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL); | 559 DCHECK_EQ(type, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL); |
| 541 | 560 |
| 542 content::Details<const syncer::ModelTypeSet> state_details(details); | 561 content::Details<const syncer::ModelTypeSet> state_details(details); |
| 543 const syncer::ModelTypeSet& types = *(state_details.ptr()); | 562 const syncer::ModelTypeSet& types = *(state_details.ptr()); |
| 544 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, | 563 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 556 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 575 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 557 if (!frontend_) | 576 if (!frontend_) |
| 558 return; | 577 return; |
| 559 | 578 |
| 560 frontend_->OnSyncConfigureRetry(); | 579 frontend_->OnSyncConfigureRetry(); |
| 561 } | 580 } |
| 562 | 581 |
| 563 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( | 582 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( |
| 564 const syncer::WeakHandle<syncer::JsBackend> js_backend, | 583 const syncer::WeakHandle<syncer::JsBackend> js_backend, |
| 565 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> | 584 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> |
| 566 debug_info_listener) { | 585 debug_info_listener, |
| 586 base::WeakPtr<syncer::SyncCore> sync_core) { | |
|
Nicolas Zea
2014/04/02 23:19:05
What do you think about creating the SyncCoreProxy
rlarocque
2014/04/03 01:03:46
I think that's a good idea. Done.
| |
| 567 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 587 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 568 if (!frontend_) | 588 if (!frontend_) |
| 569 return; | 589 return; |
| 570 | 590 |
| 571 initialized_ = true; | 591 initialized_ = true; |
| 572 | 592 |
| 593 sync_core_proxy_.reset( | |
| 594 new syncer::SyncCoreProxy( | |
| 595 registrar_->sync_thread()->message_loop_proxy(), | |
| 596 sync_core)); | |
| 597 | |
| 573 invalidator_->RegisterInvalidationHandler(this); | 598 invalidator_->RegisterInvalidationHandler(this); |
| 574 invalidation_handler_registered_ = true; | 599 invalidation_handler_registered_ = true; |
| 575 | 600 |
| 576 // Fake a state change to initialize the SyncManager's cached invalidator | 601 // Fake a state change to initialize the SyncManager's cached invalidator |
| 577 // state. | 602 // state. |
| 578 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); | 603 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); |
| 579 | 604 |
| 580 // Start forwarding refresh requests to the SyncManager | 605 // Start forwarding refresh requests to the SyncManager |
| 581 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 606 notification_registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 582 content::Source<Profile>(profile_)); | 607 content::Source<Profile>(profile_)); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 base::MessageLoop* SyncBackendHostImpl::GetSyncLoopForTesting() { | 789 base::MessageLoop* SyncBackendHostImpl::GetSyncLoopForTesting() { |
| 765 return registrar_->sync_thread()->message_loop(); | 790 return registrar_->sync_thread()->message_loop(); |
| 766 } | 791 } |
| 767 | 792 |
| 768 } // namespace browser_sync | 793 } // namespace browser_sync |
| 769 | 794 |
| 770 #undef SDVLOG | 795 #undef SDVLOG |
| 771 | 796 |
| 772 #undef SLOG | 797 #undef SLOG |
| 773 | 798 |
| OLD | NEW |