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