Index: sync/internal_api/sync_manager.cc |
diff --git a/sync/internal_api/sync_manager.cc b/sync/internal_api/sync_manager.cc |
index c8a293ea85f3ffc7e861d42891072d6535ca265d..d1b721fed6eb5e21239df78cd01bbabc7f7bcfc1 100644 |
--- a/sync/internal_api/sync_manager.cc |
+++ b/sync/internal_api/sync_manager.cc |
@@ -32,6 +32,7 @@ |
#include "sync/internal_api/public/base_node.h" |
#include "sync/internal_api/public/configure_reason.h" |
#include "sync/internal_api/public/engine/polling_constants.h" |
+#include "sync/internal_api/public/http_post_provider_factory.h" |
#include "sync/internal_api/public/read_node.h" |
#include "sync/internal_api/public/read_transaction.h" |
#include "sync/internal_api/public/user_share.h" |
@@ -176,14 +177,14 @@ class SyncManager::SyncInternal |
int port, |
bool use_ssl, |
const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
- HttpPostProviderFactory* post_factory, |
+ scoped_ptr<HttpPostProviderFactory> post_factory, |
const syncer::ModelSafeRoutingInfo& model_safe_routing_info, |
const std::vector<syncer::ModelSafeWorker*>& workers, |
syncer::ExtensionsActivityMonitor* |
extensions_activity_monitor, |
ChangeDelegate* change_delegate, |
const SyncCredentials& credentials, |
- syncer::SyncNotifier* sync_notifier, |
+ scoped_ptr<syncer::SyncNotifier> sync_notifier, |
const std::string& restored_key_for_bootstrapping, |
TestingMode testing_mode, |
Encryptor* encryptor, |
@@ -376,6 +377,8 @@ class SyncManager::SyncInternal |
const std::string& name, const JsArgList& args, |
const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE; |
+ void SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler); |
+ |
private: |
struct NotificationInfo { |
int total_count; |
@@ -692,20 +695,20 @@ bool SyncManager::Init( |
int sync_server_port, |
bool use_ssl, |
const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
- HttpPostProviderFactory* post_factory, |
+ scoped_ptr<HttpPostProviderFactory> post_factory, |
const syncer::ModelSafeRoutingInfo& model_safe_routing_info, |
const std::vector<syncer::ModelSafeWorker*>& workers, |
syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
ChangeDelegate* change_delegate, |
const SyncCredentials& credentials, |
- syncer::SyncNotifier* sync_notifier, |
+ scoped_ptr<syncer::SyncNotifier> sync_notifier, |
const std::string& restored_key_for_bootstrapping, |
TestingMode testing_mode, |
Encryptor* encryptor, |
UnrecoverableErrorHandler* unrecoverable_error_handler, |
ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- DCHECK(post_factory); |
+ DCHECK(post_factory.get()); |
DVLOG(1) << "SyncManager starting Init..."; |
std::string server_string(sync_server_and_path); |
return data_->Init(database_location, |
@@ -714,13 +717,13 @@ bool SyncManager::Init( |
sync_server_port, |
use_ssl, |
blocking_task_runner, |
- post_factory, |
+ post_factory.Pass(), |
model_safe_routing_info, |
workers, |
extensions_activity_monitor, |
change_delegate, |
credentials, |
- sync_notifier, |
+ sync_notifier.Pass(), |
restored_key_for_bootstrapping, |
testing_mode, |
encryptor, |
@@ -749,6 +752,21 @@ syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() { |
return data_->InitialSyncEndedTypes(); |
} |
+syncer::ModelTypeSet SyncManager::GetTypesWithEmptyProgressMarkerToken( |
+ syncer::ModelTypeSet types) { |
+ syncer::ModelTypeSet result; |
+ for (syncer::ModelTypeSet::Iterator i = types.First(); |
+ i.Good(); i.Inc()) { |
+ sync_pb::DataTypeProgressMarker marker; |
+ GetUserShare()->directory->GetDownloadProgress(i.Get(), &marker); |
+ |
+ if (marker.token().empty()) |
+ result.Put(i.Get()); |
+ |
+ } |
+ return result; |
+} |
+ |
void SyncManager::StartSyncingNormally( |
const syncer::ModelSafeRoutingInfo& routing_info) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -793,40 +811,39 @@ bool SyncManager::IsUsingExplicitPassphrase() { |
return data_ && data_->IsUsingExplicitPassphrase(); |
} |
-void SyncManager::RequestCleanupDisabledTypes( |
- const syncer::ModelSafeRoutingInfo& routing_info) { |
+void SyncManager::ConfigureSyncer( |
+ ConfigureReason reason, |
+ const syncer::ModelTypeSet& types_to_config, |
+ const syncer::ModelSafeRoutingInfo& new_routing_info, |
+ const base::Closure& ready_task, |
+ const base::Closure& retry_task) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- if (data_->scheduler()) { |
- data_->session_context()->set_routing_info(routing_info); |
- data_->scheduler()->CleanupDisabledTypes(); |
- } |
-} |
+ DCHECK(!ready_task.is_null()); |
+ DCHECK(!retry_task.is_null()); |
-void SyncManager::RequestConfig( |
- const syncer::ModelSafeRoutingInfo& routing_info, |
- const ModelTypeSet& types, ConfigureReason reason) { |
- 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)); |
-} |
+ // 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); |
-void SyncManager::StartConfigurationMode(const base::Closure& callback) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
if (!data_->scheduler()) { |
LOG(INFO) |
- << "SyncManager::StartConfigurationMode: could not start " |
- << "configuration mode because because scheduler is null"; |
+ << "SyncManager::ConfigureSyncer: could not configure because " |
+ << "scheduler is null"; |
+ params.ready_task.Run(); |
return; |
} |
- data_->scheduler()->Start( |
- syncer::SyncScheduler::CONFIGURATION_MODE, callback); |
+ |
+ data_->scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); |
+ if (!data_->scheduler()->ScheduleConfiguration(params)) |
+ retry_task.Run(); |
+ |
} |
bool SyncManager::SyncInternal::Init( |
@@ -836,13 +853,13 @@ bool SyncManager::SyncInternal::Init( |
int port, |
bool use_ssl, |
const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
- HttpPostProviderFactory* post_factory, |
+ scoped_ptr<HttpPostProviderFactory> post_factory, |
const syncer::ModelSafeRoutingInfo& model_safe_routing_info, |
const std::vector<syncer::ModelSafeWorker*>& workers, |
syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
ChangeDelegate* change_delegate, |
const SyncCredentials& credentials, |
- syncer::SyncNotifier* sync_notifier, |
+ scoped_ptr<syncer::SyncNotifier> sync_notifier, |
const std::string& restored_key_for_bootstrapping, |
TestingMode testing_mode, |
Encryptor* encryptor, |
@@ -861,7 +878,7 @@ bool SyncManager::SyncInternal::Init( |
change_delegate_ = change_delegate; |
testing_mode_ = testing_mode; |
- sync_notifier_.reset(sync_notifier); |
+ sync_notifier_ = sync_notifier.Pass(); |
AddObserver(&js_sync_manager_observer_); |
SetJsEventHandler(event_handler); |
@@ -895,7 +912,7 @@ bool SyncManager::SyncInternal::Init( |
backing_store)); |
connection_manager_.reset(new SyncAPIServerConnectionManager( |
- sync_server_and_path, port, use_ssl, post_factory)); |
+ sync_server_and_path, port, use_ssl, post_factory.release())); |
net::NetworkChangeNotifier::AddIPAddressObserver(this); |
observing_ip_address_changes_ = true; |
@@ -927,8 +944,7 @@ bool SyncManager::SyncInternal::Init( |
if (signed_in) { |
if (scheduler()) { |
- scheduler()->Start( |
- syncer::SyncScheduler::CONFIGURATION_MODE, base::Closure()); |
+ scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); |
} |
initialized_ = true; |
@@ -1102,9 +1118,13 @@ void SyncManager::SyncInternal::NotifyCryptographerState( |
void SyncManager::SyncInternal::StartSyncingNormally( |
const syncer::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); |
} |
} |
@@ -2340,6 +2360,11 @@ void SyncManager::SyncInternal::RemoveObserver( |
observers_.RemoveObserver(observer); |
} |
+void SyncManager::SyncInternal::SetSyncSchedulerForTest( |
+ scoped_ptr<SyncScheduler> sync_scheduler) { |
+ scheduler_ = sync_scheduler.Pass(); |
+} |
+ |
SyncStatus SyncManager::GetDetailedStatus() const { |
return data_->GetStatus(); |
} |
@@ -2370,6 +2395,10 @@ TimeDelta SyncManager::GetNudgeDelayTimeDelta( |
return data_->GetNudgeDelayTimeDelta(model_type); |
} |
+void SyncManager::SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler) { |
+ data_->SetSyncSchedulerForTest(scheduler.Pass()); |
+} |
+ |
syncer::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { |
ReadTransaction trans(FROM_HERE, GetUserShare()); |
return GetEncryptedTypes(&trans); |
@@ -2459,20 +2488,4 @@ bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, |
return true; |
} |
-syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( |
- syncer::ModelTypeSet types, |
- syncer::UserShare* share) { |
- syncer::ModelTypeSet result; |
- for (syncer::ModelTypeSet::Iterator i = types.First(); |
- i.Good(); i.Inc()) { |
- sync_pb::DataTypeProgressMarker marker; |
- share->directory->GetDownloadProgress(i.Get(), &marker); |
- |
- if (marker.token().empty()) |
- result.Put(i.Get()); |
- |
- } |
- return result; |
-} |
- |
} // namespace syncer |