Chromium Code Reviews| 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 2738fbb2d65f1b0b877741f64151d64c8d858dee..f4a9d4bd6df48f5457fad4fe4139667c68b763ac 100644 |
| --- a/chrome/browser/sync/test_profile_sync_service.cc |
| +++ b/chrome/browser/sync/test_profile_sync_service.cc |
| @@ -30,12 +30,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) {} |
| @@ -86,6 +91,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()); |
|
tim (not reviewing)
2012/07/20 21:00:57
Plumbing the UserShare* around sure got a bit mess
rlarocque
2012/07/20 21:17:59
The main problem is that that no one is allowed to
tim (not reviewing)
2012/07/23 20:33:19
I agree it's good to keep the DCHECKs in the gener
rlarocque
2012/07/23 20:50:30
The callbacks only have access to a TestProfileSyn
tim (not reviewing)
2012/07/23 21:01:58
Yeah, I think it would be too (my initial comment
|
| + 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() { |
| @@ -98,13 +153,22 @@ browser_sync::SyncBackendHostForProfileSyncTest* |
| ProfileSyncService::GetBackendForTest()); |
| } |
| +static void DoNothingCallback(syncer::UserShare*) { |
|
tim (not reviewing)
2012/07/20 21:00:57
I think you can get rid of this (and more boilerpl
|
| +} |
| + |
| +// 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, |
| @@ -122,54 +186,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_) { |
| @@ -206,6 +226,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_, |