Refactor SyncManager::Init to receive args via a struct.

SyncManager::Init is implemented in several places, takes a whole lot of
args, and in the near future is going to get a few more.

In some cases, many of the args are optional and it is tedious to pass a
bunch of NULLs or empty strings.  Use a struct instead of an arg list.

BUG=

Review URL: https://codereview.chromium.org/451743002

Cr-Commit-Position: refs/heads/master@{#288280}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288280 0039d316-1c4b-4281-b951-d872f2087c98
parent 19c64579
...@@ -430,22 +430,29 @@ void SyncBackendHostCore::DoInitialize( ...@@ -430,22 +430,29 @@ void SyncBackendHostCore::DoInitialize(
sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_); sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_);
sync_manager_->AddObserver(this); sync_manager_->AddObserver(this);
sync_manager_->Init(sync_data_folder_path_,
options->event_handler, syncer::SyncManager::InitArgs args;
options->service_url, args.database_location = sync_data_folder_path_;
options->http_bridge_factory.Pass(), args.event_handler = options->event_handler;
options->workers, args.service_url = options->service_url;
options->extensions_activity, args.post_factory = options->http_bridge_factory.Pass();
options->registrar /* as SyncManager::ChangeDelegate */, args.workers = options->workers;
options->credentials, args.extensions_activity = options->extensions_activity;
options->invalidator_client_id, args.change_delegate = options->registrar; // as SyncManager::ChangeDelegate
options->restored_key_for_bootstrapping, args.credentials = options->credentials;
options->restored_keystore_key_for_bootstrapping, args.invalidator_client_id = options->invalidator_client_id;
options->internal_components_factory.get(), args.restored_key_for_bootstrapping = options->restored_key_for_bootstrapping;
&encryptor_, args.restored_keystore_key_for_bootstrapping =
options->unrecoverable_error_handler.Pass(), options->restored_keystore_key_for_bootstrapping;
options->report_unrecoverable_error_function, args.internal_components_factory =
&stop_syncing_signal_); options->internal_components_factory.Pass();
args.encryptor = &encryptor_;
args.unrecoverable_error_handler =
options->unrecoverable_error_handler.Pass();
args.report_unrecoverable_error_function =
options->report_unrecoverable_error_function;
args.cancelation_signal = &stop_syncing_signal_;
sync_manager_->Init(&args);
} }
void SyncBackendHostCore::DoUpdateCredentials( void SyncBackendHostCore::DoUpdateCredentials(
......
...@@ -16,6 +16,15 @@ SyncManager::ChangeObserver::~ChangeObserver() {} ...@@ -16,6 +16,15 @@ SyncManager::ChangeObserver::~ChangeObserver() {}
SyncManager::Observer::~Observer() {} SyncManager::Observer::~Observer() {}
SyncManager::InitArgs::InitArgs()
: extensions_activity(NULL),
change_delegate(NULL),
encryptor(NULL),
cancelation_signal(NULL) {
}
SyncManager::InitArgs::~InitArgs() {}
SyncManager::SyncManager() {} SyncManager::SyncManager() {}
SyncManager::~SyncManager() {} SyncManager::~SyncManager() {}
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "sync/internal_api/public/engine/model_safe_worker.h" #include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/engine/sync_status.h" #include "sync/internal_api/public/engine/sync_status.h"
#include "sync/internal_api/public/events/protocol_event.h" #include "sync/internal_api/public/events/protocol_event.h"
#include "sync/internal_api/public/http_post_provider_factory.h"
#include "sync/internal_api/public/internal_components_factory.h"
#include "sync/internal_api/public/shutdown_reason.h" #include "sync/internal_api/public/shutdown_reason.h"
#include "sync/internal_api/public/sync_context_proxy.h" #include "sync/internal_api/public/sync_context_proxy.h"
#include "sync/internal_api/public/sync_encryption_handler.h" #include "sync/internal_api/public/sync_encryption_handler.h"
...@@ -46,7 +48,6 @@ class CancelationSignal; ...@@ -46,7 +48,6 @@ class CancelationSignal;
class DataTypeDebugInfoListener; class DataTypeDebugInfoListener;
class Encryptor; class Encryptor;
class ExtensionsActivity; class ExtensionsActivity;
class HttpPostProviderFactory;
class InternalComponentsFactory; class InternalComponentsFactory;
class JsBackend; class JsBackend;
class JsEventHandler; class JsEventHandler;
...@@ -220,52 +221,65 @@ class SYNC_EXPORT SyncManager { ...@@ -220,52 +221,65 @@ class SYNC_EXPORT SyncManager {
virtual ~Observer(); virtual ~Observer();
}; };
// Arguments for initializing SyncManager.
struct SYNC_EXPORT InitArgs {
InitArgs();
~InitArgs();
// Path in which to create or open sync's sqlite database (aka the
// directory).
base::FilePath database_location;
// Used to propagate events to chrome://sync-internals. Optional.
WeakHandle<JsEventHandler> event_handler;
// URL of the sync server.
GURL service_url;
// Used to communicate with the sync server.
scoped_ptr<HttpPostProviderFactory> post_factory;
std::vector<scoped_refptr<ModelSafeWorker> > workers;
// Must outlive SyncManager.
ExtensionsActivity* extensions_activity;
// Must outlive SyncManager.
ChangeDelegate* change_delegate;
// Credentials to be used when talking to the sync server.
SyncCredentials credentials;
// Unqiuely identifies this client to the invalidation notification server.
std::string invalidator_client_id;
// Used to boostrap the cryptographer.
std::string restored_key_for_bootstrapping;
std::string restored_keystore_key_for_bootstrapping;
scoped_ptr<InternalComponentsFactory> internal_components_factory;
// Must outlive SyncManager.
Encryptor* encryptor;
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler;
ReportUnrecoverableErrorFunction report_unrecoverable_error_function;
// Carries shutdown requests across threads and will be used to cut short
// any network I/O and tell the syncer to exit early.
//
// Must outlive SyncManager.
CancelationSignal* cancelation_signal;
};
SyncManager(); SyncManager();
virtual ~SyncManager(); virtual ~SyncManager();
// Initialize the sync manager. |database_location| specifies the path of // Initialize the sync manager using arguments from |args|.
// the directory in which to locate a sqlite repository storing the syncer
// backend state. Initialization will open the database, or create it if it
// does not already exist. Returns false on failure.
// |event_handler| is the JsEventHandler used to propagate events to
// chrome://sync-internals. |event_handler| may be uninitialized.
// |service_url| is the URL of the Chrome Sync Server.
// |post_factory| will be owned internally and used to create
// instances of an HttpPostProvider.
// |model_safe_worker| ownership is given to the SyncManager.
// |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent
// HTTP header. Used internally when collecting stats to classify clients.
// |invalidator| is owned and used to listen for invalidations.
// |invalidator_client_id| is used to unqiuely identify this client to the
// invalidation notification server.
// |restored_key_for_bootstrapping| is the key used to boostrap the
// cryptographer
// |keystore_encryption_enabled| determines whether we enable the keystore
// encryption functionality in the cryptographer/nigori.
// |report_unrecoverable_error_function| may be NULL.
// |cancelation_signal| carries shutdown requests across threads. This one
// will be used to cut short any network I/O and tell the syncer to exit
// early.
// //
// TODO(akalin): Replace the |post_factory| parameter with a // Note, args is passed by non-const pointer because it contains objects like
// URLFetcher parameter. // scoped_ptr.
virtual void Init( virtual void Init(InitArgs* args) = 0;
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) = 0;
virtual ModelTypeSet InitialSyncEndedTypes() = 0; virtual ModelTypeSet InitialSyncEndedTypes() = 0;
......
...@@ -77,23 +77,7 @@ class FakeSyncManager : public SyncManager { ...@@ -77,23 +77,7 @@ class FakeSyncManager : public SyncManager {
// SyncManager implementation. // SyncManager implementation.
// Note: we treat whatever message loop this is called from as the sync // Note: we treat whatever message loop this is called from as the sync
// loop for purposes of callbacks. // loop for purposes of callbacks.
virtual void Init( virtual void Init(InitArgs* args) OVERRIDE;
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) OVERRIDE;
virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE; virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
ModelTypeSet types) OVERRIDE; ModelTypeSet types) OVERRIDE;
......
...@@ -19,28 +19,12 @@ SyncBackupManager::SyncBackupManager() ...@@ -19,28 +19,12 @@ SyncBackupManager::SyncBackupManager()
SyncBackupManager::~SyncBackupManager() { SyncBackupManager::~SyncBackupManager() {
} }
void SyncBackupManager::Init( void SyncBackupManager::Init(InitArgs* args) {
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
SyncManager::ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) {
if (SyncRollbackManagerBase::InitInternal( if (SyncRollbackManagerBase::InitInternal(
database_location, args->database_location,
internal_components_factory, args->internal_components_factory.get(),
unrecoverable_error_handler.Pass(), args->unrecoverable_error_handler.Pass(),
report_unrecoverable_error_function)) { args->report_unrecoverable_error_function)) {
GetUserShare()->directory->CollectMetaHandleCounts( GetUserShare()->directory->CollectMetaHandleCounts(
&status_.num_entries_by_type, &status_.num_to_delete_entries_by_type); &status_.num_entries_by_type, &status_.num_to_delete_entries_by_type);
......
...@@ -21,23 +21,7 @@ class SYNC_EXPORT_PRIVATE SyncBackupManager : public SyncRollbackManagerBase { ...@@ -21,23 +21,7 @@ class SYNC_EXPORT_PRIVATE SyncBackupManager : public SyncRollbackManagerBase {
virtual ~SyncBackupManager(); virtual ~SyncBackupManager();
// SyncManager implementation. // SyncManager implementation.
virtual void Init( virtual void Init(InitArgs* args) OVERRIDE;
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
SyncManager::ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) OVERRIDE;
virtual void SaveChanges() OVERRIDE; virtual void SaveChanges() OVERRIDE;
virtual SyncStatus GetDetailedStatus() const OVERRIDE; virtual SyncStatus GetDetailedStatus() const OVERRIDE;
......
...@@ -55,27 +55,18 @@ class SyncBackupManagerTest : public syncer::SyncManager::Observer, ...@@ -55,27 +55,18 @@ class SyncBackupManagerTest : public syncer::SyncManager::Observer,
.WillOnce(WithArgs<2>(Invoke(this, .WillOnce(WithArgs<2>(Invoke(this,
&SyncBackupManagerTest::HandleInit))); &SyncBackupManagerTest::HandleInit)));
TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(),
storage_option);
manager->AddObserver(this); manager->AddObserver(this);
base::RunLoop run_loop; base::RunLoop run_loop;
manager->Init(temp_dir_.path(),
MakeWeakHandle(base::WeakPtr<JsEventHandler>()), SyncManager::InitArgs args;
GURL("https://example.com/"), args.database_location = temp_dir_.path();
scoped_ptr<HttpPostProviderFactory>().Pass(), args.event_handler = MakeWeakHandle(base::WeakPtr<JsEventHandler>());
std::vector<scoped_refptr<ModelSafeWorker> >(), args.service_url = GURL("https://example.com/");
NULL, args.post_factory = scoped_ptr<HttpPostProviderFactory>().Pass();
NULL, args.internal_components_factory.reset(new TestInternalComponentsFactory(
SyncCredentials(), InternalComponentsFactory::Switches(), storage_option));
"", manager->Init(&args);
"",
"",
&factory,
NULL,
scoped_ptr<UnrecoverableErrorHandler>().Pass(),
NULL,
NULL);
loop_.PostTask(FROM_HERE, run_loop.QuitClosure()); loop_.PostTask(FROM_HERE, run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
} }
......
...@@ -303,53 +303,38 @@ void SyncManagerImpl::ConfigureSyncer( ...@@ -303,53 +303,38 @@ void SyncManagerImpl::ConfigureSyncer(
scheduler_->ScheduleConfiguration(params); scheduler_->ScheduleConfiguration(params);
} }
void SyncManagerImpl::Init( void SyncManagerImpl::Init(InitArgs* args) {
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
SyncManager::ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) {
CHECK(!initialized_); CHECK(!initialized_);
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(post_factory.get()); DCHECK(args->post_factory.get());
DCHECK(!credentials.email.empty()); DCHECK(!args->credentials.email.empty());
DCHECK(!credentials.sync_token.empty()); DCHECK(!args->credentials.sync_token.empty());
DCHECK(!credentials.scope_set.empty()); DCHECK(!args->credentials.scope_set.empty());
DCHECK(cancelation_signal); DCHECK(args->cancelation_signal);
DVLOG(1) << "SyncManager starting Init..."; DVLOG(1) << "SyncManager starting Init...";
weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr());
change_delegate_ = change_delegate; change_delegate_ = args->change_delegate;
AddObserver(&js_sync_manager_observer_); AddObserver(&js_sync_manager_observer_);
SetJsEventHandler(event_handler); SetJsEventHandler(args->event_handler);
AddObserver(&debug_info_event_listener_); AddObserver(&debug_info_event_listener_);
database_path_ = database_location.Append( database_path_ = args->database_location.Append(
syncable::Directory::kSyncDatabaseFilename); syncable::Directory::kSyncDatabaseFilename);
unrecoverable_error_handler_ = unrecoverable_error_handler.Pass(); unrecoverable_error_handler_ = args->unrecoverable_error_handler.Pass();
report_unrecoverable_error_function_ = report_unrecoverable_error_function; report_unrecoverable_error_function_ =
args->report_unrecoverable_error_function;
allstatus_.SetHasKeystoreKey( allstatus_.SetHasKeystoreKey(
!restored_keystore_key_for_bootstrapping.empty()); !args->restored_keystore_key_for_bootstrapping.empty());
sync_encryption_handler_.reset(new SyncEncryptionHandlerImpl( sync_encryption_handler_.reset(new SyncEncryptionHandlerImpl(
&share_, &share_,
encryptor, args->encryptor,
restored_key_for_bootstrapping, args->restored_key_for_bootstrapping,
restored_keystore_key_for_bootstrapping)); args->restored_keystore_key_for_bootstrapping));
sync_encryption_handler_->AddObserver(this); sync_encryption_handler_->AddObserver(this);
sync_encryption_handler_->AddObserver(&debug_info_event_listener_); sync_encryption_handler_->AddObserver(&debug_info_event_listener_);
sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_); sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_);
...@@ -358,8 +343,9 @@ void SyncManagerImpl::Init( ...@@ -358,8 +343,9 @@ void SyncManagerImpl::Init(
DCHECK(absolute_db_path.IsAbsolute()); DCHECK(absolute_db_path.IsAbsolute());
scoped_ptr<syncable::DirectoryBackingStore> backing_store = scoped_ptr<syncable::DirectoryBackingStore> backing_store =
internal_components_factory->BuildDirectoryBackingStore( args->internal_components_factory->BuildDirectoryBackingStore(
credentials.email, absolute_db_path).Pass(); args->credentials.email,
absolute_db_path).Pass();
DCHECK(backing_store.get()); DCHECK(backing_store.get());
share_.directory.reset( share_.directory.reset(
...@@ -369,13 +355,13 @@ void SyncManagerImpl::Init( ...@@ -369,13 +355,13 @@ void SyncManagerImpl::Init(
report_unrecoverable_error_function_, report_unrecoverable_error_function_,
sync_encryption_handler_.get(), sync_encryption_handler_.get(),
sync_encryption_handler_->GetCryptographerUnsafe())); sync_encryption_handler_->GetCryptographerUnsafe()));
share_.sync_credentials = credentials; share_.sync_credentials = args->credentials;
// UserShare is accessible to a lot of code that doesn't need access to the // UserShare is accessible to a lot of code that doesn't need access to the
// sync token so clear sync_token from the UserShare. // sync token so clear sync_token from the UserShare.
share_.sync_credentials.sync_token = ""; share_.sync_credentials.sync_token = "";
const std::string& username = credentials.email; const std::string& username = args->credentials.email;
DVLOG(1) << "Username: " << username; DVLOG(1) << "Username: " << username;
if (!OpenDirectory(username)) { if (!OpenDirectory(username)) {
NotifyInitializationFailure(); NotifyInitializationFailure();
...@@ -384,11 +370,11 @@ void SyncManagerImpl::Init( ...@@ -384,11 +370,11 @@ void SyncManagerImpl::Init(
} }
connection_manager_.reset(new SyncAPIServerConnectionManager( connection_manager_.reset(new SyncAPIServerConnectionManager(
service_url.host() + service_url.path(), args->service_url.host() + args->service_url.path(),
service_url.EffectiveIntPort(), args->service_url.EffectiveIntPort(),
service_url.SchemeIsSecure(), args->service_url.SchemeIsSecure(),
post_factory.release(), args->post_factory.release(),
cancelation_signal)); args->cancelation_signal));
connection_manager_->set_client_id(directory()->cache_guid()); connection_manager_->set_client_id(directory()->cache_guid());
connection_manager_->AddListener(this); connection_manager_->AddListener(this);
...@@ -396,10 +382,11 @@ void SyncManagerImpl::Init( ...@@ -396,10 +382,11 @@ void SyncManagerImpl::Init(
DVLOG(1) << "Setting sync client ID: " << sync_id; DVLOG(1) << "Setting sync client ID: " << sync_id;
allstatus_.SetSyncId(sync_id); allstatus_.SetSyncId(sync_id);
DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id; DVLOG(1) << "Setting invalidator client ID: " << args->invalidator_client_id;
allstatus_.SetInvalidatorClientId(invalidator_client_id); allstatus_.SetInvalidatorClientId(args->invalidator_client_id);
model_type_registry_.reset(new ModelTypeRegistry(workers, directory(), this)); model_type_registry_.reset(
new ModelTypeRegistry(args->workers, directory(), this));
// Bind the SyncContext WeakPtr to this thread. This helps us crash earlier // Bind the SyncContext WeakPtr to this thread. This helps us crash earlier
// if the pointer is misused in debug mode. // if the pointer is misused in debug mode.
...@@ -414,17 +401,19 @@ void SyncManagerImpl::Init( ...@@ -414,17 +401,19 @@ void SyncManagerImpl::Init(
std::vector<SyncEngineEventListener*> listeners; std::vector<SyncEngineEventListener*> listeners;
listeners.push_back(&allstatus_); listeners.push_back(&allstatus_);
listeners.push_back(this); listeners.push_back(this);
session_context_ = internal_components_factory->BuildContext( session_context_ =
connection_manager_.get(), args->internal_components_factory->BuildContext(
directory(), connection_manager_.get(),
extensions_activity, directory(),
listeners, args->extensions_activity,
&debug_info_event_listener_, listeners,
model_type_registry_.get(), &debug_info_event_listener_,
invalidator_client_id).Pass(); model_type_registry_.get(),
session_context_->set_account_name(credentials.email); args->invalidator_client_id)
scheduler_ = internal_components_factory->BuildScheduler( .Pass();
name_, session_context_.get(), cancelation_signal).Pass(); session_context_->set_account_name(args->credentials.email);
scheduler_ = args->internal_components_factory->BuildScheduler(
name_, session_context_.get(), args->cancelation_signal).Pass();
scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); scheduler_->Start(SyncScheduler::CONFIGURATION_MODE);
...@@ -434,7 +423,7 @@ void SyncManagerImpl::Init( ...@@ -434,7 +423,7 @@ void SyncManagerImpl::Init(
net::NetworkChangeNotifier::AddConnectionTypeObserver(this); net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
observing_network_connectivity_changes_ = true; observing_network_connectivity_changes_ = true;
UpdateCredentials(credentials); UpdateCredentials(args->credentials);
NotifyInitializationSuccess(); NotifyInitializationSuccess();
} }
......
...@@ -68,23 +68,7 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl ...@@ -68,23 +68,7 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl
virtual ~SyncManagerImpl(); virtual ~SyncManagerImpl();
// SyncManager implementation. // SyncManager implementation.
virtual void Init( virtual void Init(InitArgs* args) OVERRIDE;
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
SyncManager::ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) OVERRIDE;
virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE; virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
ModelTypeSet types) OVERRIDE; ModelTypeSet types) OVERRIDE;
......
...@@ -815,25 +815,21 @@ class SyncManagerTest : public testing::Test, ...@@ -815,25 +815,21 @@ class SyncManagerTest : public testing::Test,
scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(GROUP_PASSIVE); scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(GROUP_PASSIVE);
workers.push_back(worker); workers.push_back(worker);
// Takes ownership of |fake_invalidator_|. SyncManager::InitArgs args;
sync_manager_.Init( args.database_location = temp_dir_.path();
temp_dir_.path(), args.service_url = GURL("https://example.com/");
WeakHandle<JsEventHandler>(), args.post_factory =
GURL("https://example.com/"), scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory());
scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()), args.workers = workers;
workers, args.extensions_activity = extensions_activity_.get(),
extensions_activity_.get(), args.change_delegate = this;
this, args.credentials = credentials;
credentials, args.invalidator_client_id = "fake_invalidator_client_id";
"fake_invalidator_client_id", args.internal_components_factory.reset(GetFactory());
std::string(), args.encryptor = &encryptor_;
std::string(), // bootstrap tokens args.unrecoverable_error_handler.reset(new TestUnrecoverableErrorHandler);
scoped_ptr<InternalComponentsFactory>(GetFactory()).get(), args.cancelation_signal = &cancelation_signal_;
&encryptor_, sync_manager_.Init(&args);
scoped_ptr<UnrecoverableErrorHandler>(new TestUnrecoverableErrorHandler)
.Pass(),
NULL,
&cancelation_signal_);
sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
......
...@@ -22,34 +22,18 @@ SyncRollbackManager::SyncRollbackManager() ...@@ -22,34 +22,18 @@ SyncRollbackManager::SyncRollbackManager()
SyncRollbackManager::~SyncRollbackManager() { SyncRollbackManager::~SyncRollbackManager() {
} }
void SyncRollbackManager::Init( void SyncRollbackManager::Init(InitArgs* args) {
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
SyncManager::ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) {
if (SyncRollbackManagerBase::InitInternal( if (SyncRollbackManagerBase::InitInternal(
database_location, args->database_location,
internal_components_factory, args->internal_components_factory.get(),
unrecoverable_error_handler.Pass(), args->unrecoverable_error_handler.Pass(),
report_unrecoverable_error_function)) { args->report_unrecoverable_error_function)) {
change_delegate_ = change_delegate; change_delegate_ = args->change_delegate;
for (size_t i = 0; i < workers.size(); ++i) { for (size_t i = 0; i < args->workers.size(); ++i) {
ModelSafeGroup group = workers[i]->GetModelSafeGroup(); ModelSafeGroup group = args->workers[i]->GetModelSafeGroup();
CHECK(workers_.find(group) == workers_.end()); CHECK(workers_.find(group) == workers_.end());
workers_[group] = workers[i]; workers_[group] = args->workers[i];
} }
rollback_ready_types_ = GetUserShare()->directory->InitialSyncEndedTypes(); rollback_ready_types_ = GetUserShare()->directory->InitialSyncEndedTypes();
......
...@@ -22,23 +22,7 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManager : public SyncRollbackManagerBase { ...@@ -22,23 +22,7 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManager : public SyncRollbackManagerBase {
virtual ~SyncRollbackManager(); virtual ~SyncRollbackManager();
// SyncManager implementation. // SyncManager implementation.
virtual void Init( virtual void Init(InitArgs* args) OVERRIDE;
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
SyncManager::ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) OVERRIDE;
virtual void StartSyncingNormally( virtual void StartSyncingNormally(
const ModelSafeRoutingInfo& routing_info) OVERRIDE; const ModelSafeRoutingInfo& routing_info) OVERRIDE;
......
...@@ -21,51 +21,24 @@ void OnConfigDone(bool success) { ...@@ -21,51 +21,24 @@ void OnConfigDone(bool success) {
class SyncTestRollbackManager : public SyncRollbackManagerBase { class SyncTestRollbackManager : public SyncRollbackManagerBase {
public: public:
virtual void Init( virtual void Init(InitArgs* args) OVERRIDE {
const base::FilePath& database_location, SyncRollbackManagerBase::InitInternal(
const WeakHandle<JsEventHandler>& event_handler, args->database_location,
const GURL& service_url, args->internal_components_factory.get(),
scoped_ptr<HttpPostProviderFactory> post_factory, args->unrecoverable_error_handler.Pass(),
const std::vector<scoped_refptr<ModelSafeWorker> >& workers, args->report_unrecoverable_error_function);
ExtensionsActivity* extensions_activity,
ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) OVERRIDE {
SyncRollbackManagerBase::InitInternal(database_location,
internal_components_factory,
unrecoverable_error_handler.Pass(),
report_unrecoverable_error_function);
} }
}; };
class SyncRollbackManagerBaseTest : public testing::Test { class SyncRollbackManagerBaseTest : public testing::Test {
protected: protected:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(), SyncManager::InitArgs args;
STORAGE_IN_MEMORY); args.database_location = base::FilePath(base::FilePath::kCurrentDirectory);
manager_.Init(base::FilePath(base::FilePath::kCurrentDirectory), args.service_url = GURL("https://example.com/");
MakeWeakHandle(base::WeakPtr<JsEventHandler>()), args.internal_components_factory.reset(new TestInternalComponentsFactory(
GURL("https://example.com/"), InternalComponentsFactory::Switches(), STORAGE_IN_MEMORY));
scoped_ptr<HttpPostProviderFactory>().Pass(), manager_.Init(&args);
std::vector<scoped_refptr<ModelSafeWorker> >(),
NULL,
NULL,
SyncCredentials(),
"",
"",
"",
&factory,
NULL,
scoped_ptr<UnrecoverableErrorHandler>().Pass(),
NULL,
NULL);
} }
SyncTestRollbackManager manager_; SyncTestRollbackManager manager_;
......
...@@ -111,27 +111,16 @@ class SyncRollbackManagerTest : public testing::Test, ...@@ -111,27 +111,16 @@ class SyncRollbackManagerTest : public testing::Test,
&SyncRollbackManagerTest::HandleInit))); &SyncRollbackManagerTest::HandleInit)));
manager->AddObserver(this); manager->AddObserver(this);
TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(),
storage_option);
base::RunLoop run_loop; base::RunLoop run_loop;
manager->Init( SyncManager::InitArgs args;
temp_dir_.path(), args.database_location = temp_dir_.path();
MakeWeakHandle(base::WeakPtr<JsEventHandler>()), args.service_url = GURL("https://example.com/");
GURL("https://example.com/"), args.workers.push_back(worker_);
scoped_ptr<HttpPostProviderFactory>().Pass(), args.change_delegate = delegate;
std::vector<scoped_refptr<ModelSafeWorker> >(1, worker_.get()), args.internal_components_factory.reset(new TestInternalComponentsFactory(
NULL, InternalComponentsFactory::Switches(), storage_option));
delegate, manager->Init(&args);
SyncCredentials(),
"",
"",
"",
&factory,
NULL,
scoped_ptr<UnrecoverableErrorHandler>().Pass(),
NULL,
NULL);
loop_.PostTask(FROM_HERE, run_loop.QuitClosure()); loop_.PostTask(FROM_HERE, run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
} }
......
...@@ -72,23 +72,7 @@ void FakeSyncManager::WaitForSyncThread() { ...@@ -72,23 +72,7 @@ void FakeSyncManager::WaitForSyncThread() {
run_loop.Run(); run_loop.Run();
} }
void FakeSyncManager::Init( void FakeSyncManager::Init(InitArgs* args) {
const base::FilePath& database_location,
const WeakHandle<JsEventHandler>& event_handler,
const GURL& service_url,
scoped_ptr<HttpPostProviderFactory> post_factory,
const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
ExtensionsActivity* extensions_activity,
ChangeDelegate* change_delegate,
const SyncCredentials& credentials,
const std::string& invalidator_client_id,
const std::string& restored_key_for_bootstrapping,
const std::string& restored_keystore_key_for_bootstrapping,
InternalComponentsFactory* internal_components_factory,
Encryptor* encryptor,
scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
CancelationSignal* cancelation_signal) {
sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); sync_task_runner_ = base::ThreadTaskRunnerHandle::Get();
PurgePartiallySyncedTypes(); PurgePartiallySyncedTypes();
......
...@@ -430,23 +430,26 @@ int SyncClientMain(int argc, char* argv[]) { ...@@ -430,23 +430,26 @@ int SyncClientMain(int argc, char* argv[]) {
}; };
CancelationSignal scm_cancelation_signal; CancelationSignal scm_cancelation_signal;
sync_manager->Init(database_dir.path(), SyncManager::InitArgs args;
WeakHandle<JsEventHandler>(js_event_handler.AsWeakPtr()), args.database_location = database_dir.path();
GURL(kSyncServiceURL), args.event_handler = WeakHandle<JsEventHandler>(js_event_handler.AsWeakPtr());
post_factory.Pass(), args.service_url = GURL(kSyncServiceURL);
workers, args.post_factory = post_factory.Pass();
extensions_activity, args.workers = workers;
&change_delegate, args.extensions_activity = extensions_activity;
credentials, args.change_delegate = &change_delegate;
invalidator_id, args.credentials = credentials;
kRestoredKeyForBootstrapping, args.invalidator_client_id = invalidator_id;
kRestoredKeystoreKeyForBootstrapping, args.restored_key_for_bootstrapping = kRestoredKeyForBootstrapping;
new InternalComponentsFactoryImpl(factory_switches), args.restored_keystore_key_for_bootstrapping =
&null_encryptor, kRestoredKeystoreKeyForBootstrapping;
scoped_ptr<UnrecoverableErrorHandler>( args.internal_components_factory.reset(
new LoggingUnrecoverableErrorHandler).Pass(), new InternalComponentsFactoryImpl(factory_switches));
&LogUnrecoverableErrorContext, args.encryptor = &null_encryptor;
&scm_cancelation_signal); args.unrecoverable_error_handler.reset(new LoggingUnrecoverableErrorHandler);
args.report_unrecoverable_error_function = &LogUnrecoverableErrorContext;
args.cancelation_signal = &scm_cancelation_signal;
sync_manager->Init(&args);
// TODO(akalin): Avoid passing in model parameters multiple times by // TODO(akalin): Avoid passing in model parameters multiple times by
// organizing handling of model types. // organizing handling of model types.
invalidator->UpdateCredentials(credentials.email, credentials.sync_token); invalidator->UpdateCredentials(credentials.email, credentials.sync_token);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment