Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Unified Diff: sync/internal_api/sync_manager.cc

Issue 10483015: [Sync] Refactor sync configuration logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments + rebase Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/internal_api/sync_manager.cc
diff --git a/sync/internal_api/sync_manager.cc b/sync/internal_api/sync_manager.cc
index 8a2ff7053ad17039685c30f6bf90a8f99380ae19..0cee7268ea23a9d1009135afd5986776d0f107c9 100644
--- a/sync/internal_api/sync_manager.cc
+++ b/sync/internal_api/sync_manager.cc
@@ -59,6 +59,7 @@
using base::TimeDelta;
using browser_sync::AllStatus;
+using browser_sync::ConfigurationParams;
using browser_sync::Cryptographer;
using browser_sync::Encryptor;
using browser_sync::JsArgList;
@@ -816,46 +817,50 @@ bool SyncManager::IsUsingExplicitPassphrase() {
return data_ && data_->IsUsingExplicitPassphrase();
}
-void SyncManager::RequestCleanupDisabledTypes(
- const browser_sync::ModelSafeRoutingInfo& routing_info) {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (data_->scheduler()) {
- data_->session_context()->set_routing_info(routing_info);
- data_->scheduler()->CleanupDisabledTypes();
- }
-}
-
void SyncManager::RequestClearServerData() {
DCHECK(thread_checker_.CalledOnValidThread());
if (data_->scheduler())
data_->scheduler()->ClearUserData();
}
-void SyncManager::RequestConfig(
- const browser_sync::ModelSafeRoutingInfo& routing_info,
- const ModelTypeSet& types, ConfigureReason reason) {
+void SyncManager::ConfigureSyncer(
+ ConfigureReason reason,
+ const syncable::ModelTypeSet& types_to_config,
+ const browser_sync::ModelSafeRoutingInfo& new_routing_info,
+ const base::Closure& ready_task,
+ const base::Closure& retry_task) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (!data_->scheduler()) {
- LOG(INFO)
- << "SyncManager::RequestConfig: bailing out because scheduler is "
- << "null";
- return;
- }
- StartConfigurationMode(base::Closure());
- data_->session_context()->set_routing_info(routing_info);
- data_->scheduler()->ScheduleConfiguration(types, GetSourceFromReason(reason));
+ DCHECK(!ready_task.is_null());
+ DCHECK(!retry_task.is_null());
+
+ // TODO(zea): set this based on whether cryptographer has keystore
+ // encryption key or not (requires opening a transaction). crbug.com/129665.
+ ConfigurationParams::KeystoreKeyStatus keystore_key_status =
+ ConfigurationParams::KEYSTORE_KEY_UNNECESSARY;
+
+ ConfigurationParams params(GetSourceFromReason(reason),
+ types_to_config,
+ new_routing_info,
+ keystore_key_status,
+ ready_task);
+
+ // Returns false if a retry has been scheduled. Either way, will invoke the
+ // ready task when the configure job completes.
+ if (!DoConfigureSyncer(params))
+ retry_task.Run();
}
-void SyncManager::StartConfigurationMode(const base::Closure& callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+bool SyncManager::DoConfigureSyncer(const ConfigurationParams& params) {
if (!data_->scheduler()) {
LOG(INFO)
- << "SyncManager::StartConfigurationMode: could not start "
- << "configuration mode because because scheduler is null";
- return;
+ << "SyncManager::DoConfigureSyncer: could not configure because "
+ << "scheduler is null";
+ params.ready_task.Run();
+ return true;
}
- data_->scheduler()->Start(
- browser_sync::SyncScheduler::CONFIGURATION_MODE, callback);
+
+ data_->scheduler()->Start(SyncScheduler::CONFIGURATION_MODE);
+ return data_->scheduler()->ScheduleConfiguration(params);
}
bool SyncManager::SyncInternal::Init(
@@ -941,8 +946,7 @@ bool SyncManager::SyncInternal::Init(
if (signed_in) {
if (scheduler()) {
- scheduler()->Start(
- browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure());
+ scheduler()->Start(SyncScheduler::CONFIGURATION_MODE);
}
initialized_ = true;
@@ -1116,9 +1120,13 @@ void SyncManager::SyncInternal::NotifyCryptographerState(
void SyncManager::SyncInternal::StartSyncingNormally(
const browser_sync::ModelSafeRoutingInfo& routing_info) {
// Start the sync scheduler.
- if (scheduler()) { // NULL during certain unittests.
+ if (scheduler()) { // NULL during certain unittests.
+ // TODO(sync): We always want the newest set of routes when we switch back
+ // to normal mode. Figure out how to enforce set_routing_info is always
+ // appropriately set and that it's only modified when switching to normal
+ // mode.
session_context()->set_routing_info(routing_info);
- scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure());
+ scheduler()->Start(SyncScheduler::NORMAL_MODE);
}
}

Powered by Google App Engine
This is Rietveld 408576698