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..eb29d1a9185ed630a258515417dd9356f5d7838e 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,8 @@ |
#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/glue/device_info.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 +162,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 DoInitialProcessControlTypes(); |
+ |
+ void FinishInitialProcessControlTypes(); |
// The shutdown order is a bit complicated: |
// 1) From |sync_thread_|, invoke the syncapi Shutdown call to do |
@@ -198,6 +202,10 @@ class SyncBackendHost::Core |
syncer::SyncManager* sync_manager() { return sync_manager_.get(); } |
+ SyncedDeviceTracker* synced_device_tracker() { |
+ return &synced_device_tracker_; |
+ } |
+ |
// Delete the sync data folder to cleanup backend data. Happens the first |
// time sync is enabled for a user (to prevent accidentally reusing old |
// sync databases), as well as shutdown when you're no longer syncing. |
@@ -250,6 +258,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_; |
@@ -356,42 +367,11 @@ SyncBackendHost::~SyncBackendHost() { |
namespace { |
-// Helper to construct a user agent string (ASCII) suitable for use by |
-// the syncapi for any HTTP communication. This string is used by the sync |
-// backend for classifying client types when calculating statistics. |
-std::string MakeUserAgentForSyncApi() { |
- std::string user_agent; |
- user_agent = "Chrome "; |
-#if defined(OS_WIN) |
- user_agent += "WIN "; |
-#elif defined(OS_CHROMEOS) |
- user_agent += "CROS "; |
-#elif defined(OS_LINUX) |
- user_agent += "LINUX "; |
-#elif defined(OS_FREEBSD) |
- user_agent += "FREEBSD "; |
-#elif defined(OS_OPENBSD) |
- user_agent += "OPENBSD "; |
-#elif defined(OS_MACOSX) |
- user_agent += "MAC "; |
-#endif |
- chrome::VersionInfo version_info; |
- if (!version_info.is_valid()) { |
- DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; |
- return user_agent; |
- } |
- |
- user_agent += version_info.Version(); |
- user_agent += " (" + version_info.LastChange() + ")"; |
- if (!version_info.IsOfficialBuild()) |
- user_agent += "-devel"; |
- return user_agent; |
-} |
- |
scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( |
const scoped_refptr<net::URLRequestContextGetter>& getter) { |
return scoped_ptr<syncer::HttpPostProviderFactory>( |
- new syncer::HttpBridgeFactory(getter, MakeUserAgentForSyncApi())); |
+ new syncer::HttpBridgeFactory( |
+ getter, DeviceInfo::MakeUserAgentForSyncApi())); |
} |
} // namespace |
@@ -789,6 +769,10 @@ void SyncBackendHost::GetModelSafeRoutingInfo( |
} |
} |
+SyncedDeviceTracker* SyncBackendHost::GetSyncedDeviceTrackerForTest() { |
+ return core_->synced_device_tracker(); |
+} |
+ |
void SyncBackendHost::InitCore(const DoInitializeOptions& options) { |
sync_thread_.message_loop()->PostTask(FROM_HERE, |
base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); |
@@ -1101,7 +1085,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 +1148,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 +1156,33 @@ void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
passphrase, is_explicit); |
} |
+void SyncBackendHost::Core::DoInitialProcessControlTypes() { |
+ 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( |
+ base::Bind(&SyncBackendHost::Core::FinishInitialProcessControlTypes, |
+ this)); |
+ } else { |
+ FinishInitialProcessControlTypes(); |
+ } |
+} |
+ |
+void SyncBackendHost::Core::FinishInitialProcessControlTypes() { |
+ host_.Call( |
+ FROM_HERE, |
+ &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
+ true); |
+} |
+ |
void SyncBackendHost::Core::DoSetDecryptionPassphrase( |
const std::string& passphrase) { |
DCHECK_EQ(MessageLoop::current(), sync_loop_); |
@@ -1206,6 +1208,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 +1352,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_CONTROL_TYPES; |
ConfigureDataTypes( |
syncer::CONFIGURE_REASON_NEW_CLIENT, |
syncer::ModelTypeSet(syncer::ControlTypes()), |
@@ -1360,16 +1365,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_CONTROL_TYPES: |
+ initialization_state_ = PROCESSING_CONTROL_TYPES; |
+ // Updates encryption and other metadata. Will call |
+ // OnEncryptedTypesChanged() and OnEncryptionComplete() if necessary. |
+ InitialProcessControlTypes( |
+ base::Bind( |
+ &SyncBackendHost:: |
+ HandleInitializationCompletedOnFrontendLoop, |
+ weak_ptr_factory_.GetWeakPtr(), true)); |
break; |
- case ASSOCIATING_NIGORI: |
+ case PROCESSING_CONTROL_TYPES: |
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 +1550,16 @@ void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( |
failed_configuration_types.Empty()); |
} |
+void SyncBackendHost::InitialProcessControlTypes( |
+ 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::DoInitialProcessControlTypes, |
+ core_.get())); |
+} |
+ |
#undef SDVLOG |
#undef SLOG |