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 15 matching lines...) Expand all Loading... | |
| 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 | |
| 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<InvalidatorStorage>& invalidator_storage, | 60 const base::WeakPtr<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 Loading... | |
| 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 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 restored_types = syncer::ModelTypeSet::All(); | 180 restored_types = syncer::ModelTypeSet::All(); |
| 158 } | 181 } |
| 159 | 182 |
| 160 initial_download_closure_ = base::Bind( | 183 initial_download_closure_ = base::Bind( |
| 161 &SyncBackendHostForProfileSyncTest::ContinueInitialization, | 184 &SyncBackendHostForProfileSyncTest::ContinueInitialization, |
| 162 weak_ptr_factory_.GetWeakPtr(), | 185 weak_ptr_factory_.GetWeakPtr(), |
| 163 js_backend, | 186 js_backend, |
| 164 debug_info_listener, | 187 debug_info_listener, |
| 165 restored_types); | 188 restored_types); |
| 166 if (fail_initial_download_) { | 189 if (fail_initial_download_) { |
| 190 // HandleInitializationCompletedOnFrontendLoop(false); | |
|
tim (not reviewing)
2013/05/23 19:03:42
Tidy up.
pavely
2013/05/30 07:42:12
Done.
| |
| 167 frontend()->OnSyncConfigureRetry(); | 191 frontend()->OnSyncConfigureRetry(); |
| 168 if (synchronous_init_) | 192 if (synchronous_init_) |
| 169 MessageLoop::current()->Quit(); | 193 message_loop_runner_->Quit(); |
| 170 } else { | 194 } else { |
| 171 initial_download_closure_.Run(); | 195 initial_download_closure_.Run(); |
| 172 initial_download_closure_.Reset(); | 196 initial_download_closure_.Reset(); |
| 173 } | 197 } |
| 174 } | 198 } |
| 175 | 199 |
| 176 void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange( | 200 void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange( |
| 177 syncer::InvalidatorState state) { | 201 syncer::InvalidatorState state) { |
| 178 frontend()->OnInvalidatorStateChange(state); | 202 frontend()->OnInvalidatorStateChange(state); |
| 179 } | 203 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 bool synchronous_backend_initialization) | 236 bool synchronous_backend_initialization) |
| 213 : ProfileSyncService(factory, | 237 : ProfileSyncService(factory, |
| 214 profile, | 238 profile, |
| 215 signin, | 239 signin, |
| 216 behavior), | 240 behavior), |
| 217 synchronous_backend_initialization_( | 241 synchronous_backend_initialization_( |
| 218 synchronous_backend_initialization), | 242 synchronous_backend_initialization), |
| 219 synchronous_sync_configuration_(false), | 243 synchronous_sync_configuration_(false), |
| 220 set_initial_sync_ended_on_init_(true), | 244 set_initial_sync_ended_on_init_(true), |
| 221 fail_initial_download_(false), | 245 fail_initial_download_(false), |
| 222 storage_option_(syncer::STORAGE_IN_MEMORY) { | 246 storage_option_(syncer::STORAGE_IN_MEMORY), |
| 247 message_loop_runner_() { | |
|
tim (not reviewing)
2013/05/23 19:03:42
Remove unnecessary initializer.
pavely
2013/05/30 07:42:12
Done.
| |
| 223 SetSyncSetupCompleted(); | 248 SetSyncSetupCompleted(); |
| 224 } | 249 } |
| 225 | 250 |
| 226 TestProfileSyncService::~TestProfileSyncService() { | 251 TestProfileSyncService::~TestProfileSyncService() { |
| 227 } | 252 } |
| 228 | 253 |
| 229 // static | 254 // static |
| 230 ProfileKeyedService* TestProfileSyncService::BuildAutoStartAsyncInit( | 255 ProfileKeyedService* TestProfileSyncService::BuildAutoStartAsyncInit( |
| 231 content::BrowserContext* context) { | 256 content::BrowserContext* context) { |
| 232 Profile* profile = static_cast<Profile*>(context); | 257 Profile* profile = static_cast<Profile*>(context); |
| 233 SigninManagerBase* signin = | 258 SigninManagerBase* signin = |
| 234 SigninManagerFactory::GetForProfile(profile); | 259 SigninManagerFactory::GetForProfile(profile); |
| 235 ProfileSyncComponentsFactoryMock* factory = | 260 ProfileSyncComponentsFactoryMock* factory = |
| 236 new ProfileSyncComponentsFactoryMock(); | 261 new ProfileSyncComponentsFactoryMock(); |
| 237 return new TestProfileSyncService( | 262 return new TestProfileSyncService( |
| 238 factory, profile, signin, ProfileSyncService::AUTO_START, false); | 263 factory, profile, signin, ProfileSyncService::AUTO_START, false); |
| 239 } | 264 } |
| 240 | 265 |
| 241 ProfileSyncComponentsFactoryMock* | 266 ProfileSyncComponentsFactoryMock* |
| 242 TestProfileSyncService::components_factory_mock() { | 267 TestProfileSyncService::components_factory_mock() { |
| 243 // We always create a mock factory, see Build* routines. | 268 // We always create a mock factory, see Build* routines. |
| 244 return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); | 269 return static_cast<ProfileSyncComponentsFactoryMock*>(factory()); |
| 245 } | 270 } |
| 246 | 271 |
| 272 void TestProfileSyncService::RequestAccessToken( | |
| 273 bool invalidate_previous_token, | |
| 274 bool invoke_callback) { | |
| 275 ProfileSyncService::RequestAccessToken(invalidate_previous_token, | |
| 276 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.
| |
| 277 if (synchronous_backend_initialization_ && invoke_callback) { | |
| 278 message_loop_runner_.Run(); | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 void TestProfileSyncService::OnGetTokenFailure( | |
| 283 const OAuth2TokenService::Request* request, | |
| 284 const GoogleServiceAuthError& error) { | |
| 285 ProfileSyncService::OnGetTokenFailure(request, error); | |
| 286 if (synchronous_backend_initialization_) { | |
| 287 message_loop_runner_.Quit(); | |
| 288 } | |
| 289 } | |
| 290 | |
| 291 | |
| 247 void TestProfileSyncService::OnBackendInitialized( | 292 void TestProfileSyncService::OnBackendInitialized( |
| 248 const syncer::WeakHandle<syncer::JsBackend>& backend, | 293 const syncer::WeakHandle<syncer::JsBackend>& backend, |
| 249 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 294 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 250 debug_info_listener, | 295 debug_info_listener, |
| 251 bool success) { | 296 bool success) { |
| 252 ProfileSyncService::OnBackendInitialized(backend, | 297 ProfileSyncService::OnBackendInitialized(backend, |
| 253 debug_info_listener, | 298 debug_info_listener, |
| 254 success); | 299 success); |
| 255 | 300 |
| 256 // TODO(akalin): Figure out a better way to do this. | 301 // TODO(akalin): Figure out a better way to do this. |
| 257 if (synchronous_backend_initialization_) { | 302 if (synchronous_backend_initialization_) { |
| 258 MessageLoop::current()->Quit(); | 303 message_loop_runner_.Quit(); |
|
tim (not reviewing)
2013/05/23 19:03:42
:/ This seems to make it worse than before, it's
| |
| 259 } | 304 } |
| 260 } | 305 } |
| 261 | 306 |
| 262 void TestProfileSyncService::OnConfigureDone( | 307 void TestProfileSyncService::OnConfigureDone( |
| 263 const browser_sync::DataTypeManager::ConfigureResult& result) { | 308 const browser_sync::DataTypeManager::ConfigureResult& result) { |
| 264 ProfileSyncService::OnConfigureDone(result); | 309 ProfileSyncService::OnConfigureDone(result); |
| 265 if (!synchronous_sync_configuration_) | 310 if (!synchronous_sync_configuration_) |
| 266 MessageLoop::current()->Quit(); | 311 MessageLoop::current()->Quit(); |
| 267 } | 312 } |
| 268 | 313 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 287 void TestProfileSyncService::CreateBackend() { | 332 void TestProfileSyncService::CreateBackend() { |
| 288 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | 333 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
| 289 profile(), | 334 profile(), |
| 290 sync_prefs_.AsWeakPtr(), | 335 sync_prefs_.AsWeakPtr(), |
| 291 invalidator_storage_.AsWeakPtr(), | 336 invalidator_storage_.AsWeakPtr(), |
| 292 id_factory_, | 337 id_factory_, |
| 293 callback_, | 338 callback_, |
| 294 set_initial_sync_ended_on_init_, | 339 set_initial_sync_ended_on_init_, |
| 295 synchronous_backend_initialization_, | 340 synchronous_backend_initialization_, |
| 296 fail_initial_download_, | 341 fail_initial_download_, |
| 297 storage_option_)); | 342 storage_option_, |
| 343 &message_loop_runner_)); | |
| 298 } | 344 } |
| 345 | |
| 346 scoped_ptr<OAuth2TokenService::Request> FakeOAuth2TokenService::StartRequest( | |
| 347 const OAuth2TokenService::ScopeSet& scopes, | |
| 348 OAuth2TokenService::Consumer* consumer) { | |
| 349 // Ensure token in question is cached and never expires. Request will succeed | |
| 350 // without network IO. | |
| 351 RegisterCacheEntry(GetRefreshToken(), scopes, "access_token", | |
| 352 base::Time::Max()); | |
|
tim (not reviewing)
2013/05/23 19:03:42
indent is off.
pavely
2013/05/30 07:42:12
Done.
| |
| 353 return ProfileOAuth2TokenService::StartRequest(scopes, consumer); | |
| 354 } | |
| 355 | |
| 356 ProfileKeyedService* FakeOAuth2TokenService::BuildTokenService( | |
| 357 content::BrowserContext* context) { | |
| 358 Profile* profile = static_cast<Profile*>(context); | |
| 359 | |
| 360 FakeOAuth2TokenService* service = | |
| 361 new FakeOAuth2TokenService(profile->GetRequestContext()); | |
| 362 service->Initialize(profile); | |
| 363 return service; | |
| 364 } | |
| OLD | NEW |