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/run_loop.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "sync/internal_api/public/http_post_provider_factory.h" | 16 #include "sync/internal_api/public/http_post_provider_factory.h" |
17 #include "sync/internal_api/public/internal_components_factory.h" | 17 #include "sync/internal_api/public/internal_components_factory.h" |
18 #include "sync/internal_api/public/util/weak_handle.h" | 18 #include "sync/internal_api/public/util/weak_handle.h" |
19 #include "sync/notifier/notifications_disabled_reason.h" | |
20 #include "sync/notifier/invalidator.h" | 19 #include "sync/notifier/invalidator.h" |
| 20 #include "sync/notifier/invalidator_state.h" |
21 #include "sync/notifier/object_id_state_map.h" | 21 #include "sync/notifier/object_id_state_map.h" |
22 #include "sync/test/fake_sync_encryption_handler.h" | 22 #include "sync/test/fake_sync_encryption_handler.h" |
23 | 23 |
24 namespace syncer { | 24 namespace syncer { |
25 | 25 |
26 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, | 26 FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, |
27 ModelTypeSet progress_marker_types, | 27 ModelTypeSet progress_marker_types, |
28 ModelTypeSet configure_fail_types) : | 28 ModelTypeSet configure_fail_types) : |
29 initial_sync_ended_types_(initial_sync_ended_types), | 29 initial_sync_ended_types_(initial_sync_ended_types), |
30 progress_marker_types_(progress_marker_types), | 30 progress_marker_types_(progress_marker_types), |
(...skipping 15 matching lines...) Expand all Loading... |
46 return downloaded_types; | 46 return downloaded_types; |
47 } | 47 } |
48 | 48 |
49 ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { | 49 ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { |
50 ModelTypeSet enabled_types = enabled_types_; | 50 ModelTypeSet enabled_types = enabled_types_; |
51 enabled_types_.Clear(); | 51 enabled_types_.Clear(); |
52 return enabled_types; | 52 return enabled_types; |
53 } | 53 } |
54 | 54 |
55 void FakeSyncManager::Invalidate(const ObjectIdStateMap& id_state_map, | 55 void FakeSyncManager::Invalidate(const ObjectIdStateMap& id_state_map, |
56 IncomingNotificationSource source) { | 56 IncomingInvalidationSource source) { |
57 if (!sync_task_runner_->PostTask( | 57 if (!sync_task_runner_->PostTask( |
58 FROM_HERE, | 58 FROM_HERE, |
59 base::Bind(&FakeSyncManager::InvalidateOnSyncThread, | 59 base::Bind(&FakeSyncManager::InvalidateOnSyncThread, |
60 base::Unretained(this), id_state_map, source))) { | 60 base::Unretained(this), id_state_map, source))) { |
61 NOTREACHED(); | 61 NOTREACHED(); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void FakeSyncManager::EnableNotifications() { | 65 void FakeSyncManager::UpdateInvalidatorState(InvalidatorState state) { |
66 if (!sync_task_runner_->PostTask( | 66 if (!sync_task_runner_->PostTask( |
67 FROM_HERE, | 67 FROM_HERE, |
68 base::Bind(&FakeSyncManager::EnableNotificationsOnSyncThread, | 68 base::Bind(&FakeSyncManager::UpdateInvalidatorStateOnSyncThread, |
69 base::Unretained(this)))) { | 69 base::Unretained(this), state))) { |
70 NOTREACHED(); | 70 NOTREACHED(); |
71 } | 71 } |
72 } | 72 } |
73 | |
74 void FakeSyncManager::DisableNotifications( | |
75 NotificationsDisabledReason reason) { | |
76 if (!sync_task_runner_->PostTask( | |
77 FROM_HERE, | |
78 base::Bind(&FakeSyncManager::DisableNotificationsOnSyncThread, | |
79 base::Unretained(this), reason))) { | |
80 NOTREACHED(); | |
81 } | |
82 } | |
83 | 73 |
84 namespace { | 74 namespace { |
85 | 75 |
86 void DoNothing() {} | 76 void DoNothing() {} |
87 | 77 |
88 } // namespace | 78 } // namespace |
89 | 79 |
90 void FakeSyncManager::WaitForSyncThread() { | 80 void FakeSyncManager::WaitForSyncThread() { |
91 // Post a task to |sync_task_runner_| and block until it runs. | 81 // Post a task to |sync_task_runner_| and block until it runs. |
92 base::RunLoop run_loop; | 82 base::RunLoop run_loop; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 NOTIMPLEMENTED(); | 245 NOTIMPLEMENTED(); |
256 return false; | 246 return false; |
257 } | 247 } |
258 | 248 |
259 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { | 249 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { |
260 return fake_encryption_handler_.get(); | 250 return fake_encryption_handler_.get(); |
261 } | 251 } |
262 | 252 |
263 void FakeSyncManager::InvalidateOnSyncThread( | 253 void FakeSyncManager::InvalidateOnSyncThread( |
264 const ObjectIdStateMap& id_state_map, | 254 const ObjectIdStateMap& id_state_map, |
265 IncomingNotificationSource source) { | 255 IncomingInvalidationSource source) { |
266 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 256 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
267 registrar_.DispatchInvalidationsToHandlers(id_state_map, source); | 257 registrar_.DispatchInvalidationsToHandlers(id_state_map, source); |
268 } | 258 } |
269 | 259 |
270 void FakeSyncManager::EnableNotificationsOnSyncThread() { | 260 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( |
| 261 InvalidatorState state) { |
271 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 262 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); |
272 registrar_.EmitOnNotificationsEnabled(); | 263 registrar_.UpdateInvalidatorState(state); |
273 } | |
274 | |
275 void FakeSyncManager::DisableNotificationsOnSyncThread( | |
276 NotificationsDisabledReason reason) { | |
277 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
278 registrar_.EmitOnNotificationsDisabled(reason); | |
279 } | 264 } |
280 | 265 |
281 } // namespace syncer | 266 } // namespace syncer |
OLD | NEW |