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/sync/glue/data_type_controller.h" | 8 #include "chrome/browser/sync/glue/data_type_controller.h" |
9 #include "chrome/browser/sync/glue/sync_backend_host.h" | 9 #include "chrome/browser/sync/glue/sync_backend_host.h" |
10 #include "chrome/browser/sync/profile_sync_components_factory.h" | 10 #include "chrome/browser/sync/profile_sync_components_factory.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const base::WeakPtr<SyncPrefs>& sync_prefs, | 36 const base::WeakPtr<SyncPrefs>& sync_prefs, |
37 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, | 37 const base::WeakPtr<InvalidatorStorage>& invalidator_storage, |
38 syncer::TestIdFactory& id_factory, | 38 syncer::TestIdFactory& id_factory, |
39 base::Closure& callback, | 39 base::Closure& callback, |
40 bool set_initial_sync_ended_on_init, | 40 bool set_initial_sync_ended_on_init, |
41 bool synchronous_init, | 41 bool synchronous_init, |
42 bool fail_initial_download, | 42 bool fail_initial_download, |
43 syncer::StorageOption storage_option) | 43 syncer::StorageOption storage_option) |
44 : browser_sync::SyncBackendHost( | 44 : browser_sync::SyncBackendHost( |
45 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), | 45 profile->GetDebugName(), profile, sync_prefs, invalidator_storage), |
| 46 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
46 id_factory_(id_factory), | 47 id_factory_(id_factory), |
47 callback_(callback), | 48 callback_(callback), |
| 49 fail_initial_download_(fail_initial_download), |
48 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), | 50 set_initial_sync_ended_on_init_(set_initial_sync_ended_on_init), |
49 synchronous_init_(synchronous_init), | 51 synchronous_init_(synchronous_init), |
50 fail_initial_download_(fail_initial_download), | |
51 storage_option_(storage_option) {} | 52 storage_option_(storage_option) {} |
52 | 53 |
53 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} | 54 SyncBackendHostForProfileSyncTest::~SyncBackendHostForProfileSyncTest() {} |
54 | 55 |
55 namespace { | 56 namespace { |
56 | 57 |
57 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { | 58 scoped_ptr<syncer::HttpPostProviderFactory> MakeTestHttpBridgeFactory() { |
58 return scoped_ptr<syncer::HttpPostProviderFactory>( | 59 return scoped_ptr<syncer::HttpPostProviderFactory>( |
59 new browser_sync::TestHttpBridgeFactory()); | 60 new browser_sync::TestHttpBridgeFactory()); |
60 } | 61 } |
(...skipping 21 matching lines...) Expand all Loading... |
82 new TestInternalComponentsFactory(factory_switches, storage); | 83 new TestInternalComponentsFactory(factory_switches, storage); |
83 | 84 |
84 SyncBackendHost::InitCore(test_options); | 85 SyncBackendHost::InitCore(test_options); |
85 if (synchronous_init_) { | 86 if (synchronous_init_) { |
86 // The SyncBackend posts a task to the current loop when | 87 // The SyncBackend posts a task to the current loop when |
87 // initialization completes. | 88 // initialization completes. |
88 MessageLoop::current()->Run(); | 89 MessageLoop::current()->Run(); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
| 93 void SyncBackendHostForProfileSyncTest::UpdateCredentials( |
| 94 const syncer::SyncCredentials& credentials) { |
| 95 // If we had failed the initial download, complete initialization now. |
| 96 if (!initial_download_closure_.is_null()) { |
| 97 initial_download_closure_.Run(); |
| 98 initial_download_closure_.Reset(); |
| 99 } |
| 100 } |
| 101 |
92 void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer( | 102 void SyncBackendHostForProfileSyncTest::RequestConfigureSyncer( |
93 syncer::ConfigureReason reason, | 103 syncer::ConfigureReason reason, |
94 syncer::ModelTypeSet types_to_config, | 104 syncer::ModelTypeSet types_to_config, |
95 const syncer::ModelSafeRoutingInfo& routing_info, | 105 const syncer::ModelSafeRoutingInfo& routing_info, |
96 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 106 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
97 const base::Closure& retry_callback) { | 107 const base::Closure& retry_callback) { |
98 syncer::ModelTypeSet failed_configuration_types; | 108 syncer::ModelTypeSet failed_configuration_types; |
99 if (fail_initial_download_) | 109 if (fail_initial_download_) |
100 failed_configuration_types = types_to_config; | 110 failed_configuration_types = types_to_config; |
101 | 111 |
102 FinishConfigureDataTypesOnFrontendLoop(failed_configuration_types, | 112 FinishConfigureDataTypesOnFrontendLoop(failed_configuration_types, |
103 ready_task); | 113 ready_task); |
104 } | 114 } |
105 | 115 |
106 void SyncBackendHostForProfileSyncTest | 116 void SyncBackendHostForProfileSyncTest |
107 ::HandleSyncManagerInitializationOnFrontendLoop( | 117 ::HandleSyncManagerInitializationOnFrontendLoop( |
108 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 118 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
109 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 119 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
110 debug_info_listener, | 120 debug_info_listener, |
111 syncer::ModelTypeSet restored_types) { | 121 syncer::ModelTypeSet restored_types) { |
112 // Here's our opportunity to pretend to do things that the SyncManager would | 122 // Here's our opportunity to pretend to do things that the SyncManager would |
113 // normally do during initialization, but can't because this is a test. | 123 // normally do during initialization, but can't because this is a test. |
114 // Set up any nodes the test wants around before model association. | 124 // Set up any nodes the test wants around before model association. |
115 if (!callback_.is_null()) { | 125 if (!callback_.is_null()) { |
116 callback_.Run(); | 126 callback_.Run(); |
117 } | 127 } |
(...skipping 16 matching lines...) Expand all Loading... |
134 } | 144 } |
135 | 145 |
136 if (!directory->initial_sync_ended_for_type(EXPERIMENTS)) { | 146 if (!directory->initial_sync_ended_for_type(EXPERIMENTS)) { |
137 syncer::TestUserShare::CreateRoot(EXPERIMENTS, user_share); | 147 syncer::TestUserShare::CreateRoot(EXPERIMENTS, user_share); |
138 } | 148 } |
139 | 149 |
140 SetInitialSyncEndedForAllTypes(); | 150 SetInitialSyncEndedForAllTypes(); |
141 restored_types = syncer::ModelTypeSet::All(); | 151 restored_types = syncer::ModelTypeSet::All(); |
142 } | 152 } |
143 | 153 |
144 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( | 154 initial_download_closure_ = base::Bind( |
145 js_backend, debug_info_listener, restored_types); | 155 &SyncBackendHostForProfileSyncTest::ContinueInitialization, |
| 156 weak_ptr_factory_.GetWeakPtr(), |
| 157 js_backend, |
| 158 debug_info_listener, |
| 159 restored_types); |
| 160 if (fail_initial_download_) { |
| 161 frontend()->OnSyncConfigureRetry(); |
| 162 if (synchronous_init_) |
| 163 MessageLoop::current()->Quit(); |
| 164 } else { |
| 165 initial_download_closure_.Run(); |
| 166 initial_download_closure_.Reset(); |
| 167 } |
146 } | 168 } |
147 | 169 |
148 void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForAllTypes() { | 170 void SyncBackendHostForProfileSyncTest::SetInitialSyncEndedForAllTypes() { |
149 UserShare* user_share = GetUserShare(); | 171 UserShare* user_share = GetUserShare(); |
150 Directory* directory = user_share->directory.get(); | 172 Directory* directory = user_share->directory.get(); |
151 | 173 |
152 for (int i = syncer::FIRST_REAL_MODEL_TYPE; | 174 for (int i = syncer::FIRST_REAL_MODEL_TYPE; |
153 i < syncer::MODEL_TYPE_COUNT; ++i) { | 175 i < syncer::MODEL_TYPE_COUNT; ++i) { |
154 directory->set_initial_sync_ended_for_type( | 176 directory->set_initial_sync_ended_for_type( |
155 syncer::ModelTypeFromInt(i), true); | 177 syncer::ModelTypeFromInt(i), true); |
156 } | 178 } |
157 } | 179 } |
158 | 180 |
159 void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange( | 181 void SyncBackendHostForProfileSyncTest::EmitOnInvalidatorStateChange( |
160 syncer::InvalidatorState state) { | 182 syncer::InvalidatorState state) { |
161 frontend()->OnInvalidatorStateChange(state); | 183 frontend()->OnInvalidatorStateChange(state); |
162 } | 184 } |
163 | 185 |
164 void SyncBackendHostForProfileSyncTest::EmitOnIncomingInvalidation( | 186 void SyncBackendHostForProfileSyncTest::EmitOnIncomingInvalidation( |
165 const syncer::ObjectIdInvalidationMap& invalidation_map, | 187 const syncer::ObjectIdInvalidationMap& invalidation_map, |
166 const syncer::IncomingInvalidationSource source) { | 188 const syncer::IncomingInvalidationSource source) { |
167 frontend()->OnIncomingInvalidation(invalidation_map, source); | 189 frontend()->OnIncomingInvalidation(invalidation_map, source); |
168 } | 190 } |
169 | 191 |
| 192 void SyncBackendHostForProfileSyncTest::ContinueInitialization( |
| 193 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 194 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 195 debug_info_listener, |
| 196 syncer::ModelTypeSet restored_types) { |
| 197 SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
| 198 js_backend, debug_info_listener, restored_types); |
| 199 } |
| 200 |
170 } // namespace browser_sync | 201 } // namespace browser_sync |
171 | 202 |
172 syncer::TestIdFactory* TestProfileSyncService::id_factory() { | 203 syncer::TestIdFactory* TestProfileSyncService::id_factory() { |
173 return &id_factory_; | 204 return &id_factory_; |
174 } | 205 } |
175 | 206 |
176 browser_sync::SyncBackendHostForProfileSyncTest* | 207 browser_sync::SyncBackendHostForProfileSyncTest* |
177 TestProfileSyncService::GetBackendForTest() { | 208 TestProfileSyncService::GetBackendForTest() { |
178 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( | 209 return static_cast<browser_sync::SyncBackendHostForProfileSyncTest*>( |
179 ProfileSyncService::GetBackendForTest()); | 210 ProfileSyncService::GetBackendForTest()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 profile(), | 279 profile(), |
249 sync_prefs_.AsWeakPtr(), | 280 sync_prefs_.AsWeakPtr(), |
250 invalidator_storage_.AsWeakPtr(), | 281 invalidator_storage_.AsWeakPtr(), |
251 id_factory_, | 282 id_factory_, |
252 callback_, | 283 callback_, |
253 set_initial_sync_ended_on_init_, | 284 set_initial_sync_ended_on_init_, |
254 synchronous_backend_initialization_, | 285 synchronous_backend_initialization_, |
255 fail_initial_download_, | 286 fail_initial_download_, |
256 storage_option_)); | 287 storage_option_)); |
257 } | 288 } |
OLD | NEW |