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