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