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