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

Side by Side 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: Fix issues based on feedback Created 7 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/test_profile_sync_service.h" 5 #include "chrome/browser/sync/test_profile_sync_service.h"
6 6
7 #include "chrome/browser/signin/signin_manager.h" 7 #include "chrome/browser/signin/signin_manager.h"
8 #include "chrome/browser/signin/signin_manager_factory.h" 8 #include "chrome/browser/signin/signin_manager_factory.h"
9 #include "chrome/browser/sync/glue/data_type_controller.h" 9 #include "chrome/browser/sync/glue/data_type_controller.h"
10 #include "chrome/browser/sync/glue/sync_backend_host.h" 10 #include "chrome/browser/sync/glue/sync_backend_host.h"
(...skipping 15 matching lines...) Expand all
26 using syncer::sessions::SyncSourceInfo; 26 using syncer::sessions::SyncSourceInfo;
27 using syncer::UserShare; 27 using syncer::UserShare;
28 using syncer::syncable::Directory; 28 using syncer::syncable::Directory;
29 using syncer::DEVICE_INFO; 29 using syncer::DEVICE_INFO;
30 using syncer::EXPERIMENTS; 30 using syncer::EXPERIMENTS;
31 using syncer::NIGORI; 31 using syncer::NIGORI;
32 using syncer::PRIORITY_PREFERENCES; 32 using syncer::PRIORITY_PREFERENCES;
33 33
34 namespace browser_sync { 34 namespace browser_sync {
35 35
36 MessageLoopRunner::MessageLoopRunner()
37 : running_(false) {
38 }
39
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
40 MessageLoopRunner::~MessageLoopRunner() {
41 DCHECK(!running_);
42 }
43
44 void MessageLoopRunner::Run() {
45 if (running_)
46 return;
47 running_ = true;
48 MessageLoop::current()->Run();
49 running_ = false;
50 }
51
52 void MessageLoopRunner::Quit() {
53 if (running_)
54 MessageLoop::current()->Quit();
55 }
56
36 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( 57 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest(
37 Profile* profile, 58 Profile* profile,
38 const base::WeakPtr<SyncPrefs>& sync_prefs, 59 const base::WeakPtr<SyncPrefs>& sync_prefs,
39 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage, 60 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage,
40 syncer::TestIdFactory& id_factory, 61 syncer::TestIdFactory& id_factory,
41 base::Closure& callback, 62 base::Closure& callback,
42 bool set_initial_sync_ended_on_init, 63 bool set_initial_sync_ended_on_init,
43 bool synchronous_init, 64 bool synchronous_init,
44 bool fail_initial_download, 65 bool fail_initial_download,
45 syncer::StorageOption storage_option) 66 syncer::StorageOption storage_option,
67 MessageLoopRunner* message_loop_runner)
46 : browser_sync::SyncBackendHost( 68 : browser_sync::SyncBackendHost(
47 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), 69 profile->GetDebugName(), profile, sync_prefs, invalidator_storage),
48 weak_ptr_factory_(this), 70 weak_ptr_factory_(this),
49 id_factory_(id_factory), 71 id_factory_(id_factory),
50 callback_(callback), 72 callback_(callback),
51 fail_initial_download_(fail_initial_download), 73 fail_initial_download_(fail_initial_download),
52 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), 74 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init),
53 synchronous_init_(synchronous_init), 75 synchronous_init_(synchronous_init),
54 storage_option_(storage_option) {} 76 storage_option_(storage_option),
77 message_loop_runner_(message_loop_runner) {}
55 78
56 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} 79 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {}
57 80
58 namespace { 81 namespace {
59 82
60 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { 83 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() {
61 return scoped_ptr<syncer::HttpPostProviderFactory>( 84 return scoped_ptr<syncer::HttpPostProviderFactory>(
62 new browser_sync::TestHttpBridgeFactory()); 85 new browser_sync::TestHttpBridgeFactory());
63 } 86 }
64 87
(...skipping 16 matching lines...) Expand all
81 test_options.internal_components_factory->GetSwitches(); 104 test_options.internal_components_factory->GetSwitches();
82 delete test_options.internal_components_factory; 105 delete test_options.internal_components_factory;
83 106
84 test_options.internal_components_factory = 107 test_options.internal_components_factory =
85 new TestInternalComponentsFactory(factory_switches, storage); 108 new TestInternalComponentsFactory(factory_switches, storage);
86 109
87 SyncBackendHost::InitCore(test_options); 110 SyncBackendHost::InitCore(test_options);
88 if (synchronous_init_) { 111 if (synchronous_init_) {
89 // The SyncBackend posts a task to the current loop when 112 // The SyncBackend posts a task to the current loop when
90 // initialization completes. 113 // initialization completes.
91 base::MessageLoop::current()->Run(); 114 message_loop_runner_->Run();
92 } 115 }
93 } 116 }
94 117
95 void SyncBackendHostForProfileSyncTest::UpdateCredentials( 118 void SyncBackendHostForProfileSyncTest::UpdateCredentials(
96 const syncer::SyncCredentials& credentials) { 119 const syncer::SyncCredentials& credentials) {
97 // If we had failed the initial download, complete initialization now. 120 // If we had failed the initial download, complete initialization now.
98 if (!initial_download_closure_.is_null()) { 121 if (!initial_download_closure_.is_null()) {
99 initial_download_closure_.Run(); 122 initial_download_closure_.Run();
100 initial_download_closure_.Reset(); 123 initial_download_closure_.Reset();
101 } 124 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 185
163 initial_download_closure_ = base::Bind( 186 initial_download_closure_ = base::Bind(
164 &SyncBackendHostForProfileSyncTest::ContinueInitialization, 187 &SyncBackendHostForProfileSyncTest::ContinueInitialization,
165 weak_ptr_factory_.GetWeakPtr(), 188 weak_ptr_factory_.GetWeakPtr(),
166 js_backend, 189 js_backend,
167 debug_info_listener, 190 debug_info_listener,
168 restored_types); 191 restored_types);
169 if (fail_initial_download_) { 192 if (fail_initial_download_) {
170 frontend()->OnSyncConfigureRetry(); 193 frontend()->OnSyncConfigureRetry();
171 if (synchronous_init_) 194 if (synchronous_init_)
172 base::MessageLoop::current()->Quit(); 195 message_loop_runner_->Quit();
173 } else { 196 } else {
174 initial_download_closure_.Run(); 197 initial_download_closure_.Run();
175 initial_download_closure_.Reset(); 198 initial_download_closure_.Reset();
176 } 199 }
177 } 200 }
178 201
179 void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange( 202 void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange(
180 syncer::InvalidatorState state) { 203 syncer::InvalidatorState state) {
181 frontend()->OnInvalidatorStateChange(state); 204 frontend()->OnInvalidatorStateChange(state);
182 } 205 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return new TestProfileSyncService( 263 return new TestProfileSyncService(
241 factory, profile, signin, ProfileSyncService::AUTO_START, false); 264 factory, profile, signin, ProfileSyncService::AUTO_START, false);
242 } 265 }
243 266
244 ProfileSyncComponentsFactoryMock* 267 ProfileSyncComponentsFactoryMock*
245 TestProfileSyncService::components_factory_mock() { 268 TestProfileSyncService::components_factory_mock() {
246 // We always create a mock factory, see Build* routines. 269 // We always create a mock factory, see Build* routines.
247 return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); 270 return static_cast<ProfileSyncComponentsFactoryMock*>(factory());
248 } 271 }
249 272
273 void TestProfileSyncService::RequestAccessToken(
274 bool invalidate_previous_token,
275 bool invoke_callback) {
276 ProfileSyncService::RequestAccessToken(invalidate_previous_token,
277 invoke_callback);
278 if (synchronous_backend_initialization_ && invoke_callback) {
279 message_loop_runner_.Run();
280 }
281 }
282
283 void TestProfileSyncService::OnGetTokenFailure(
284 const OAuth2TokenService::Request* request,
285 const GoogleServiceAuthError& error) {
286 ProfileSyncService::OnGetTokenFailure(request, error);
287 if (synchronous_backend_initialization_) {
288 message_loop_runner_.Quit();
289 }
290 }
291
292
250 void TestProfileSyncService::OnBackendInitialized( 293 void TestProfileSyncService::OnBackendInitialized(
251 const syncer::WeakHandle<syncer::JsBackend>& backend, 294 const syncer::WeakHandle<syncer::JsBackend>& backend,
252 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 295 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
253 debug_info_listener, 296 debug_info_listener,
254 bool success) { 297 bool success) {
255 ProfileSyncService::OnBackendInitialized(backend, 298 ProfileSyncService::OnBackendInitialized(backend,
256 debug_info_listener, 299 debug_info_listener,
257 success); 300 success);
258 301
259 // TODO(akalin): Figure out a better way to do this. 302 // TODO(akalin): Figure out a better way to do this.
260 if (synchronous_backend_initialization_) { 303 if (synchronous_backend_initialization_) {
261 base::MessageLoop::current()->Quit(); 304 message_loop_runner_.Quit();
262 } 305 }
263 } 306 }
264 307
265 void TestProfileSyncService::OnConfigureDone( 308 void TestProfileSyncService::OnConfigureDone(
266 const browser_sync::DataTypeManager::ConfigureResult& result) { 309 const browser_sync::DataTypeManager::ConfigureResult& result) {
267 ProfileSyncService::OnConfigureDone(result); 310 ProfileSyncService::OnConfigureDone(result);
268 if (!synchronous_sync_configuration_) 311 if (!synchronous_sync_configuration_)
269 base::MessageLoop::current()->Quit(); 312 base::MessageLoop::current()->Quit();
270 } 313 }
271 314
(...skipping 18 matching lines...) Expand all
290 void TestProfileSyncService::CreateBackend() { 333 void TestProfileSyncService::CreateBackend() {
291 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( 334 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest(
292 profile(), 335 profile(),
293 sync_prefs_.AsWeakPtr(), 336 sync_prefs_.AsWeakPtr(),
294 invalidator_storage_.AsWeakPtr(), 337 invalidator_storage_.AsWeakPtr(),
295 id_factory_, 338 id_factory_,
296 callback_, 339 callback_,
297 set_initial_sync_ended_on_init_, 340 set_initial_sync_ended_on_init_,
298 synchronous_backend_initialization_, 341 synchronous_backend_initialization_,
299 fail_initial_download_, 342 fail_initial_download_,
300 storage_option_)); 343 storage_option_,
344 &message_loop_runner_));
301 } 345 }
346
347 scoped_ptr<OAuth2TokenService::Request> FakeOAuth2TokenService::StartRequest(
348 const OAuth2TokenService::ScopeSet& scopes,
349 OAuth2TokenService::Consumer* consumer) {
350 // Ensure token in question is cached and never expires. Request will succeed
351 // without network IO.
352 RegisterCacheEntry(GetRefreshToken(), scopes, "access_token",
353 base::Time::Max());
354 return ProfileOAuth2TokenService::StartRequest(scopes, consumer);
355 }
356
357 BrowserContextKeyedService* FakeOAuth2TokenService::BuildTokenService(
358 content::BrowserContext* context) {
359 Profile* profile = static_cast<Profile*>(context);
360
361 FakeOAuth2TokenService* service =
362 new FakeOAuth2TokenService(context->GetRequestContext());
363 service->Initialize(profile);
364 return service;
365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698