| 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 "base/message_loop.h" | 7 #include <cstddef> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/location.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/thread_task_runner_handle.h" |
| 8 #include "sync/internal_api/public/http_post_provider_factory.h" | 15 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 9 #include "sync/internal_api/public/internal_components_factory.h" | 16 #include "sync/internal_api/public/internal_components_factory.h" |
| 10 #include "sync/internal_api/public/util/weak_handle.h" | 17 #include "sync/internal_api/public/util/weak_handle.h" |
| 18 #include "sync/notifier/notifications_disabled_reason.h" |
| 19 #include "sync/notifier/object_id_payload_map.h" |
| 11 #include "sync/notifier/sync_notifier.h" | 20 #include "sync/notifier/sync_notifier.h" |
| 12 | 21 |
| 13 namespace syncer { | 22 namespace syncer { |
| 14 | 23 |
| 15 FakeSyncManager::FakeSyncManager() { | 24 FakeSyncManager::FakeSyncManager() {} |
| 16 } | |
| 17 | 25 |
| 18 FakeSyncManager::~FakeSyncManager() { | 26 FakeSyncManager::~FakeSyncManager() {} |
| 19 } | |
| 20 | 27 |
| 21 void FakeSyncManager::set_initial_sync_ended_types(ModelTypeSet types) { | 28 void FakeSyncManager::set_initial_sync_ended_types(ModelTypeSet types) { |
| 22 initial_sync_ended_types_ = types; | 29 initial_sync_ended_types_ = types; |
| 23 } | 30 } |
| 24 | 31 |
| 25 void FakeSyncManager::set_progress_marker_types(ModelTypeSet types) { | 32 void FakeSyncManager::set_progress_marker_types(ModelTypeSet types) { |
| 26 progress_marker_types_ = types; | 33 progress_marker_types_ = types; |
| 27 } | 34 } |
| 28 | 35 |
| 29 void FakeSyncManager::set_configure_fail_types(ModelTypeSet types) { | 36 void FakeSyncManager::set_configure_fail_types(ModelTypeSet types) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 downloaded_types_.Clear(); | 48 downloaded_types_.Clear(); |
| 42 return downloaded_types; | 49 return downloaded_types; |
| 43 } | 50 } |
| 44 | 51 |
| 45 ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { | 52 ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { |
| 46 ModelTypeSet enabled_types = enabled_types_; | 53 ModelTypeSet enabled_types = enabled_types_; |
| 47 enabled_types_.Clear(); | 54 enabled_types_.Clear(); |
| 48 return enabled_types; | 55 return enabled_types; |
| 49 } | 56 } |
| 50 | 57 |
| 58 void FakeSyncManager::Invalidate( |
| 59 const ObjectIdPayloadMap& id_payloads, |
| 60 IncomingNotificationSource source) { |
| 61 if (!sync_task_runner_->PostTask( |
| 62 FROM_HERE, |
| 63 base::Bind(&FakeSyncManager::InvalidateOnSyncThread, |
| 64 base::Unretained(this), id_payloads, source))) { |
| 65 NOTREACHED(); |
| 66 } |
| 67 } |
| 68 |
| 69 void FakeSyncManager::EnableNotifications() { |
| 70 if (!sync_task_runner_->PostTask( |
| 71 FROM_HERE, |
| 72 base::Bind(&FakeSyncManager::EnableNotificationsOnSyncThread, |
| 73 base::Unretained(this)))) { |
| 74 NOTREACHED(); |
| 75 } |
| 76 } |
| 77 |
| 78 void FakeSyncManager::DisableNotifications( |
| 79 NotificationsDisabledReason reason) { |
| 80 if (!sync_task_runner_->PostTask( |
| 81 FROM_HERE, |
| 82 base::Bind(&FakeSyncManager::DisableNotificationsOnSyncThread, |
| 83 base::Unretained(this), reason))) { |
| 84 NOTREACHED(); |
| 85 } |
| 86 } |
| 87 |
| 51 bool FakeSyncManager::Init( | 88 bool FakeSyncManager::Init( |
| 52 const FilePath& database_location, | 89 const FilePath& database_location, |
| 53 const WeakHandle<JsEventHandler>& event_handler, | 90 const WeakHandle<JsEventHandler>& event_handler, |
| 54 const std::string& sync_server_and_path, | 91 const std::string& sync_server_and_path, |
| 55 int sync_server_port, | 92 int sync_server_port, |
| 56 bool use_ssl, | 93 bool use_ssl, |
| 57 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 94 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 58 scoped_ptr<HttpPostProviderFactory> post_factory, | 95 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 59 const std::vector<ModelSafeWorker*>& workers, | 96 const std::vector<ModelSafeWorker*>& workers, |
| 60 ExtensionsActivityMonitor* extensions_activity_monitor, | 97 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 61 ChangeDelegate* change_delegate, | 98 ChangeDelegate* change_delegate, |
| 62 const SyncCredentials& credentials, | 99 const SyncCredentials& credentials, |
| 63 scoped_ptr<SyncNotifier> sync_notifier, | 100 scoped_ptr<SyncNotifier> sync_notifier, |
| 64 const std::string& restored_key_for_bootstrapping, | 101 const std::string& restored_key_for_bootstrapping, |
| 65 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 102 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 66 Encryptor* encryptor, | 103 Encryptor* encryptor, |
| 67 UnrecoverableErrorHandler* unrecoverable_error_handler, | 104 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 68 ReportUnrecoverableErrorFunction | 105 ReportUnrecoverableErrorFunction |
| 69 report_unrecoverable_error_function) { | 106 report_unrecoverable_error_function) { |
| 70 sync_loop_ = MessageLoop::current(); | 107 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 71 PurgePartiallySyncedTypes(); | 108 PurgePartiallySyncedTypes(); |
| 72 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 109 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 73 OnInitializationComplete( | 110 OnInitializationComplete( |
| 74 syncer::WeakHandle<syncer::JsBackend>(), | 111 syncer::WeakHandle<syncer::JsBackend>(), |
| 75 true, initial_sync_ended_types_)); | 112 true, initial_sync_ended_types_)); |
| 76 return true; | 113 return true; |
| 77 } | 114 } |
| 78 | 115 |
| 79 void FakeSyncManager::ThrowUnrecoverableError() { | 116 void FakeSyncManager::ThrowUnrecoverableError() { |
| 80 NOTIMPLEMENTED(); | 117 NOTIMPLEMENTED(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 104 } | 141 } |
| 105 | 142 |
| 106 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 143 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
| 107 NOTIMPLEMENTED(); | 144 NOTIMPLEMENTED(); |
| 108 } | 145 } |
| 109 | 146 |
| 110 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { | 147 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { |
| 111 enabled_types_ = types; | 148 enabled_types_ = types; |
| 112 } | 149 } |
| 113 | 150 |
| 151 void FakeSyncManager::UpdateRegisteredIds( |
| 152 SyncNotifierObserver* handler, const ObjectIdSet& ids) { |
| 153 notifier_helper_.UpdateRegisteredIds(handler, ids); |
| 154 } |
| 155 |
| 114 void FakeSyncManager::StartSyncingNormally( | 156 void FakeSyncManager::StartSyncingNormally( |
| 115 const ModelSafeRoutingInfo& routing_info) { | 157 const ModelSafeRoutingInfo& routing_info) { |
| 116 // Do nothing. | 158 // Do nothing. |
| 117 } | 159 } |
| 118 | 160 |
| 119 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, | 161 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, |
| 120 bool is_explicit) { | 162 bool is_explicit) { |
| 121 NOTIMPLEMENTED(); | 163 NOTIMPLEMENTED(); |
| 122 } | 164 } |
| 123 | 165 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 bool FakeSyncManager::IsUsingExplicitPassphrase() { | 216 bool FakeSyncManager::IsUsingExplicitPassphrase() { |
| 175 NOTIMPLEMENTED(); | 217 NOTIMPLEMENTED(); |
| 176 return false; | 218 return false; |
| 177 } | 219 } |
| 178 | 220 |
| 179 void FakeSyncManager::SaveChanges() { | 221 void FakeSyncManager::SaveChanges() { |
| 180 // Do nothing. | 222 // Do nothing. |
| 181 } | 223 } |
| 182 | 224 |
| 183 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) { | 225 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) { |
| 184 sync_loop_->PostTask(FROM_HERE, callback); | 226 if (!sync_task_runner_->PostTask(FROM_HERE, callback)) { |
| 227 NOTREACHED(); |
| 228 } |
| 185 } | 229 } |
| 186 | 230 |
| 187 void FakeSyncManager::ShutdownOnSyncThread() { | 231 void FakeSyncManager::ShutdownOnSyncThread() { |
| 188 // Do nothing. | 232 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 189 } | 233 } |
| 190 | 234 |
| 191 UserShare* FakeSyncManager::GetUserShare() { | 235 UserShare* FakeSyncManager::GetUserShare() { |
| 192 NOTIMPLEMENTED(); | 236 NOTIMPLEMENTED(); |
| 193 return NULL; | 237 return NULL; |
| 194 } | 238 } |
| 195 | 239 |
| 196 void FakeSyncManager::RefreshNigori(const std::string& chrome_version, | 240 void FakeSyncManager::RefreshNigori(const std::string& chrome_version, |
| 197 const base::Closure& done_callback) { | 241 const base::Closure& done_callback) { |
| 198 done_callback.Run(); | 242 done_callback.Run(); |
| 199 } | 243 } |
| 200 | 244 |
| 201 void FakeSyncManager::EnableEncryptEverything() { | 245 void FakeSyncManager::EnableEncryptEverything() { |
| 202 NOTIMPLEMENTED(); | 246 NOTIMPLEMENTED(); |
| 203 } | 247 } |
| 204 | 248 |
| 205 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) { | 249 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) { |
| 206 return false; | 250 return false; |
| 207 } | 251 } |
| 208 | 252 |
| 209 bool FakeSyncManager::HasUnsyncedItems() { | 253 bool FakeSyncManager::HasUnsyncedItems() { |
| 210 NOTIMPLEMENTED(); | 254 NOTIMPLEMENTED(); |
| 211 return false; | 255 return false; |
| 212 } | 256 } |
| 213 | 257 |
| 258 void FakeSyncManager::InvalidateOnSyncThread( |
| 259 const ObjectIdPayloadMap& id_payloads, |
| 260 IncomingNotificationSource source) { |
| 261 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 262 notifier_helper_.DispatchInvalidationsToHandlers(id_payloads, source); |
| 263 } |
| 264 |
| 265 void FakeSyncManager::EnableNotificationsOnSyncThread() { |
| 266 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 267 notifier_helper_.EmitOnNotificationsEnabled(); |
| 268 } |
| 269 |
| 270 void FakeSyncManager::DisableNotificationsOnSyncThread( |
| 271 NotificationsDisabledReason reason) { |
| 272 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 273 notifier_helper_.EmitOnNotificationsDisabled(reason); |
| 274 } |
| 275 |
| 214 } // namespace syncer | 276 } // namespace syncer |
| 215 | |
| OLD | NEW |