Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Unified Diff: chrome/browser/sync/test_profile_sync_service.cc

Issue 15421011: Use OAuth2 token for sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a183b7e761eb8b294b89c64379a2177ce4997aaa..6c002e9a09365accaf67055541b68ee42192aadf 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) {
+}
+
+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.
- MessageLoop::current()->Run();
+ message_loop_runner_->Run();
}
}
@@ -164,9 +187,10 @@ void SyncBackendHostForProfileSyncTest
debug_info_listener,
restored_types);
if (fail_initial_download_) {
+// HandleInitializationCompletedOnFrontendLoop(false);
tim (not reviewing) 2013/05/23 19:03:42 Tidy up.
pavely 2013/05/30 07:42:12 Done.
frontend()->OnSyncConfigureRetry();
if (synchronous_init_)
- MessageLoop::current()->Quit();
+ message_loop_runner_->Quit();
} else {
initial_download_closure_.Run();
initial_download_closure_.Reset();
@@ -219,7 +243,8 @@ TestProfileSyncService::TestProfileSyncService(
synchronous_sync_configuration_(false),
set_initial_sync_ended_on_init_(true),
fail_initial_download_(false),
- storage_option_(syncer::STORAGE_IN_MEMORY) {
+ storage_option_(syncer::STORAGE_IN_MEMORY),
+ message_loop_runner_() {
tim (not reviewing) 2013/05/23 19:03:42 Remove unnecessary initializer.
pavely 2013/05/30 07:42:12 Done.
SetSyncSetupCompleted();
}
@@ -244,6 +269,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);
tim (not reviewing) 2013/05/23 19:03:42 nit - indent is off (4 spaces).
pavely 2013/05/30 07:42:12 Done.
+ 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>&
@@ -255,7 +300,7 @@ void TestProfileSyncService::OnBackendInitialized(
// TODO(akalin): Figure out a better way to do this.
if (synchronous_backend_initialization_) {
- MessageLoop::current()->Quit();
+ message_loop_runner_.Quit();
tim (not reviewing) 2013/05/23 19:03:42 :/ This seems to make it worse than before, it's
}
}
@@ -294,5 +339,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());
tim (not reviewing) 2013/05/23 19:03:42 indent is off.
pavely 2013/05/30 07:42:12 Done.
+ return ProfileOAuth2TokenService::StartRequest(scopes, consumer);
+}
+
+ProfileKeyedService* FakeOAuth2TokenService::BuildTokenService(
+ content::BrowserContext* context) {
+ Profile* profile = static_cast<Profile*>(context);
+
+ FakeOAuth2TokenService* service =
+ new FakeOAuth2TokenService(profile->GetRequestContext());
+ service->Initialize(profile);
+ return service;
}

Powered by Google App Engine
This is Rietveld 408576698