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 void FakeSyncManager::Init( | 99 void 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 153 } |
142 | 154 |
143 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 155 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
144 NOTIMPLEMENTED(); | 156 NOTIMPLEMENTED(); |
145 } | 157 } |
146 | 158 |
147 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { | 159 void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { |
148 enabled_types_ = types; | 160 enabled_types_ = types; |
149 } | 161 } |
150 | 162 |
| 163 void FakeSyncManager::RegisterInvalidationHandler( |
| 164 SyncNotifierObserver* handler) { |
| 165 registrar_.RegisterHandler(handler); |
| 166 } |
| 167 |
151 void FakeSyncManager::UpdateRegisteredInvalidationIds( | 168 void FakeSyncManager::UpdateRegisteredInvalidationIds( |
152 SyncNotifierObserver* handler, | 169 SyncNotifierObserver* handler, |
153 const ObjectIdSet& ids) { | 170 const ObjectIdSet& ids) { |
154 notifier_helper_.UpdateRegisteredIds(handler, ids); | 171 registrar_.UpdateRegisteredIds(handler, ids); |
| 172 } |
| 173 |
| 174 void FakeSyncManager::UnregisterInvalidationHandler( |
| 175 SyncNotifierObserver* handler) { |
| 176 registrar_.UnregisterHandler(handler); |
155 } | 177 } |
156 | 178 |
157 void FakeSyncManager::StartSyncingNormally( | 179 void FakeSyncManager::StartSyncingNormally( |
158 const ModelSafeRoutingInfo& routing_info) { | 180 const ModelSafeRoutingInfo& routing_info) { |
159 // Do nothing. | 181 // Do nothing. |
160 } | 182 } |
161 | 183 |
162 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, | 184 void FakeSyncManager::SetEncryptionPassphrase(const std::string& passphrase, |
163 bool is_explicit) { | 185 bool is_explicit) { |
164 NOTIMPLEMENTED(); | 186 NOTIMPLEMENTED(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 279 |
258 bool FakeSyncManager::HasUnsyncedItems() { | 280 bool FakeSyncManager::HasUnsyncedItems() { |
259 NOTIMPLEMENTED(); | 281 NOTIMPLEMENTED(); |
260 return false; | 282 return false; |
261 } | 283 } |
262 | 284 |
263 void FakeSyncManager::InvalidateOnSyncThread( | 285 void FakeSyncManager::InvalidateOnSyncThread( |
264 const ObjectIdPayloadMap& id_payloads, | 286 const ObjectIdPayloadMap& id_payloads, |
265 IncomingNotificationSource source) { | 287 IncomingNotificationSource source) { |
266 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 288 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
267 notifier_helper_.DispatchInvalidationsToHandlers(id_payloads, source); | 289 registrar_.DispatchInvalidationsToHandlers(id_payloads, source); |
268 } | 290 } |
269 | 291 |
270 void FakeSyncManager::EnableNotificationsOnSyncThread() { | 292 void FakeSyncManager::EnableNotificationsOnSyncThread() { |
271 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 293 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
272 notifier_helper_.EmitOnNotificationsEnabled(); | 294 registrar_.EmitOnNotificationsEnabled(); |
273 } | 295 } |
274 | 296 |
275 void FakeSyncManager::DisableNotificationsOnSyncThread( | 297 void FakeSyncManager::DisableNotificationsOnSyncThread( |
276 NotificationsDisabledReason reason) { | 298 NotificationsDisabledReason reason) { |
277 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 299 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
278 notifier_helper_.EmitOnNotificationsDisabled(reason); | 300 registrar_.EmitOnNotificationsDisabled(reason); |
279 } | 301 } |
280 | 302 |
281 } // namespace syncer | 303 } // namespace syncer |
OLD | NEW |