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 06d586a0400341f005d316d14909c04bd2e29d2d..30bb8c07c40e9bd0f31a2a43175323c01daaf003 100644 |
| --- a/chrome/browser/sync/test_profile_sync_service.cc |
| +++ b/chrome/browser/sync/test_profile_sync_service.cc |
| @@ -33,6 +33,27 @@ using syncer::PRIORITY_PREFERENCES; |
| namespace browser_sync { |
| +MessageLoopRunner::MessageLoopRunner() |
| +: running_(false) { |
| +} |
| + |
|
Andrew T Wilson (Slow)
2013/05/31 12:57:28
Doesn't MessageLoop already expose is_running()? C
pavely
2013/06/04 00:49:59
Thank you. I was reading through RunLoop trying to
|
| +MessageLoopRunner::~MessageLoopRunner() { |
| + DCHECK(!running_); |
| +} |
| + |
| +void MessageLoopRunner::Run() { |
| + if (running_) |
| + return; |
| + running_ = true; |
| + MessageLoop::current()->Run(); |
| + running_ = false; |
| +} |
| + |
| +void MessageLoopRunner::Quit() { |
| + if (running_) |
| + MessageLoop::current()->Quit(); |
| +} |
| + |
| SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
| Profile* profile, |
| const base::WeakPtr<SyncPrefs>& sync_prefs, |
| @@ -42,7 +63,8 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
| bool set_initial_sync_ended_on_init, |
| bool synchronous_init, |
| bool fail_initial_download, |
| - syncer::StorageOption storage_option) |
| + syncer::StorageOption storage_option, |
| + MessageLoopRunner* message_loop_runner) |
| : browser_sync::SyncBackendHost( |
| profile->GetDebugName(), profile, sync_prefs, invalidator_storage), |
| weak_ptr_factory_(this), |
| @@ -51,7 +73,8 @@ SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
| fail_initial_download_(fail_initial_download), |
| set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), |
| synchronous_init_(synchronous_init), |
| - storage_option_(storage_option) {} |
| + storage_option_(storage_option), |
| + message_loop_runner_(message_loop_runner) {} |
| SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
| @@ -88,7 +111,7 @@ void SyncBackendHostForProfileSyncTest::InitCore( |
| if (synchronous_init_) { |
| // The SyncBackend posts a task to the current loop when |
| // initialization completes. |
| - base::MessageLoop::current()->Run(); |
| + message_loop_runner_->Run(); |
| } |
| } |
| @@ -169,7 +192,7 @@ void SyncBackendHostForProfileSyncTest |
| if (fail_initial_download_) { |
| frontend()->OnSyncConfigureRetry(); |
| if (synchronous_init_) |
| - base::MessageLoop::current()->Quit(); |
| + message_loop_runner_->Quit(); |
| } else { |
| initial_download_closure_.Run(); |
| initial_download_closure_.Reset(); |
| @@ -247,6 +270,26 @@ TestProfileSyncService::components_factory_mock() { |
| return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); |
| } |
| +void TestProfileSyncService::RequestAccessToken( |
| + bool invalidate_previous_token, |
| + bool invoke_callback) { |
| + ProfileSyncService::RequestAccessToken(invalidate_previous_token, |
| + invoke_callback); |
| + if (synchronous_backend_initialization_ && invoke_callback) { |
| + message_loop_runner_.Run(); |
| + } |
| +} |
| + |
| +void TestProfileSyncService::OnGetTokenFailure( |
| + const OAuth2TokenService::Request* request, |
| + const GoogleServiceAuthError& error) { |
| + ProfileSyncService::OnGetTokenFailure(request, error); |
| + if (synchronous_backend_initialization_) { |
| + message_loop_runner_.Quit(); |
| + } |
| +} |
| + |
| + |
| void TestProfileSyncService::OnBackendInitialized( |
| const syncer::WeakHandle<syncer::JsBackend>& backend, |
| const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| @@ -258,7 +301,7 @@ void TestProfileSyncService::OnBackendInitialized( |
| // TODO(akalin): Figure out a better way to do this. |
| if (synchronous_backend_initialization_) { |
| - base::MessageLoop::current()->Quit(); |
| + message_loop_runner_.Quit(); |
| } |
| } |
| @@ -297,5 +340,26 @@ void TestProfileSyncService::CreateBackend() { |
| set_initial_sync_ended_on_init_, |
| synchronous_backend_initialization_, |
| fail_initial_download_, |
| - storage_option_)); |
| + storage_option_, |
| + &message_loop_runner_)); |
| +} |
| + |
| +scoped_ptr<OAuth2TokenService::Request> FakeOAuth2TokenService::StartRequest( |
| + const OAuth2TokenService::ScopeSet& scopes, |
| + OAuth2TokenService::Consumer* consumer) { |
| + // Ensure token in question is cached and never expires. Request will succeed |
| + // without network IO. |
| + RegisterCacheEntry(GetRefreshToken(), scopes, "access_token", |
| + base::Time::Max()); |
| + return ProfileOAuth2TokenService::StartRequest(scopes, consumer); |
| +} |
| + |
| +BrowserContextKeyedService* FakeOAuth2TokenService::BuildTokenService( |
| + content::BrowserContext* context) { |
| + Profile* profile = static_cast<Profile*>(context); |
| + |
| + FakeOAuth2TokenService* service = |
| + new FakeOAuth2TokenService(context->GetRequestContext()); |
| + service->Initialize(profile); |
| + return service; |
| } |