| Index: chrome/browser/sync/test_profile_sync_service.cc
|
| diff --git a/chrome/browser/sync/test_profile_sync_service.cc b/chrome/browser/sync/test_profile_sync_service.cc
|
| index 51a915d9c16a24330044ee020741e99261b3d7a5..83d19794c3ecc5b83bfb1efbb7ea11ffcbb250ee 100644
|
| --- a/chrome/browser/sync/test_profile_sync_service.cc
|
| +++ b/chrome/browser/sync/test_profile_sync_service.cc
|
| @@ -32,12 +32,17 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
|
| Profile* profile,
|
| const base::WeakPtr<SyncPrefs>& sync_prefs,
|
| const base::WeakPtr<InvalidatorStorage>& invalidator_storage,
|
| + syncer::TestIdFactory& id_factory,
|
| + base::Callback<void(UserShare*)>& callback,
|
| bool set_initial_sync_ended_on_init,
|
| bool synchronous_init,
|
| bool fail_initial_download,
|
| bool use_real_database)
|
| : browser_sync::SyncBackendHost(
|
| profile->GetDebugName(), profile, sync_prefs, invalidator_storage),
|
| + id_factory_(id_factory),
|
| + callback_(callback),
|
| + set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init),
|
| synchronous_init_(synchronous_init),
|
| fail_initial_download_(fail_initial_download),
|
| use_real_database_(use_real_database) {}
|
| @@ -95,6 +100,56 @@ void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer(
|
| ready_task);
|
| }
|
|
|
| +void SyncBackendHostForProfileSyncTest
|
| + ::HandleSyncManagerInitializationOnFrontendLoop(
|
| + const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success,
|
| + syncer::ModelTypeSet restored_types) {
|
| + // Here's our opportunity to pretend to do things that the SyncManager would
|
| + // normally do during initialization, but can't because this is a test.
|
| + bool send_passphrase_required = false;
|
| + if (success) {
|
| + // Set up any nodes the test wants around before model association.
|
| + if (!callback_.is_null()) {
|
| + callback_.Run(GetUserShareForTest());
|
| + callback_.Reset();
|
| + }
|
| +
|
| + // Pretend we downloaded initial updates and set initial sync ended bits
|
| + // if we were asked to.
|
| + if (set_initial_sync_ended_on_init_) {
|
| + UserShare* user_share = GetUserShareForTest();
|
| + Directory* directory = user_share->directory.get();
|
| +
|
| + if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) {
|
| + ProfileSyncServiceTestHelper::CreateRoot(
|
| + syncer::NIGORI, GetUserShareForTest(),
|
| + &id_factory_);
|
| +
|
| + // A side effect of adding the NIGORI mode (normally done by the
|
| + // syncer) is a decryption attempt, which will fail the first time.
|
| + send_passphrase_required = true;
|
| + }
|
| +
|
| + SetInitialSyncEndedForAllTypes();
|
| + restored_types = syncer::ModelTypeSet::All();
|
| + }
|
| + }
|
| +
|
| + SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
|
| + js_backend, success, restored_types);
|
| +}
|
| +
|
| +void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForAllTypes() {
|
| + UserShare* user_share = GetUserShareForTest();
|
| + Directory* directory = user_share->directory.get();
|
| +
|
| + for (int i = syncer::FIRST_REAL_MODEL_TYPE;
|
| + i < syncer::MODEL_TYPE_COUNT; ++i) {
|
| + directory->set_initial_sync_ended_for_type(
|
| + syncer::ModelTypeFromInt(i), true);
|
| + }
|
| +}
|
| +
|
| } // namespace browser_sync
|
|
|
| syncer::TestIdFactory* TestProfileSyncService::id_factory() {
|
| @@ -107,13 +162,22 @@ browser_sync::SyncBackendHostForProfileSyncTest*
|
| ProfileSyncService::GetBackendForTest());
|
| }
|
|
|
| +static void DoNothingCallback(syncer::UserShare*) {
|
| +}
|
| +
|
| +// static
|
| +base::Callback<void(syncer::UserShare*)>
|
| + TestProfileSyncService::NullCallback() {
|
| + return base::Bind(DoNothingCallback);
|
| +}
|
| +
|
| TestProfileSyncService::TestProfileSyncService(
|
| ProfileSyncComponentsFactory* factory,
|
| Profile* profile,
|
| SigninManager* signin,
|
| ProfileSyncService::StartBehavior behavior,
|
| bool synchronous_backend_initialization,
|
| - const base::Closure& callback)
|
| + const base::Callback<void(UserShare*)>& callback)
|
| : ProfileSyncService(factory,
|
| profile,
|
| signin,
|
| @@ -131,54 +195,10 @@ TestProfileSyncService::TestProfileSyncService(
|
| TestProfileSyncService::~TestProfileSyncService() {
|
| }
|
|
|
| -void TestProfileSyncService::SetInitialSyncEndedForAllTypes() {
|
| - UserShare* user_share = GetUserShare();
|
| - Directory* directory = user_share->directory.get();
|
| -
|
| - for (int i = syncer::FIRST_REAL_MODEL_TYPE;
|
| - i < syncer::MODEL_TYPE_COUNT; ++i) {
|
| - directory->set_initial_sync_ended_for_type(
|
| - syncer::ModelTypeFromInt(i), true);
|
| - }
|
| -}
|
| -
|
| void TestProfileSyncService::OnBackendInitialized(
|
| const syncer::WeakHandle<syncer::JsBackend>& backend,
|
| bool success) {
|
| - bool send_passphrase_required = false;
|
| - if (success) {
|
| - // Set this so below code can access GetUserShare().
|
| - backend_initialized_ = true;
|
| -
|
| - // Set up any nodes the test wants around before model association.
|
| - if (!callback_.is_null()) {
|
| - callback_.Run();
|
| - callback_.Reset();
|
| - }
|
| -
|
| - // Pretend we downloaded initial updates and set initial sync ended bits
|
| - // if we were asked to.
|
| - if (set_initial_sync_ended_on_init_) {
|
| - UserShare* user_share = GetUserShare();
|
| - Directory* directory = user_share->directory.get();
|
| -
|
| - if (!directory->initial_sync_ended_for_type(syncer::NIGORI)) {
|
| - ProfileSyncServiceTestHelper::CreateRoot(
|
| - syncer::NIGORI, GetUserShare(),
|
| - id_factory());
|
| -
|
| - // A side effect of adding the NIGORI mode (normally done by the
|
| - // syncer) is a decryption attempt, which will fail the first time.
|
| - send_passphrase_required = true;
|
| - }
|
| -
|
| - SetInitialSyncEndedForAllTypes();
|
| - }
|
| - }
|
| -
|
| ProfileSyncService::OnBackendInitialized(backend, success);
|
| - if (success && send_passphrase_required)
|
| - OnPassphraseRequired(syncer::REASON_DECRYPTION, sync_pb::EncryptedData());
|
|
|
| // TODO(akalin): Figure out a better way to do this.
|
| if (synchronous_backend_initialization_) {
|
| @@ -215,6 +235,8 @@ void TestProfileSyncService::CreateBackend() {
|
| profile(),
|
| sync_prefs_.AsWeakPtr(),
|
| invalidator_storage_.AsWeakPtr(),
|
| + id_factory_,
|
| + callback_,
|
| set_initial_sync_ended_on_init_,
|
| synchronous_backend_initialization_,
|
| fail_initial_download_,
|
|
|