Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 // first place, but SyncBackendHost will have created one by now so we must | 78 // first place, but SyncBackendHost will have created one by now so we must |
| 79 // free it. Grab the switches to pass on first. | 79 // free it. Grab the switches to pass on first. |
| 80 InternalComponentsFactory::Switches factory_switches = | 80 InternalComponentsFactory::Switches factory_switches = |
| 81 test_options.internal_components_factory->GetSwitches(); | 81 test_options.internal_components_factory->GetSwitches(); |
| 82 delete test_options.internal_components_factory; | 82 delete test_options.internal_components_factory; |
| 83 | 83 |
| 84 test_options.internal_components_factory = | 84 test_options.internal_components_factory = |
| 85 new TestInternalComponentsFactory(factory_switches, storage); | 85 new TestInternalComponentsFactory(factory_switches, storage); |
| 86 | 86 |
| 87 SyncBackendHost::InitCore(test_options); | 87 SyncBackendHost::InitCore(test_options); |
| 88 if (synchronous_init_) { | 88 if (synchronous_init_ && !base::MessageLoop::current()->is_running()) { |
| 89 // The SyncBackend posts a task to the current loop when | 89 // The SyncBackend posts a task to the current loop when |
| 90 // initialization completes. | 90 // initialization completes. |
| 91 base::MessageLoop::current()->Run(); | 91 base::MessageLoop::current()->Run(); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 void SyncBackendHostForProfileSyncTest::UpdateCredentials( | 95 void SyncBackendHostForProfileSyncTest::UpdateCredentials( |
| 96 const syncer::SyncCredentials& credentials) { | 96 const syncer::SyncCredentials& credentials) { |
| 97 // If we had failed the initial download, complete initialization now. | 97 // If we had failed the initial download, complete initialization now. |
| 98 if (!initial_download_closure_.is_null()) { | 98 if (!initial_download_closure_.is_null()) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 return new TestProfileSyncService( | 240 return new TestProfileSyncService( |
| 241 factory, profile, signin, ProfileSyncService::AUTO_START, false); | 241 factory, profile, signin, ProfileSyncService::AUTO_START, false); |
| 242 } | 242 } |
| 243 | 243 |
| 244 ProfileSyncComponentsFactoryMock* | 244 ProfileSyncComponentsFactoryMock* |
| 245 TestProfileSyncService::components_factory_mock() { | 245 TestProfileSyncService::components_factory_mock() { |
| 246 // We always create a mock factory, see Build* routines. | 246 // We always create a mock factory, see Build* routines. |
| 247 return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); | 247 return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void TestProfileSyncService::RequestAccessToken() { | |
| 251 ProfileSyncService::RequestAccessToken(); | |
| 252 if (synchronous_backend_initialization_) { | |
| 253 base::MessageLoop::current()->Run(); | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 void TestProfileSyncService::OnGetTokenFailure( | |
| 258 const OAuth2TokenService::Request* request, | |
| 259 const GoogleServiceAuthError& error) { | |
| 260 ProfileSyncService::OnGetTokenFailure(request, error); | |
| 261 if (synchronous_backend_initialization_) { | |
| 262 base::MessageLoop::current()->Quit(); | |
|
Andrew T Wilson (Slow)
2013/06/04 14:37:32
Should we also add an OnGetTokenSuccess() loop tha
pavely
2013/06/04 20:11:13
In success case TryStart will be called and will r
| |
| 263 } | |
| 264 } | |
| 265 | |
| 266 | |
| 250 void TestProfileSyncService::OnBackendInitialized( | 267 void TestProfileSyncService::OnBackendInitialized( |
| 251 const syncer::WeakHandle<syncer::JsBackend>& backend, | 268 const syncer::WeakHandle<syncer::JsBackend>& backend, |
| 252 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 269 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 253 debug_info_listener, | 270 debug_info_listener, |
| 254 bool success) { | 271 bool success) { |
| 255 ProfileSyncService::OnBackendInitialized(backend, | 272 ProfileSyncService::OnBackendInitialized(backend, |
| 256 debug_info_listener, | 273 debug_info_listener, |
| 257 success); | 274 success); |
| 258 | 275 |
| 259 // TODO(akalin): Figure out a better way to do this. | 276 // TODO(akalin): Figure out a better way to do this. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 profile(), | 309 profile(), |
| 293 sync_prefs_.AsWeakPtr(), | 310 sync_prefs_.AsWeakPtr(), |
| 294 invalidator_storage_.AsWeakPtr(), | 311 invalidator_storage_.AsWeakPtr(), |
| 295 id_factory_, | 312 id_factory_, |
| 296 callback_, | 313 callback_, |
| 297 set_initial_sync_ended_on_init_, | 314 set_initial_sync_ended_on_init_, |
| 298 synchronous_backend_initialization_, | 315 synchronous_backend_initialization_, |
| 299 fail_initial_download_, | 316 fail_initial_download_, |
| 300 storage_option_)); | 317 storage_option_)); |
| 301 } | 318 } |
| 319 | |
| 320 scoped_ptr<OAuth2TokenService::Request> FakeOAuth2TokenService::StartRequest( | |
| 321 const OAuth2TokenService::ScopeSet& scopes, | |
| 322 OAuth2TokenService::Consumer* consumer) { | |
| 323 // Ensure token in question is cached and never expires. Request will succeed | |
| 324 // without network IO. | |
| 325 RegisterCacheEntry(GetRefreshToken(), scopes, "access_token", | |
| 326 base::Time::Max()); | |
| 327 return ProfileOAuth2TokenService::StartRequest(scopes, consumer); | |
| 328 } | |
| 329 | |
| 330 BrowserContextKeyedService* FakeOAuth2TokenService::BuildTokenService( | |
| 331 content::BrowserContext* context) { | |
| 332 Profile* profile = static_cast<Profile*>(context); | |
| 333 | |
| 334 FakeOAuth2TokenService* service = | |
| 335 new FakeOAuth2TokenService(context->GetRequestContext()); | |
| 336 service->Initialize(profile); | |
| 337 return service; | |
| 338 } | |
| OLD | NEW |