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(
sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_);
sync_manager_->AddObserver(this);
sync_manager_->Init(sync_data_folder_path_,
options->event_handler,
options->service_url,
options->http_bridge_factory.Pass(),
options->workers,
options->extensions_activity,
options->registrar /* as SyncManager::ChangeDelegate */,
options->credentials,
options->invalidator_client_id,
options->restored_key_for_bootstrapping,
options->restored_keystore_key_for_bootstrapping,
options->internal_components_factory.get(),
&encryptor_,
options->unrecoverable_error_handler.Pass(),
options->report_unrecoverable_error_function,
&stop_syncing_signal_);
syncer::SyncManager::InitArgs args;
args.database_location = sync_data_folder_path_;
args.event_handler = options->event_handler;
args.service_url = options->service_url;
args.post_factory = options->http_bridge_factory.Pass();
args.workers = options->workers;
args.extensions_activity = options->extensions_activity;
args.change_delegate = options->registrar; // as SyncManager::ChangeDelegate
args.credentials = options->credentials;
args.invalidator_client_id = options->invalidator_client_id;
args.restored_key_for_bootstrapping = options->restored_key_for_bootstrapping;
args.restored_keystore_key_for_bootstrapping =
options->restored_keystore_key_for_bootstrapping;
args.internal_components_factory =
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(
......
......@@ -16,6 +16,15 @@ SyncManager::ChangeObserver::~ChangeObserver() {}
SyncManager::Observer::~Observer() {}
SyncManager::InitArgs::InitArgs()
: extensions_activity(NULL),
change_delegate(NULL),
encryptor(NULL),
cancelation_signal(NULL) {
}
SyncManager::InitArgs::~InitArgs() {}
SyncManager::SyncManager() {}
SyncManager::~SyncManager() {}
......
......@@ -25,6 +25,8 @@
#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/engine/sync_status.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/sync_context_proxy.h"
#include "sync/internal_api/public/sync_encryption_handler.h"
......@@ -46,7 +48,6 @@ class CancelationSignal;
class DataTypeDebugInfoListener;
class Encryptor;
class ExtensionsActivity;
class HttpPostProviderFactory;
class InternalComponentsFactory;
class JsBackend;
class JsEventHandler;
......@@ -220,52 +221,65 @@ class SYNC_EXPORT SyncManager {
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();
virtual ~SyncManager();
// Initialize the sync manager. |database_location| specifies the path of
// 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.
// Initialize the sync manager using arguments from |args|.
//
// TODO(akalin): Replace the |post_factory| parameter with a
// URLFetcher parameter.
virtual void Init(
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;
// Note, args is passed by non-const pointer because it contains objects like
// scoped_ptr.
virtual void Init(InitArgs* args) = 0;
virtual ModelTypeSet InitialSyncEndedTypes() = 0;
......
......@@ -77,23 +77,7 @@ class FakeSyncManager : public SyncManager {
// SyncManager implementation.
// Note: we treat whatever message loop this is called from as the sync
// loop for purposes of callbacks.
virtual void Init(
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 void Init(InitArgs* args) OVERRIDE;
virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
ModelTypeSet types) OVERRIDE;
......
......@@ -19,28 +19,12 @@ SyncBackupManager::SyncBackupManager()
SyncBackupManager::~SyncBackupManager() {
}
void SyncBackupManager::Init(
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) {
void SyncBackupManager::Init(InitArgs* args) {
if (SyncRollbackManagerBase::InitInternal(
database_location,
internal_components_factory,
unrecoverable_error_handler.Pass(),
report_unrecoverable_error_function)) {
args->database_location,
args->internal_components_factory.get(),
args->unrecoverable_error_handler.Pass(),
args->report_unrecoverable_error_function)) {
GetUserShare()->directory->CollectMetaHandleCounts(
&status_.num_entries_by_type, &status_.num_to_delete_entries_by_type);
......
......@@ -21,23 +21,7 @@ class SYNC_EXPORT_PRIVATE SyncBackupManager : public SyncRollbackManagerBase {
virtual ~SyncBackupManager();
// SyncManager implementation.
virtual void Init(
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 Init(InitArgs* args) OVERRIDE;
virtual void SaveChanges() OVERRIDE;
virtual SyncStatus GetDetailedStatus() const OVERRIDE;
......
......@@ -55,27 +55,18 @@ class SyncBackupManagerTest : public syncer::SyncManager::Observer,
.WillOnce(WithArgs<2>(Invoke(this,
&SyncBackupManagerTest::HandleInit)));
TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(),
storage_option);
manager->AddObserver(this);
base::RunLoop run_loop;
manager->Init(temp_dir_.path(),
MakeWeakHandle(base::WeakPtr<JsEventHandler>()),
GURL("https://example.com/"),
scoped_ptr<HttpPostProviderFactory>().Pass(),
std::vector<scoped_refptr<ModelSafeWorker> >(),
NULL,
NULL,
SyncCredentials(),
"",
"",
"",
&factory,
NULL,
scoped_ptr<UnrecoverableErrorHandler>().Pass(),
NULL,
NULL);
SyncManager::InitArgs args;
args.database_location = temp_dir_.path();
args.event_handler = MakeWeakHandle(base::WeakPtr<JsEventHandler>());
args.service_url = GURL("https://example.com/");
args.post_factory = scoped_ptr<HttpPostProviderFactory>().Pass();
args.internal_components_factory.reset(new TestInternalComponentsFactory(
InternalComponentsFactory::Switches(), storage_option));
manager->Init(&args);
loop_.PostTask(FROM_HERE, run_loop.QuitClosure());
run_loop.Run();
}
......
......@@ -303,53 +303,38 @@ void SyncManagerImpl::ConfigureSyncer(
scheduler_->ScheduleConfiguration(params);
}
void SyncManagerImpl::Init(
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) {
void SyncManagerImpl::Init(InitArgs* args) {
CHECK(!initialized_);
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(post_factory.get());
DCHECK(!credentials.email.empty());
DCHECK(!credentials.sync_token.empty());
DCHECK(!credentials.scope_set.empty());
DCHECK(cancelation_signal);
DCHECK(args->post_factory.get());
DCHECK(!args->credentials.email.empty());
DCHECK(!args->credentials.sync_token.empty());
DCHECK(!args->credentials.scope_set.empty());
DCHECK(args->cancelation_signal);
DVLOG(1) << "SyncManager starting Init...";
weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr());
change_delegate_ = change_delegate;
change_delegate_ = args->change_delegate;
AddObserver(&js_sync_manager_observer_);
SetJsEventHandler(event_handler);
SetJsEventHandler(args->event_handler);
AddObserver(&debug_info_event_listener_);
database_path_ = database_location.Append(
database_path_ = args->database_location.Append(
syncable::Directory::kSyncDatabaseFilename);
unrecoverable_error_handler_ = unrecoverable_error_handler.Pass();
report_unrecoverable_error_function_ = report_unrecoverable_error_function;
unrecoverable_error_handler_ = args->unrecoverable_error_handler.Pass();
report_unrecoverable_error_function_ =
args->report_unrecoverable_error_function;
allstatus_.SetHasKeystoreKey(
!restored_keystore_key_for_bootstrapping.empty());
!args->restored_keystore_key_for_bootstrapping.empty());
sync_encryption_handler_.reset(new SyncEncryptionHandlerImpl(
&share_,
encryptor,
restored_key_for_bootstrapping,
restored_keystore_key_for_bootstrapping));
args->encryptor,
args->restored_key_for_bootstrapping,
args->restored_keystore_key_for_bootstrapping));
sync_encryption_handler_->AddObserver(this);
sync_encryption_handler_->AddObserver(&debug_info_event_listener_);
sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_);
......@@ -358,8 +343,9 @@ void SyncManagerImpl::Init(
DCHECK(absolute_db_path.IsAbsolute());
scoped_ptr<syncable::DirectoryBackingStore> backing_store =
internal_components_factory->BuildDirectoryBackingStore(
credentials.email, absolute_db_path).Pass();
args->internal_components_factory->BuildDirectoryBackingStore(
args->credentials.email,
absolute_db_path).Pass();
DCHECK(backing_store.get());
share_.directory.reset(
......@@ -369,13 +355,13 @@ void SyncManagerImpl::Init(
report_unrecoverable_error_function_,
sync_encryption_handler_.get(),
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
// sync token so clear sync_token from the UserShare.
share_.sync_credentials.sync_token = "";
const std::string& username = credentials.email;
const std::string& username = args->credentials.email;
DVLOG(1) << "Username: " << username;
if (!OpenDirectory(username)) {
NotifyInitializationFailure();
......@@ -384,11 +370,11 @@ void SyncManagerImpl::Init(
}
connection_manager_.reset(new SyncAPIServerConnectionManager(
service_url.host() + service_url.path(),
service_url.EffectiveIntPort(),
service_url.SchemeIsSecure(),
post_factory.release(),
cancelation_signal));
args->service_url.host() + args->service_url.path(),
args->service_url.EffectiveIntPort(),
args->service_url.SchemeIsSecure(),
args->post_factory.release(),
args->cancelation_signal));
connection_manager_->set_client_id(directory()->cache_guid());
connection_manager_->AddListener(this);
......@@ -396,10 +382,11 @@ void SyncManagerImpl::Init(
DVLOG(1) << "Setting sync client ID: " << sync_id;
allstatus_.SetSyncId(sync_id);
DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id;
allstatus_.SetInvalidatorClientId(invalidator_client_id);
DVLOG(1) << "Setting invalidator client ID: " << args->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
// if the pointer is misused in debug mode.
......@@ -414,17 +401,19 @@ void SyncManagerImpl::Init(
std::vector<SyncEngineEventListener*> listeners;
listeners.push_back(&allstatus_);
listeners.push_back(this);
session_context_ = internal_components_factory->BuildContext(
connection_manager_.get(),
directory(),
extensions_activity,
listeners,
&debug_info_event_listener_,
model_type_registry_.get(),
invalidator_client_id).Pass();
session_context_->set_account_name(credentials.email);
scheduler_ = internal_components_factory->BuildScheduler(
name_, session_context_.get(), cancelation_signal).Pass();
session_context_ =
args->internal_components_factory->BuildContext(
connection_manager_.get(),
directory(),
args->extensions_activity,
listeners,
&debug_info_event_listener_,
model_type_registry_.get(),
args->invalidator_client_id)
.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);
......@@ -434,7 +423,7 @@ void SyncManagerImpl::Init(
net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
observing_network_connectivity_changes_ = true;
UpdateCredentials(credentials);
UpdateCredentials(args->credentials);
NotifyInitializationSuccess();
}
......
......@@ -68,23 +68,7 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl
virtual ~SyncManagerImpl();
// SyncManager implementation.
virtual void Init(
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 Init(InitArgs* args) OVERRIDE;
virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
ModelTypeSet types) OVERRIDE;
......
......@@ -815,25 +815,21 @@ class SyncManagerTest : public testing::Test,
scoped_refptr<ModelSafeWorker> worker = new FakeModelWorker(GROUP_PASSIVE);
workers.push_back(worker);
// Takes ownership of |fake_invalidator_|.
sync_manager_.Init(
temp_dir_.path(),
WeakHandle<JsEventHandler>(),
GURL("https://example.com/"),
scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()),
workers,
extensions_activity_.get(),
this,
credentials,
"fake_invalidator_client_id",
std::string(),
std::string(), // bootstrap tokens
scoped_ptr<InternalComponentsFactory>(GetFactory()).get(),
&encryptor_,
scoped_ptr<UnrecoverableErrorHandler>(new TestUnrecoverableErrorHandler)
.Pass(),
NULL,
&cancelation_signal_);
SyncManager::InitArgs args;
args.database_location = temp_dir_.path();
args.service_url = GURL("https://example.com/");
args.post_factory =
scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory());
args.workers = workers;
args.extensions_activity = extensions_activity_.get(),
args.change_delegate = this;
args.credentials = credentials;
args.invalidator_client_id = "fake_invalidator_client_id";
args.internal_components_factory.reset(GetFactory());
args.encryptor = &encryptor_;
args.unrecoverable_error_handler.reset(new TestUnrecoverableErrorHandler);
args.cancelation_signal = &cancelation_signal_;
sync_manager_.Init(&args);
sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
......
......@@ -22,34 +22,18 @@ SyncRollbackManager::SyncRollbackManager()
SyncRollbackManager::~SyncRollbackManager() {
}
void SyncRollbackManager::Init(
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) {
void SyncRollbackManager::Init(InitArgs* args) {
if (SyncRollbackManagerBase::InitInternal(
database_location,
internal_components_factory,
unrecoverable_error_handler.Pass(),
report_unrecoverable_error_function)) {
change_delegate_ = change_delegate;
for (size_t i = 0; i < workers.size(); ++i) {
ModelSafeGroup group = workers[i]->GetModelSafeGroup();
args->database_location,
args->internal_components_factory.get(),
args->unrecoverable_error_handler.Pass(),
args->report_unrecoverable_error_function)) {
change_delegate_ = args->change_delegate;
for (size_t i = 0; i < args->workers.size(); ++i) {
ModelSafeGroup group = args->workers[i]->GetModelSafeGroup();
CHECK(workers_.find(group) == workers_.end());
workers_[group] = workers[i];
workers_[group] = args->workers[i];
}
rollback_ready_types_ = GetUserShare()->directory->InitialSyncEndedTypes();
......
......@@ -22,23 +22,7 @@ class SYNC_EXPORT_PRIVATE SyncRollbackManager : public SyncRollbackManagerBase {
virtual ~SyncRollbackManager();
// SyncManager implementation.
virtual void Init(
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 Init(InitArgs* args) OVERRIDE;
virtual void StartSyncingNormally(
const ModelSafeRoutingInfo& routing_info) OVERRIDE;
......
......@@ -21,51 +21,24 @@ void OnConfigDone(bool success) {
class SyncTestRollbackManager : public SyncRollbackManagerBase {
public:
virtual void Init(
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 {
SyncRollbackManagerBase::InitInternal(database_location,
internal_components_factory,
unrecoverable_error_handler.Pass(),
report_unrecoverable_error_function);
virtual void Init(InitArgs* args) OVERRIDE {
SyncRollbackManagerBase::InitInternal(
args->database_location,
args->internal_components_factory.get(),
args->unrecoverable_error_handler.Pass(),
args->report_unrecoverable_error_function);
}
};
class SyncRollbackManagerBaseTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(),
STORAGE_IN_MEMORY);
manager_.Init(base::FilePath(base::FilePath::kCurrentDirectory),
MakeWeakHandle(base::WeakPtr<JsEventHandler>()),
GURL("https://example.com/"),
scoped_ptr<HttpPostProviderFactory>().Pass(),
std::vector<scoped_refptr<ModelSafeWorker> >(),
NULL,
NULL,
SyncCredentials(),
"",
"",
"",
&factory,
NULL,
scoped_ptr<UnrecoverableErrorHandler>().Pass(),
NULL,
NULL);
SyncManager::InitArgs args;
args.database_location = base::FilePath(base::FilePath::kCurrentDirectory);
args.service_url = GURL("https://example.com/");
args.internal_components_factory.reset(new TestInternalComponentsFactory(
InternalComponentsFactory::Switches(), STORAGE_IN_MEMORY));
manager_.Init(&args);
}
SyncTestRollbackManager manager_;
......
......@@ -111,27 +111,16 @@ class SyncRollbackManagerTest : public testing::Test,
&SyncRollbackManagerTest::HandleInit)));
manager->AddObserver(this);
TestInternalComponentsFactory factory(InternalComponentsFactory::Switches(),
storage_option);
base::RunLoop run_loop;
manager->Init(
temp_dir_.path(),
MakeWeakHandle(base::WeakPtr<JsEventHandler>()),
GURL("https://example.com/"),
scoped_ptr<HttpPostProviderFactory>().Pass(),
std::vector<scoped_refptr<ModelSafeWorker> >(1, worker_.get()),
NULL,
delegate,
SyncCredentials(),
"",
"",
"",
&factory,
NULL,
scoped_ptr<UnrecoverableErrorHandler>().Pass(),
NULL,
NULL);
SyncManager::InitArgs args;
args.database_location = temp_dir_.path();
args.service_url = GURL("https://example.com/");
args.workers.push_back(worker_);
args.change_delegate = delegate;
args.internal_components_factory.reset(new TestInternalComponentsFactory(
InternalComponentsFactory::Switches(), storage_option));
manager->Init(&args);
loop_.PostTask(FROM_HERE, run_loop.QuitClosure());
run_loop.Run();
}
......
......@@ -72,23 +72,7 @@ void FakeSyncManager::WaitForSyncThread() {
run_loop.Run();
}
void FakeSyncManager::Init(
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) {
void FakeSyncManager::Init(InitArgs* args) {
sync_task_runner_ = base::ThreadTaskRunnerHandle::Get();
PurgePartiallySyncedTypes();
......
......@@ -430,23 +430,26 @@ int SyncClientMain(int argc, char* argv[]) {
};
CancelationSignal scm_cancelation_signal;
sync_manager->Init(database_dir.path(),
WeakHandle<JsEventHandler>(js_event_handler.AsWeakPtr()),
GURL(kSyncServiceURL),
post_factory.Pass(),
workers,
extensions_activity,
&change_delegate,
credentials,
invalidator_id,
kRestoredKeyForBootstrapping,
kRestoredKeystoreKeyForBootstrapping,
new InternalComponentsFactoryImpl(factory_switches),
&null_encryptor,
scoped_ptr<UnrecoverableErrorHandler>(
new LoggingUnrecoverableErrorHandler).Pass(),
&LogUnrecoverableErrorContext,
&scm_cancelation_signal);
SyncManager::InitArgs args;
args.database_location = database_dir.path();
args.event_handler = WeakHandle<JsEventHandler>(js_event_handler.AsWeakPtr());
args.service_url = GURL(kSyncServiceURL);
args.post_factory = post_factory.Pass();
args.workers = workers;
args.extensions_activity = extensions_activity;
args.change_delegate = &change_delegate;
args.credentials = credentials;
args.invalidator_client_id = invalidator_id;
args.restored_key_for_bootstrapping = kRestoredKeyForBootstrapping;
args.restored_keystore_key_for_bootstrapping =
kRestoredKeystoreKeyForBootstrapping;
args.internal_components_factory.reset(
new InternalComponentsFactoryImpl(factory_switches));
args.encryptor = &null_encryptor;
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
// organizing handling of model types.
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