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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return new TestProfileSyncService( | 242 return new TestProfileSyncService( |
243 factory, profile, signin, ProfileSyncService::AUTO_START, false); | 243 factory, profile, signin, ProfileSyncService::AUTO_START, false); |
244 } | 244 } |
245 | 245 |
246 ProfileSyncComponentsFactoryMock* | 246 ProfileSyncComponentsFactoryMock* |
247 TestProfileSyncService::components_factory_mock() { | 247 TestProfileSyncService::components_factory_mock() { |
248 // We always create a mock factory, see Build* routines. | 248 // We always create a mock factory, see Build* routines. |
249 return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); | 249 return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); |
250 } | 250 } |
251 | 251 |
| 252 void TestProfileSyncService::RequestAccessToken() { |
| 253 ProfileSyncService::RequestAccessToken(); |
| 254 if (synchronous_backend_initialization_) { |
| 255 base::MessageLoop::current()->Run(); |
| 256 } |
| 257 } |
| 258 |
| 259 void TestProfileSyncService::OnGetTokenFailure( |
| 260 const OAuth2TokenService::Request* request, |
| 261 const GoogleServiceAuthError& error) { |
| 262 ProfileSyncService::OnGetTokenFailure(request, error); |
| 263 if (synchronous_backend_initialization_) { |
| 264 base::MessageLoop::current()->Quit(); |
| 265 } |
| 266 } |
| 267 |
| 268 |
252 void TestProfileSyncService::OnBackendInitialized( | 269 void TestProfileSyncService::OnBackendInitialized( |
253 const syncer::WeakHandle<syncer::JsBackend>& backend, | 270 const syncer::WeakHandle<syncer::JsBackend>& backend, |
254 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 271 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
255 debug_info_listener, | 272 debug_info_listener, |
256 bool success) { | 273 bool success) { |
257 ProfileSyncService::OnBackendInitialized(backend, | 274 ProfileSyncService::OnBackendInitialized(backend, |
258 debug_info_listener, | 275 debug_info_listener, |
259 success); | 276 success); |
260 | 277 |
261 // TODO(akalin): Figure out a better way to do this. | 278 // TODO(akalin): Figure out a better way to do this. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 profile(), | 311 profile(), |
295 sync_prefs_.AsWeakPtr(), | 312 sync_prefs_.AsWeakPtr(), |
296 invalidator_storage_.AsWeakPtr(), | 313 invalidator_storage_.AsWeakPtr(), |
297 id_factory_, | 314 id_factory_, |
298 callback_, | 315 callback_, |
299 set_initial_sync_ended_on_init_, | 316 set_initial_sync_ended_on_init_, |
300 synchronous_backend_initialization_, | 317 synchronous_backend_initialization_, |
301 fail_initial_download_, | 318 fail_initial_download_, |
302 storage_option_)); | 319 storage_option_)); |
303 } | 320 } |
| 321 |
| 322 scoped_ptr<OAuth2TokenService::Request> FakeOAuth2TokenService::StartRequest( |
| 323 const OAuth2TokenService::ScopeSet& scopes, |
| 324 OAuth2TokenService::Consumer* consumer) { |
| 325 // Ensure token in question is cached and never expires. Request will succeed |
| 326 // without network IO. |
| 327 RegisterCacheEntry(GetRefreshToken(), scopes, "access_token", |
| 328 base::Time::Max()); |
| 329 return ProfileOAuth2TokenService::StartRequest(scopes, consumer); |
| 330 } |
| 331 |
| 332 BrowserContextKeyedService* FakeOAuth2TokenService::BuildTokenService( |
| 333 content::BrowserContext* context) { |
| 334 Profile* profile = static_cast<Profile*>(context); |
| 335 |
| 336 FakeOAuth2TokenService* service = |
| 337 new FakeOAuth2TokenService(context->GetRequestContext()); |
| 338 service->Initialize(profile); |
| 339 return service; |
| 340 } |
OLD | NEW |