| 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 18 matching lines...) Expand all Loading... |
| 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 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( | 36 SyncBackendHostForProfileSyncTest::SyncBackendHostForProfileSyncTest( |
| 37 Profile* profile, | 37 Profile* profile, |
| 38 const base::WeakPtr<SyncPrefs>& sync_prefs, | 38 const base::WeakPtr<SyncPrefs>& sync_prefs, |
| 39 const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage, | |
| 40 syncer::TestIdFactory& id_factory, | 39 syncer::TestIdFactory& id_factory, |
| 41 base::Closure& callback, | 40 base::Closure& callback, |
| 42 bool set_initial_sync_ended_on_init, | 41 bool set_initial_sync_ended_on_init, |
| 43 bool synchronous_init, | 42 bool synchronous_init, |
| 44 bool fail_initial_download, | 43 bool fail_initial_download, |
| 45 syncer::StorageOption storage_option) | 44 syncer::StorageOption storage_option) |
| 46 : browser_sync::SyncBackendHost( | 45 : browser_sync::SyncBackendHost( |
| 47 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), | 46 profile->GetDebugName(), profile, sync_prefs), |
| 48 weak_ptr_factory_(this), | 47 weak_ptr_factory_(this), |
| 49 id_factory_(id_factory), | 48 id_factory_(id_factory), |
| 50 callback_(callback), | 49 callback_(callback), |
| 51 fail_initial_download_(fail_initial_download), | 50 fail_initial_download_(fail_initial_download), |
| 52 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), | 51 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), |
| 53 synchronous_init_(synchronous_init), | 52 synchronous_init_(synchronous_init), |
| 54 storage_option_(storage_option) {} | 53 storage_option_(storage_option) {} |
| 55 | 54 |
| 56 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} | 55 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
| 57 | 56 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 syncer::ModelTypeSet to_unapply, | 107 syncer::ModelTypeSet to_unapply, |
| 109 syncer::ModelTypeSet to_ignore, | 108 syncer::ModelTypeSet to_ignore, |
| 110 const syncer::ModelSafeRoutingInfo& routing_info, | 109 const syncer::ModelSafeRoutingInfo& routing_info, |
| 111 const base::Callback<void(syncer::ModelTypeSet, | 110 const base::Callback<void(syncer::ModelTypeSet, |
| 112 syncer::ModelTypeSet)>& ready_task, | 111 syncer::ModelTypeSet)>& ready_task, |
| 113 const base::Closure& retry_callback) { | 112 const base::Closure& retry_callback) { |
| 114 syncer::ModelTypeSet failed_configuration_types; | 113 syncer::ModelTypeSet failed_configuration_types; |
| 115 if (fail_initial_download_) | 114 if (fail_initial_download_) |
| 116 failed_configuration_types = to_download; | 115 failed_configuration_types = to_download; |
| 117 | 116 |
| 117 // The first parameter there should be the set of enabled types. That's not |
| 118 // something we have access to from this strange test harness. We'll just |
| 119 // send back the list of newly configured types instead and hope it doesn't |
| 120 // break anything. |
| 118 FinishConfigureDataTypesOnFrontendLoop( | 121 FinishConfigureDataTypesOnFrontendLoop( |
| 119 syncer::Difference(to_download, failed_configuration_types), | 122 syncer::Difference(to_download, failed_configuration_types), |
| 123 syncer::Difference(to_download, failed_configuration_types), |
| 120 failed_configuration_types, | 124 failed_configuration_types, |
| 121 ready_task); | 125 ready_task); |
| 122 } | 126 } |
| 123 | 127 |
| 124 void SyncBackendHostForProfileSyncTest | 128 void SyncBackendHostForProfileSyncTest |
| 125 ::HandleSyncManagerInitializationOnFrontendLoop( | 129 ::HandleSyncManagerInitializationOnFrontendLoop( |
| 126 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 130 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 127 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 131 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 128 debug_info_listener, | 132 debug_info_listener, |
| 129 syncer::ModelTypeSet restored_types) { | 133 syncer::ModelTypeSet restored_types) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (fail_initial_download_) { | 175 if (fail_initial_download_) { |
| 172 frontend()->OnSyncConfigureRetry(); | 176 frontend()->OnSyncConfigureRetry(); |
| 173 if (synchronous_init_) | 177 if (synchronous_init_) |
| 174 base::MessageLoop::current()->Quit(); | 178 base::MessageLoop::current()->Quit(); |
| 175 } else { | 179 } else { |
| 176 initial_download_closure_.Run(); | 180 initial_download_closure_.Run(); |
| 177 initial_download_closure_.Reset(); | 181 initial_download_closure_.Reset(); |
| 178 } | 182 } |
| 179 } | 183 } |
| 180 | 184 |
| 181 void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange( | |
| 182 syncer::InvalidatorState state) { | |
| 183 frontend()->OnInvalidatorStateChange(state); | |
| 184 } | |
| 185 | |
| 186 void SyncBackendHostForProfileSyncTest::EmitOnIncomingInvalidation( | |
| 187 const syncer::ObjectIdInvalidationMap& invalidation_map) { | |
| 188 frontend()->OnIncomingInvalidation(invalidation_map); | |
| 189 } | |
| 190 | |
| 191 void SyncBackendHostForProfileSyncTest::ContinueInitialization( | 185 void SyncBackendHostForProfileSyncTest::ContinueInitialization( |
| 192 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 186 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 193 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 187 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 194 debug_info_listener, | 188 debug_info_listener, |
| 195 syncer::ModelTypeSet restored_types) { | 189 syncer::ModelTypeSet restored_types) { |
| 196 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( | 190 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
| 197 js_backend, debug_info_listener, restored_types); | 191 js_backend, debug_info_listener, restored_types); |
| 198 } | 192 } |
| 199 | 193 |
| 200 } // namespace browser_sync | 194 } // namespace browser_sync |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 297 } |
| 304 void TestProfileSyncService::set_storage_option( | 298 void TestProfileSyncService::set_storage_option( |
| 305 syncer::StorageOption storage_option) { | 299 syncer::StorageOption storage_option) { |
| 306 storage_option_ = storage_option; | 300 storage_option_ = storage_option; |
| 307 } | 301 } |
| 308 | 302 |
| 309 void TestProfileSyncService::CreateBackend() { | 303 void TestProfileSyncService::CreateBackend() { |
| 310 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( | 304 backend_.reset(new browser_sync::SyncBackendHostForProfileSyncTest( |
| 311 profile(), | 305 profile(), |
| 312 sync_prefs_.AsWeakPtr(), | 306 sync_prefs_.AsWeakPtr(), |
| 313 invalidator_storage_.AsWeakPtr(), | |
| 314 id_factory_, | 307 id_factory_, |
| 315 callback_, | 308 callback_, |
| 316 set_initial_sync_ended_on_init_, | 309 set_initial_sync_ended_on_init_, |
| 317 synchronous_backend_initialization_, | 310 synchronous_backend_initialization_, |
| 318 fail_initial_download_, | 311 fail_initial_download_, |
| 319 storage_option_)); | 312 storage_option_)); |
| 320 } | 313 } |
| 321 | 314 |
| 322 scoped_ptr<OAuth2TokenService::Request> FakeOAuth2TokenService::StartRequest( | 315 scoped_ptr<OAuth2TokenService::Request> FakeOAuth2TokenService::StartRequest( |
| 323 const OAuth2TokenService::ScopeSet& scopes, | 316 const OAuth2TokenService::ScopeSet& scopes, |
| 324 OAuth2TokenService::Consumer* consumer) { | 317 OAuth2TokenService::Consumer* consumer) { |
| 325 // Ensure token in question is cached and never expires. Request will succeed | 318 // Ensure token in question is cached and never expires. Request will succeed |
| 326 // without network IO. | 319 // without network IO. |
| 327 RegisterCacheEntry(GetRefreshToken(), scopes, "access_token", | 320 RegisterCacheEntry(GetRefreshToken(), scopes, "access_token", |
| 328 base::Time::Max()); | 321 base::Time::Max()); |
| 329 return ProfileOAuth2TokenService::StartRequest(scopes, consumer); | 322 return ProfileOAuth2TokenService::StartRequest(scopes, consumer); |
| 330 } | 323 } |
| 331 | 324 |
| 332 BrowserContextKeyedService* FakeOAuth2TokenService::BuildTokenService( | 325 BrowserContextKeyedService* FakeOAuth2TokenService::BuildTokenService( |
| 333 content::BrowserContext* context) { | 326 content::BrowserContext* context) { |
| 334 Profile* profile = static_cast<Profile*>(context); | 327 Profile* profile = static_cast<Profile*>(context); |
| 335 | 328 |
| 336 FakeOAuth2TokenService* service = | 329 FakeOAuth2TokenService* service = |
| 337 new FakeOAuth2TokenService(context->GetRequestContext()); | 330 new FakeOAuth2TokenService(context->GetRequestContext()); |
| 338 service->Initialize(profile); | 331 service->Initialize(profile); |
| 339 return service; | 332 return service; |
| 340 } | 333 } |
| OLD | NEW |