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/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
15 #include "sync/internal_api/public/http_post_provider_factory.h" | 16 #include "sync/internal_api/public/http_post_provider_factory.h" |
16 #include "sync/internal_api/public/internal_components_factory.h" | 17 #include "sync/internal_api/public/internal_components_factory.h" |
17 #include "sync/internal_api/public/util/weak_handle.h" | 18 #include "sync/internal_api/public/util/weak_handle.h" |
18 #include "sync/notifier/notifications_disabled_reason.h" | 19 #include "sync/notifier/notifications_disabled_reason.h" |
19 #include "sync/notifier/object_id_payload_map.h" | 20 #include "sync/notifier/object_id_payload_map.h" |
20 #include "sync/notifier/sync_notifier.h" | 21 #include "sync/notifier/sync_notifier.h" |
21 | 22 |
22 namespace syncer { | 23 namespace syncer { |
23 | 24 |
24 FakeSyncManager::FakeSyncManager() {} | 25 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, |
| 26 ModelTypeSet progress_marker_types, |
| 27 ModelTypeSet configure_fail_types) : |
| 28 initial_sync_ended_types_(initial_sync_ended_types), |
| 29 progress_marker_types_(progress_marker_types), |
| 30 configure_fail_types_(configure_fail_types) {} |
25 | 31 |
26 FakeSyncManager::~FakeSyncManager() {} | 32 FakeSyncManager::~FakeSyncManager() {} |
27 | 33 |
28 void FakeSyncManager::set_initial_sync_ended_types(ModelTypeSet types) { | |
29 initial_sync_ended_types_ = types; | |
30 } | |
31 | |
32 void FakeSyncManager::set_progress_marker_types(ModelTypeSet types) { | |
33 progress_marker_types_ = types; | |
34 } | |
35 | |
36 void FakeSyncManager::set_configure_fail_types(ModelTypeSet types) { | |
37 configure_fail_types_ = types; | |
38 } | |
39 | |
40 ModelTypeSet FakeSyncManager::GetAndResetCleanedTypes() { | 34 ModelTypeSet FakeSyncManager::GetAndResetCleanedTypes() { |
41 ModelTypeSet cleaned_types = cleaned_types_; | 35 ModelTypeSet cleaned_types = cleaned_types_; |
42 cleaned_types_.Clear(); | 36 cleaned_types_.Clear(); |
43 return cleaned_types; | 37 return cleaned_types; |
44 } | 38 } |
45 | 39 |
46 ModelTypeSet FakeSyncManager::GetAndResetDownloadedTypes() { | 40 ModelTypeSet FakeSyncManager::GetAndResetDownloadedTypes() { |
47 ModelTypeSet downloaded_types = downloaded_types_; | 41 ModelTypeSet downloaded_types = downloaded_types_; |
48 downloaded_types_.Clear(); | 42 downloaded_types_.Clear(); |
49 return downloaded_types; | 43 return downloaded_types; |
(...skipping 27 matching lines...) Expand all Loading... |
77 void FakeSyncManager::DisableNotifications( | 71 void FakeSyncManager::DisableNotifications( |
78 NotificationsDisabledReason reason) { | 72 NotificationsDisabledReason reason) { |
79 if (!sync_task_runner_->PostTask( | 73 if (!sync_task_runner_->PostTask( |
80 FROM_HERE, | 74 FROM_HERE, |
81 base::Bind(&FakeSyncManager::DisableNotificationsOnSyncThread, | 75 base::Bind(&FakeSyncManager::DisableNotificationsOnSyncThread, |
82 base::Unretained(this), reason))) { | 76 base::Unretained(this), reason))) { |
83 NOTREACHED(); | 77 NOTREACHED(); |
84 } | 78 } |
85 } | 79 } |
86 | 80 |
| 81 namespace { |
| 82 |
| 83 void DoNothing() {} |
| 84 |
| 85 } // namespace |
| 86 |
| 87 void FakeSyncManager::WaitForSyncThread() { |
| 88 // Post a task to |sync_task_runner_| and block until it runs. |
| 89 base::RunLoop run_loop; |
| 90 if (!sync_task_runner_->PostTaskAndReply( |
| 91 FROM_HERE, |
| 92 base::Bind(&DoNothing), |
| 93 run_loop.QuitClosure())) { |
| 94 NOTREACHED(); |
| 95 } |
| 96 run_loop.Run(); |
| 97 } |
| 98 |
87 bool FakeSyncManager::Init( | 99 bool FakeSyncManager::Init( |
88 const FilePath& database_location, | 100 const FilePath& database_location, |
89 const WeakHandle<JsEventHandler>& event_handler, | 101 const WeakHandle<JsEventHandler>& event_handler, |
90 const std::string& sync_server_and_path, | 102 const std::string& sync_server_and_path, |
91 int sync_server_port, | 103 int sync_server_port, |
92 bool use_ssl, | 104 bool use_ssl, |
93 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 105 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
94 scoped_ptr<HttpPostProviderFactory> post_factory, | 106 scoped_ptr<HttpPostProviderFactory> post_factory, |
95 const std::vector<ModelSafeWorker*>& workers, | 107 const std::vector<ModelSafeWorker*>& workers, |
96 ExtensionsActivityMonitor* extensions_activity_monitor, | 108 ExtensionsActivityMonitor* extensions_activity_monitor, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 154 } |
143 | 155 |
144 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 156 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
145 NOTIMPLEMENTED(); | 157 NOTIMPLEMENTED(); |
146 } | 158 } |
147 | 159 |
148 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { | 160 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { |
149 enabled_types_ = types; | 161 enabled_types_ = types; |
150 } | 162 } |
151 | 163 |
| 164 void FakeSyncManager::RegisterInvalidationHandler( |
| 165 SyncNotifierObserver* handler) { |
| 166 registrar_.RegisterHandler(handler); |
| 167 } |
| 168 |
152 void FakeSyncManager::UpdateRegisteredInvalidationIds( | 169 void FakeSyncManager::UpdateRegisteredInvalidationIds( |
153 SyncNotifierObserver* handler, | 170 SyncNotifierObserver* handler, |
154 const ObjectIdSet& ids) { | 171 const ObjectIdSet& ids) { |
155 notifier_helper_.UpdateRegisteredIds(handler, ids); | 172 registrar_.UpdateRegisteredIds(handler, ids); |
| 173 } |
| 174 |
| 175 void FakeSyncManager::UnregisterInvalidationHandler( |
| 176 SyncNotifierObserver* handler) { |
| 177 registrar_.UnregisterHandler(handler); |
156 } | 178 } |
157 | 179 |
158 void FakeSyncManager::StartSyncingNormally( | 180 void FakeSyncManager::StartSyncingNormally( |
159 const ModelSafeRoutingInfo& routing_info) { | 181 const ModelSafeRoutingInfo& routing_info) { |
160 // Do nothing. | 182 // Do nothing. |
161 } | 183 } |
162 | 184 |
163 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, | 185 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, |
164 bool is_explicit) { | 186 bool is_explicit) { |
165 NOTIMPLEMENTED(); | 187 NOTIMPLEMENTED(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 280 |
259 bool FakeSyncManager::HasUnsyncedItems() { | 281 bool FakeSyncManager::HasUnsyncedItems() { |
260 NOTIMPLEMENTED(); | 282 NOTIMPLEMENTED(); |
261 return false; | 283 return false; |
262 } | 284 } |
263 | 285 |
264 void FakeSyncManager::InvalidateOnSyncThread( | 286 void FakeSyncManager::InvalidateOnSyncThread( |
265 const ObjectIdPayloadMap& id_payloads, | 287 const ObjectIdPayloadMap& id_payloads, |
266 IncomingNotificationSource source) { | 288 IncomingNotificationSource source) { |
267 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 289 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
268 notifier_helper_.DispatchInvalidationsToHandlers(id_payloads, source); | 290 registrar_.DispatchInvalidationsToHandlers(id_payloads, source); |
269 } | 291 } |
270 | 292 |
271 void FakeSyncManager::EnableNotificationsOnSyncThread() { | 293 void FakeSyncManager::EnableNotificationsOnSyncThread() { |
272 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 294 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
273 notifier_helper_.EmitOnNotificationsEnabled(); | 295 registrar_.EmitOnNotificationsEnabled(); |
274 } | 296 } |
275 | 297 |
276 void FakeSyncManager::DisableNotificationsOnSyncThread( | 298 void FakeSyncManager::DisableNotificationsOnSyncThread( |
277 NotificationsDisabledReason reason) { | 299 NotificationsDisabledReason reason) { |
278 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 300 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
279 notifier_helper_.EmitOnNotificationsDisabled(reason); | 301 registrar_.EmitOnNotificationsDisabled(reason); |
280 } | 302 } |
281 | 303 |
282 } // namespace syncer | 304 } // namespace syncer |
OLD | NEW |