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 6cd5ad55f55235654e101732d7cae1cdb2866bfc..063b8edd4cb67386b5a8412be6bcf9688cf43c6e 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::Closure& 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) {} |
@@ -94,6 +99,54 @@ 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(); |
+ } |
+ |
+ // 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, user_share, &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 = 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); |
+ } |
+} |
+ |
} // namespace browser_sync |
syncer::TestIdFactory* TestProfileSyncService::id_factory() { |
@@ -130,54 +183,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_) { |
@@ -196,6 +205,10 @@ void TestProfileSyncService::Observe( |
} |
} |
+UserShare* TestProfileSyncService::GetUserShare() const { |
+ return backend_->GetUserShare(); |
+} |
+ |
void TestProfileSyncService::dont_set_initial_sync_ended_on_init() { |
set_initial_sync_ended_on_init_ = false; |
} |
@@ -214,6 +227,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_, |