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 "sync/internal_api/public/test/fake_sync_manager.h" | 5 #include "sync/internal_api/public/test/fake_sync_manager.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "sync/internal_api/public/http_post_provider_factory.h" | 16 #include "sync/internal_api/public/http_post_provider_factory.h" |
17 #include "sync/internal_api/public/internal_components_factory.h" | 17 #include "sync/internal_api/public/internal_components_factory.h" |
18 #include "sync/internal_api/public/util/weak_handle.h" | 18 #include "sync/internal_api/public/util/weak_handle.h" |
19 #include "sync/notifier/invalidator.h" | 19 #include "sync/notifier/invalidator.h" |
20 #include "sync/notifier/invalidator_state.h" | 20 #include "sync/notifier/invalidator_state.h" |
21 #include "sync/notifier/object_id_state_map.h" | 21 #include "sync/notifier/object_id_state_map.h" |
22 #include "sync/test/fake_sync_encryption_handler.h" | 22 #include "sync/test/fake_sync_encryption_handler.h" |
| 23 #include "sync/syncable/directory.h" |
23 | 24 |
24 namespace syncer { | 25 namespace syncer { |
25 | 26 |
26 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, | 27 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, |
27 ModelTypeSet progress_marker_types, | 28 ModelTypeSet progress_marker_types, |
28 ModelTypeSet configure_fail_types) : | 29 ModelTypeSet configure_fail_types) : |
29 initial_sync_ended_types_(initial_sync_ended_types), | 30 initial_sync_ended_types_(initial_sync_ended_types), |
30 progress_marker_types_(progress_marker_types), | 31 progress_marker_types_(progress_marker_types), |
31 configure_fail_types_(configure_fail_types) { | 32 configure_fail_types_(configure_fail_types) { |
32 fake_encryption_handler_.reset(new FakeSyncEncryptionHandler()); | 33 fake_encryption_handler_.reset(new FakeSyncEncryptionHandler()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 89 } |
89 run_loop.Run(); | 90 run_loop.Run(); |
90 } | 91 } |
91 | 92 |
92 void FakeSyncManager::Init( | 93 void FakeSyncManager::Init( |
93 const FilePath& database_location, | 94 const FilePath& database_location, |
94 const WeakHandle<JsEventHandler>& event_handler, | 95 const WeakHandle<JsEventHandler>& event_handler, |
95 const std::string& sync_server_and_path, | 96 const std::string& sync_server_and_path, |
96 int sync_server_port, | 97 int sync_server_port, |
97 bool use_ssl, | 98 bool use_ssl, |
98 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | |
99 scoped_ptr<HttpPostProviderFactory> post_factory, | 99 scoped_ptr<HttpPostProviderFactory> post_factory, |
100 const std::vector<ModelSafeWorker*>& workers, | 100 const std::vector<ModelSafeWorker*>& workers, |
101 ExtensionsActivityMonitor* extensions_activity_monitor, | 101 ExtensionsActivityMonitor* extensions_activity_monitor, |
102 ChangeDelegate* change_delegate, | 102 ChangeDelegate* change_delegate, |
103 const SyncCredentials& credentials, | 103 const SyncCredentials& credentials, |
104 scoped_ptr<Invalidator> invalidator, | 104 scoped_ptr<Invalidator> invalidator, |
105 const std::string& restored_key_for_bootstrapping, | 105 const std::string& restored_key_for_bootstrapping, |
106 const std::string& restored_keystore_key_for_bootstrapping, | 106 const std::string& restored_keystore_key_for_bootstrapping, |
107 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 107 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
108 Encryptor* encryptor, | 108 Encryptor* encryptor, |
109 UnrecoverableErrorHandler* unrecoverable_error_handler, | 109 UnrecoverableErrorHandler* unrecoverable_error_handler, |
110 ReportUnrecoverableErrorFunction | 110 ReportUnrecoverableErrorFunction |
111 report_unrecoverable_error_function) { | 111 report_unrecoverable_error_function) { |
112 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 112 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
113 PurgePartiallySyncedTypes(); | 113 PurgePartiallySyncedTypes(); |
| 114 |
| 115 test_user_share_.SetUp(); |
| 116 UserShare* share = test_user_share_.user_share(); |
| 117 for (ModelTypeSet::Iterator it = initial_sync_ended_types_.First(); |
| 118 it.Good(); it.Inc()) { |
| 119 TestUserShare::CreateRoot(it.Get(), share); |
| 120 } |
| 121 |
114 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 122 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
115 OnInitializationComplete( | 123 OnInitializationComplete( |
116 syncer::WeakHandle<syncer::JsBackend>(), | 124 syncer::WeakHandle<syncer::JsBackend>(), |
117 true, initial_sync_ended_types_)); | 125 true, initial_sync_ended_types_)); |
118 } | 126 } |
119 | 127 |
120 void FakeSyncManager::ThrowUnrecoverableError() { | 128 void FakeSyncManager::ThrowUnrecoverableError() { |
121 NOTIMPLEMENTED(); | 129 NOTIMPLEMENTED(); |
122 } | 130 } |
123 | 131 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 190 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); |
183 ModelTypeSet disabled_types = Difference( | 191 ModelTypeSet disabled_types = Difference( |
184 ModelTypeSet::All(), enabled_types); | 192 ModelTypeSet::All(), enabled_types); |
185 ModelTypeSet success_types = types_to_config; | 193 ModelTypeSet success_types = types_to_config; |
186 success_types.RemoveAll(configure_fail_types_); | 194 success_types.RemoveAll(configure_fail_types_); |
187 | 195 |
188 DVLOG(1) << "Faking configuration. Downloading: " | 196 DVLOG(1) << "Faking configuration. Downloading: " |
189 << ModelTypeSetToString(success_types) << ". Cleaning: " | 197 << ModelTypeSetToString(success_types) << ". Cleaning: " |
190 << ModelTypeSetToString(disabled_types); | 198 << ModelTypeSetToString(disabled_types); |
191 | 199 |
| 200 // Update our fake directory by clearing and fake-downloading as necessary. |
| 201 UserShare* share = GetUserShare(); |
| 202 share->directory->PurgeEntriesWithTypeIn(disabled_types); |
| 203 for (ModelTypeSet::Iterator it = success_types.First(); it.Good(); it.Inc()) { |
| 204 // We must be careful to not create the same root node twice. |
| 205 if (!initial_sync_ended_types_.Has(it.Get())) { |
| 206 TestUserShare::CreateRoot(it.Get(), share); |
| 207 } |
| 208 } |
| 209 |
192 // Simulate cleaning up disabled types. | 210 // Simulate cleaning up disabled types. |
193 // TODO(sync): consider only cleaning those types that were recently disabled, | 211 // TODO(sync): consider only cleaning those types that were recently disabled, |
194 // if this isn't the first cleanup, which more accurately reflects the | 212 // if this isn't the first cleanup, which more accurately reflects the |
195 // behavior of the real cleanup logic. | 213 // behavior of the real cleanup logic. |
196 initial_sync_ended_types_.RemoveAll(disabled_types); | 214 initial_sync_ended_types_.RemoveAll(disabled_types); |
197 progress_marker_types_.RemoveAll(disabled_types); | 215 progress_marker_types_.RemoveAll(disabled_types); |
198 cleaned_types_.PutAll(disabled_types); | 216 cleaned_types_.PutAll(disabled_types); |
199 | 217 |
200 // Now simulate the actual configuration for those types that successfully | 218 // Now simulate the actual configuration for those types that successfully |
201 // download + apply. | 219 // download + apply. |
(...skipping 22 matching lines...) Expand all Loading... |
224 } | 242 } |
225 | 243 |
226 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) { | 244 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) { |
227 if (!sync_task_runner_->PostTask(FROM_HERE, callback)) { | 245 if (!sync_task_runner_->PostTask(FROM_HERE, callback)) { |
228 NOTREACHED(); | 246 NOTREACHED(); |
229 } | 247 } |
230 } | 248 } |
231 | 249 |
232 void FakeSyncManager::ShutdownOnSyncThread() { | 250 void FakeSyncManager::ShutdownOnSyncThread() { |
233 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 251 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 252 test_user_share_.TearDown(); |
234 } | 253 } |
235 | 254 |
236 UserShare* FakeSyncManager::GetUserShare() { | 255 UserShare* FakeSyncManager::GetUserShare() { |
237 return NULL; | 256 return test_user_share_.user_share(); |
238 } | 257 } |
239 | 258 |
240 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) { | 259 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) { |
241 return false; | 260 return false; |
242 } | 261 } |
243 | 262 |
244 bool FakeSyncManager::HasUnsyncedItems() { | 263 bool FakeSyncManager::HasUnsyncedItems() { |
245 NOTIMPLEMENTED(); | 264 NOTIMPLEMENTED(); |
246 return false; | 265 return false; |
247 } | 266 } |
248 | 267 |
249 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { | 268 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { |
250 return fake_encryption_handler_.get(); | 269 return fake_encryption_handler_.get(); |
251 } | 270 } |
252 | 271 |
253 void FakeSyncManager::InvalidateOnSyncThread( | 272 void FakeSyncManager::InvalidateOnSyncThread( |
254 const ObjectIdStateMap& id_state_map, | 273 const ObjectIdStateMap& id_state_map, |
255 IncomingInvalidationSource source) { | 274 IncomingInvalidationSource source) { |
256 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 275 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
257 registrar_.DispatchInvalidationsToHandlers(id_state_map, source); | 276 registrar_.DispatchInvalidationsToHandlers(id_state_map, source); |
258 } | 277 } |
259 | 278 |
260 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( | 279 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( |
261 InvalidatorState state) { | 280 InvalidatorState state) { |
262 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 281 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
263 registrar_.UpdateInvalidatorState(state); | 282 registrar_.UpdateInvalidatorState(state); |
264 } | 283 } |
265 | 284 |
266 } // namespace syncer | 285 } // namespace syncer |
OLD | NEW |