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 8341618d4c340ff17586de4d889116aff696ee8d..5b72bbca1b5ad1021b4d162aa52c6d2711710912 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" |
@@ -29,6 +28,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_; |
Nicolas Zea
2012/09/14 19:15:08
There should probably be tests/changes in sync_bac
rlarocque
2012/09/15 01:36:37
Unfortunately, we can't test it there. Those unit
Nicolas Zea
2012/09/17 17:54:00
How about passing in the sync guid when you initia
rlarocque
2012/09/19 21:37:58
Fixed by adding an accessor to the cache_guid to U
|
+ |
// The top-level syncapi entry point. Lives on the sync thread. |
scoped_ptr<syncer::SyncManager> sync_manager_; |
@@ -1101,7 +1107,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, |
@@ -1165,14 +1170,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) { |
@@ -1181,6 +1178,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. |
+ registrar_->ActivateDataType(syncer::DEVICE_INFO, |
+ syncer::GROUP_PASSIVE, |
+ &synced_device_tracker_, |
+ sync_manager_->GetUserShare()); |
+ synced_device_tracker_.InitLocalDeviceInfo( |
Nicolas Zea
2012/09/14 19:15:08
indent
rlarocque
2012/09/15 01:36:37
Done.
|
+ 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_); |
@@ -1206,6 +1230,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; |
@@ -1347,7 +1374,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()), |
@@ -1360,16 +1387,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 |
@@ -1544,6 +1572,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 |