Chromium Code Reviews| Index: chrome/browser/sync/glue/sync_backend_host.cc |
| diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc |
| index b84227205c72ba96ed0edde8d1c1210dd2a0e025..ea3ce42dfe059858b63fe3598380a83830580ca9 100644 |
| --- a/chrome/browser/sync/glue/sync_backend_host.cc |
| +++ b/chrome/browser/sync/glue/sync_backend_host.cc |
| @@ -16,7 +16,6 @@ |
| #include "base/file_util.h" |
| #include "base/location.h" |
| #include "base/metrics/histogram.h" |
| -#include "base/threading/sequenced_worker_pool.h" |
| #include "base/threading/thread_restrictions.h" |
| #include "base/timer.h" |
| #include "base/tracked_objects.h" |
| @@ -28,6 +27,7 @@ |
| #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
| #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| +#include "chrome/browser/sync/glue/synced_device_tracker.h" |
| #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
| #include "chrome/browser/sync/sync_prefs.h" |
| #include "chrome/common/chrome_notification_types.h" |
| @@ -161,9 +161,12 @@ class SyncBackendHost::Core |
| // reencrypt everything. |
| void DoEnableEncryptEverything(); |
| - // Called to load sync encryption state and re-encrypt any types |
| - // needing encryption as necessary. |
| - void DoAssociateNigori(); |
| + // Called to perform tasks which require the control data to be downloaded. |
| + // This includes refreshing encryption, setting up the device info change |
| + // processor, etc. |
| + void DoInitialProcessMetadata(); |
| + |
| + void FinishInitialProcessMetadata(); |
| // The shutdown order is a bit complicated: |
| // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do |
| @@ -250,6 +253,9 @@ class SyncBackendHost::Core |
| // Our encryptor, which uses Chrome's encryption functions. |
| ChromeEncryptor encryptor_; |
| + // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
| + SyncedDeviceTracker synced_device_tracker_; |
| + |
| // The top-level syncapi entry point. Lives on the sync thread. |
| scoped_ptr<syncer::SyncManager> sync_manager_; |
| @@ -1100,7 +1106,6 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
| options.service_url.host() + options.service_url.path(), |
| options.service_url.EffectiveIntPort(), |
| options.service_url.SchemeIsSecure(), |
| - BrowserThread::GetBlockingPool(), |
| options.make_http_bridge_factory_fn.Run().Pass(), |
| options.workers, |
| options.extensions_activity_monitor, |
| @@ -1163,14 +1168,6 @@ void SyncBackendHost::Core::DoStartSyncing( |
| sync_manager_->StartSyncingNormally(routing_info); |
| } |
| -void SyncBackendHost::Core::DoAssociateNigori() { |
| - DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - sync_manager_->GetEncryptionHandler()->Init(); |
| - host_.Call(FROM_HERE, |
| - &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
| - true); |
| -} |
| - |
| void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| const std::string& passphrase, |
| bool is_explicit) { |
| @@ -1179,6 +1176,33 @@ void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| passphrase, is_explicit); |
| } |
| +void SyncBackendHost::Core::DoInitialProcessMetadata() { |
| + DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| + |
| + // Initialize encryption. |
| + sync_manager_->GetEncryptionHandler()->Init(); |
| + |
| + // Initialize device info. |
| + if (sync_manager_->GetUserShare()) { // NULL in some tests. |
|
rlarocque
2012/09/08 01:20:44
FakeSyncManager::GetUserShare() returns NULL.
It'
|
| + registrar_->ActivateDataType(syncer::DEVICE_INFO, |
| + syncer::GROUP_PASSIVE, |
| + &synced_device_tracker_, |
| + sync_manager_->GetUserShare()); |
| + synced_device_tracker_.InitLocalDeviceInfo( |
| + base::Bind(&SyncBackendHost::Core::FinishInitialProcessMetadata, |
| + this)); |
| + } else { |
| + FinishInitialProcessMetadata(); |
| + } |
| +} |
| + |
| +void SyncBackendHost::Core::FinishInitialProcessMetadata() { |
| + host_.Call( |
| + FROM_HERE, |
| + &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
| + true); |
| +} |
| + |
| void SyncBackendHost::Core::DoSetDecryptionPassphrase( |
| const std::string& passphrase) { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| @@ -1204,6 +1228,9 @@ void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| DoDestroySyncManager(); |
| + // It's safe to do this even if the type was never activated. |
| + registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
| + |
| chrome_sync_notification_bridge_ = NULL; |
| registrar_ = NULL; |
| @@ -1345,7 +1372,7 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( |
| // trigger migration. That would be disastrous, so we must rely on the |
| // sync manager to ensure that this type never has both progress markers |
| // and !initial_sync_ended. |
| - initialization_state_ = DOWNLOADING_NIGORI; |
| + initialization_state_ = DOWNLOADING_METADATA; |
| ConfigureDataTypes( |
| syncer::CONFIGURE_REASON_NEW_CLIENT, |
| syncer::ModelTypeSet(syncer::ControlTypes()), |
| @@ -1358,16 +1385,17 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( |
| base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
| weak_ptr_factory_.GetWeakPtr())); |
| break; |
| - case DOWNLOADING_NIGORI: |
| - initialization_state_ = ASSOCIATING_NIGORI; |
| - // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() |
| - // if necessary. |
| - sync_thread_.message_loop()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&SyncBackendHost::Core::DoAssociateNigori, |
| - core_.get())); |
| + case DOWNLOADING_METADATA: |
| + initialization_state_ = PROCESSING_METADATA; |
| + // Updates encryption and other metadata. Will call |
| + // OnEncryptedTypesChanged() and OnEncryptionComplete() if necessary. |
| + InitialProcessMetadata( |
| + base::Bind( |
| + &SyncBackendHost:: |
| + HandleInitializationCompletedOnFrontendLoop, |
| + weak_ptr_factory_.GetWeakPtr(), true)); |
| break; |
| - case ASSOCIATING_NIGORI: |
| + case PROCESSING_METADATA: |
| initialization_state_ = INITIALIZED; |
| // Now that we've downloaded the nigori node, we can see if there are any |
| // experimental types to enable. This should be done before we inform |
| @@ -1549,6 +1577,16 @@ void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( |
| failed_configuration_types.Empty()); |
| } |
| +void SyncBackendHost::InitialProcessMetadata( |
| + const base::Closure& done_callback) { |
| + DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| + // Then forward the request to the sync thread. |
| + sync_thread_.message_loop()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&SyncBackendHost::Core::DoInitialProcessMetadata, |
| + core_.get())); |
| +} |
| + |
| #undef SDVLOG |
| #undef SLOG |