diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 00:47:19 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 00:47:19 +0000 |
commit | 18af9a22ada195c0ffc524fd4ab12b54e61e7663 (patch) | |
tree | b0806976a7bf941fb9162a65988ecb3cc4aab2c3 /chrome/browser/sync/glue/sync_backend_host.cc | |
parent | 93c1c66878c5f8fc76a4bd095ecbf537c2ed01e8 (diff) | |
download | chromium_src-18af9a22ada195c0ffc524fd4ab12b54e61e7663.zip chromium_src-18af9a22ada195c0ffc524fd4ab12b54e61e7663.tar.gz chromium_src-18af9a22ada195c0ffc524fd4ab12b54e61e7663.tar.bz2 |
sync: Fix backend configuration to support sync db refresh.
Removes the has_new bit in favor of checking if initial_sync_ended for requested types, and recreates the sync db on corruption (as we used to). These together mean we refresh the sync db on corruption. Also added some defensive dchecks.
To test this, I ripped out the test-only #ifdefs in SyncBackendHost so the tests use the real Initialize code path, and added a toolbox of stuff to control when we set initial sync ended bits during testing.
BUG=50965
TEST=DirectoryBackingStoreTest, ProfileSyncService* tests.
Review URL: http://codereview.chromium.org/3099001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55644 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/glue/sync_backend_host.cc')
-rwxr-xr-x[-rw-r--r--] | chrome/browser/sync/glue/sync_backend_host.cc | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index c81223b..40782ec 100644..100755 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -50,7 +50,8 @@ SyncBackendHost::SyncBackendHost( frontend_(frontend), sync_data_folder_path_(profile_path.Append(kSyncDataFolderName)), data_type_controllers_(data_type_controllers), - last_auth_error_(AuthError::None()) { + last_auth_error_(AuthError::None()), + syncapi_initialized_(false) { core_ = new Core(this); } @@ -60,7 +61,8 @@ SyncBackendHost::SyncBackendHost() frontend_loop_(MessageLoop::current()), profile_(NULL), frontend_(NULL), - last_auth_error_(AuthError::None()) { + last_auth_error_(AuthError::None()), + syncapi_initialized_(false) { } SyncBackendHost::~SyncBackendHost() { @@ -106,19 +108,28 @@ void SyncBackendHost::Initialize( registrar_.routing_info[(*it)] = GROUP_PASSIVE; } + InitCore(Core::DoInitializeOptions( + sync_service_url, lsid.empty(), + MakeHttpBridgeFactory(baseline_context_getter), + MakeHttpBridgeFactory(baseline_context_getter), + lsid, + delete_sync_data_folder, + invalidate_sync_login, + invalidate_sync_xmpp_login, + use_chrome_async_socket, + try_ssltcp_first, + notification_method)); +} + +sync_api::HttpPostProviderFactory* SyncBackendHost::MakeHttpBridgeFactory( + URLRequestContextGetter* getter) { + return new HttpBridgeFactory(getter); +} + +void SyncBackendHost::InitCore(const Core::DoInitializeOptions& options) { core_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoInitialize, - Core::DoInitializeOptions( - sync_service_url, lsid.empty(), - new HttpBridgeFactory(baseline_context_getter), - new HttpBridgeFactory(baseline_context_getter), - lsid, - delete_sync_data_folder, - invalidate_sync_login, - invalidate_sync_xmpp_login, - use_chrome_async_socket, - try_ssltcp_first, - notification_method))); + options)); } void SyncBackendHost::Authenticate(const std::string& username, @@ -190,30 +201,31 @@ void SyncBackendHost::ConfigureDataTypes(const syncable::ModelTypeSet& types, CancelableTask* ready_task) { // Only one configure is allowed at a time. DCHECK(!configure_ready_task_.get()); - AutoLock lock(registrar_lock_); - bool has_new = false; - - for (DataTypeController::TypeMap::const_iterator it = - data_type_controllers_.begin(); - it != data_type_controllers_.end(); ++it) { - syncable::ModelType type = (*it).first; - - // If a type is not specified, remove it from the routing_info. - if (types.count(type) == 0) { - registrar_.routing_info.erase(type); - } else { - // Add a newly specified data type as GROUP_PASSIVE into the - // routing_info, if it does not already exist. - if (registrar_.routing_info.count(type) == 0) { - registrar_.routing_info[type] = GROUP_PASSIVE; - has_new = true; + DCHECK(syncapi_initialized_); + + { + AutoLock lock(registrar_lock_); + for (DataTypeController::TypeMap::const_iterator it = + data_type_controllers_.begin(); + it != data_type_controllers_.end(); ++it) { + syncable::ModelType type = (*it).first; + + // If a type is not specified, remove it from the routing_info. + if (types.count(type) == 0) { + registrar_.routing_info.erase(type); + } else { + // Add a newly specified data type as GROUP_PASSIVE into the + // routing_info, if it does not already exist. + if (registrar_.routing_info.count(type) == 0) { + registrar_.routing_info[type] = GROUP_PASSIVE; + } } } } // If no new data types were added to the passive group, no need to // wait for the syncer. - if (!has_new) { + if (core_->syncapi()->InitialSyncEndedForAllEnabledTypes()) { ready_task->Run(); delete ready_task; return; @@ -221,7 +233,7 @@ void SyncBackendHost::ConfigureDataTypes(const syncable::ModelTypeSet& types, // Save the task here so we can run it when the syncer finishes // initializing the new data types. It will be run only when the - // set of initially sycned data types matches the types requested in + // set of initially synced data types matches the types requested in // this configure. configure_ready_task_.reset(ready_task); configure_initial_sync_types_ = types; @@ -231,6 +243,10 @@ void SyncBackendHost::ConfigureDataTypes(const syncable::ModelTypeSet& types, // downloading updates for newly added data types. Once this is // complete, the configure_ready_task_ is run via an // OnInitializationComplete notification. + RequestNudge(); +} + +void SyncBackendHost::RequestNudge() { core_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoRequestNudge)); } @@ -308,18 +324,22 @@ void SyncBackendHost::Core::NotifyPassphraseAccepted() { } SyncBackendHost::UserShareHandle SyncBackendHost::GetUserShareHandle() const { + DCHECK(syncapi_initialized_); return core_->syncapi()->GetUserShare(); } SyncBackendHost::Status SyncBackendHost::GetDetailedStatus() { + DCHECK(syncapi_initialized_); return core_->syncapi()->GetDetailedStatus(); } SyncBackendHost::StatusSummary SyncBackendHost::GetStatusSummary() { + DCHECK(syncapi_initialized_); return core_->syncapi()->GetStatusSummary(); } string16 SyncBackendHost::GetAuthenticatedUsername() const { + DCHECK(syncapi_initialized_); return UTF8ToUTF16(core_->syncapi()->GetAuthenticatedUsername()); } @@ -347,6 +367,7 @@ void SyncBackendHost::GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { } bool SyncBackendHost::HasUnsyncedItems() const { + DCHECK(syncapi_initialized_); return core_->syncapi()->HasUnsyncedItems(); } @@ -559,6 +580,7 @@ void SyncBackendHost::Core::HandleInitalizationCompletedOnFrontendLoop() { void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop() { if (!frontend_) return; + syncapi_initialized_ = true; frontend_->OnBackendInitialized(); } |