Chromium Code Reviews| 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 const std::string& restored_keystore_key_for_bootstrapping, | 102 const std::string& restored_keystore_key_for_bootstrapping, |
| 66 bool keystore_encryption_enabled, | 103 bool keystore_encryption_enabled, |
| 67 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 104 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 68 Encryptor* encryptor, | 105 Encryptor* encryptor, |
| 69 UnrecoverableErrorHandler* unrecoverable_error_handler, | 106 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 70 ReportUnrecoverableErrorFunction | 107 ReportUnrecoverableErrorFunction |
| 71 report_unrecoverable_error_function) { | 108 report_unrecoverable_error_function) { |
| 72 sync_loop_ = MessageLoop::current(); | 109 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 73 PurgePartiallySyncedTypes(); | 110 PurgePartiallySyncedTypes(); |
| 74 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 111 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 75 OnInitializationComplete( | 112 OnInitializationComplete( |
| 76 syncer::WeakHandle<syncer::JsBackend>(), | 113 syncer::WeakHandle<syncer::JsBackend>(), |
| 77 true, initial_sync_ended_types_)); | 114 true, initial_sync_ended_types_)); |
| 78 return true; | 115 return true; |
| 79 } | 116 } |
| 80 | 117 |
| 81 void FakeSyncManager::ThrowUnrecoverableError() { | 118 void FakeSyncManager::ThrowUnrecoverableError() { |
| 82 NOTIMPLEMENTED(); | 119 NOTIMPLEMENTED(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 106 } | 143 } |
| 107 | 144 |
| 108 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 145 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
| 109 NOTIMPLEMENTED(); | 146 NOTIMPLEMENTED(); |
| 110 } | 147 } |
| 111 | 148 |
| 112 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { | 149 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { |
| 113 enabled_types_ = types; | 150 enabled_types_ = types; |
| 114 } | 151 } |
| 115 | 152 |
| 153 void FakeSyncManager::UpdateRegisteredInvalidationIds( | |
| 154 SyncNotifierObserver* handler, const ObjectIdSet& ids) { | |
| 155 notifier_helper_.UpdateRegisteredIds(handler, ids); | |
| 156 } | |
| 157 | |
| 116 void FakeSyncManager::StartSyncingNormally( | 158 void FakeSyncManager::StartSyncingNormally( |
| 117 const ModelSafeRoutingInfo& routing_info) { | 159 const ModelSafeRoutingInfo& routing_info) { |
| 118 // Do nothing. | 160 // Do nothing. |
| 119 } | 161 } |
| 120 | 162 |
| 121 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, | 163 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, |
| 122 bool is_explicit) { | 164 bool is_explicit) { |
| 123 NOTIMPLEMENTED(); | 165 NOTIMPLEMENTED(); |
| 124 } | 166 } |
| 125 | 167 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 222 |
| 181 bool FakeSyncManager::GetKeystoreKeyBootstrapToken(std::string* token) { | 223 bool FakeSyncManager::GetKeystoreKeyBootstrapToken(std::string* token) { |
| 182 return false; | 224 return false; |
| 183 } | 225 } |
| 184 | 226 |
| 185 void FakeSyncManager::SaveChanges() { | 227 void FakeSyncManager::SaveChanges() { |
| 186 // Do nothing. | 228 // Do nothing. |
| 187 } | 229 } |
| 188 | 230 |
| 189 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) { | 231 void FakeSyncManager::StopSyncingForShutdown(const base::Closure& callback) { |
| 190 sync_loop_->PostTask(FROM_HERE, callback); | 232 if (!sync_task_runner_->PostTask(FROM_HERE, callback)) { |
|
msw
2012/08/03 05:14:21
nit: remove unnecessary {}
| |
| 233 NOTREACHED(); | |
| 234 } | |
| 191 } | 235 } |
| 192 | 236 |
| 193 void FakeSyncManager::ShutdownOnSyncThread() { | 237 void FakeSyncManager::ShutdownOnSyncThread() { |
| 194 // Do nothing. | 238 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
| 195 } | 239 } |
| 196 | 240 |
| 197 UserShare* FakeSyncManager::GetUserShare() { | 241 UserShare* FakeSyncManager::GetUserShare() { |
| 198 NOTIMPLEMENTED(); | 242 NOTIMPLEMENTED(); |
| 199 return NULL; | 243 return NULL; |
| 200 } | 244 } |
| 201 | 245 |
| 202 void FakeSyncManager::RefreshNigori(const std::string& chrome_version, | 246 void FakeSyncManager::RefreshNigori(const std::string& chrome_version, |
| 203 const base::Closure& done_callback) { | 247 const base::Closure& done_callback) { |
| 204 done_callback.Run(); | 248 done_callback.Run(); |
| 205 } | 249 } |
| 206 | 250 |
| 207 void FakeSyncManager::EnableEncryptEverything() { | 251 void FakeSyncManager::EnableEncryptEverything() { |
| 208 NOTIMPLEMENTED(); | 252 NOTIMPLEMENTED(); |
| 209 } | 253 } |
| 210 | 254 |
| 211 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) { | 255 bool FakeSyncManager::ReceivedExperiment(Experiments* experiments) { |
| 212 return false; | 256 return false; |
| 213 } | 257 } |
| 214 | 258 |
| 215 bool FakeSyncManager::HasUnsyncedItems() { | 259 bool FakeSyncManager::HasUnsyncedItems() { |
| 216 NOTIMPLEMENTED(); | 260 NOTIMPLEMENTED(); |
| 217 return false; | 261 return false; |
| 218 } | 262 } |
| 219 | 263 |
| 264 void FakeSyncManager::InvalidateOnSyncThread( | |
| 265 const ObjectIdPayloadMap& id_payloads, | |
| 266 IncomingNotificationSource source) { | |
| 267 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
| 268 notifier_helper_.DispatchInvalidationsToHandlers(id_payloads, source); | |
| 269 } | |
| 270 | |
| 271 void FakeSyncManager::EnableNotificationsOnSyncThread() { | |
| 272 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
| 273 notifier_helper_.EmitOnNotificationsEnabled(); | |
| 274 } | |
| 275 | |
| 276 void FakeSyncManager::DisableNotificationsOnSyncThread( | |
| 277 NotificationsDisabledReason reason) { | |
| 278 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
| 279 notifier_helper_.EmitOnNotificationsDisabled(reason); | |
| 280 } | |
| 281 | |
| 220 } // namespace syncer | 282 } // namespace syncer |
| 221 | |
| OLD | NEW |