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/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 enabled_types_.Clear(); | 54 enabled_types_.Clear(); |
55 return enabled_types; | 55 return enabled_types; |
56 } | 56 } |
57 | 57 |
58 ConfigureReason FakeSyncManager::GetAndResetConfigureReason() { | 58 ConfigureReason FakeSyncManager::GetAndResetConfigureReason() { |
59 ConfigureReason reason = last_configure_reason_; | 59 ConfigureReason reason = last_configure_reason_; |
60 last_configure_reason_ = CONFIGURE_REASON_UNKNOWN; | 60 last_configure_reason_ = CONFIGURE_REASON_UNKNOWN; |
61 return reason; | 61 return reason; |
62 } | 62 } |
63 | 63 |
64 void FakeSyncManager::Invalidate( | |
65 const ObjectIdInvalidationMap& invalidation_map) { | |
66 if (!sync_task_runner_->PostTask( | |
67 FROM_HERE, | |
68 base::Bind(&FakeSyncManager::InvalidateOnSyncThread, | |
69 base::Unretained(this), invalidation_map))) { | |
70 NOTREACHED(); | |
71 } | |
72 } | |
73 | |
74 void FakeSyncManager::UpdateInvalidatorState(InvalidatorState state) { | |
75 if (!sync_task_runner_->PostTask( | |
76 FROM_HERE, | |
77 base::Bind(&FakeSyncManager::UpdateInvalidatorStateOnSyncThread, | |
78 base::Unretained(this), state))) { | |
79 NOTREACHED(); | |
80 } | |
81 } | |
82 | |
83 void FakeSyncManager::WaitForSyncThread() { | 64 void FakeSyncManager::WaitForSyncThread() { |
84 // Post a task to |sync_task_runner_| and block until it runs. | 65 // Post a task to |sync_task_runner_| and block until it runs. |
85 base::RunLoop run_loop; | 66 base::RunLoop run_loop; |
86 if (!sync_task_runner_->PostTaskAndReply( | 67 if (!sync_task_runner_->PostTaskAndReply( |
87 FROM_HERE, | 68 FROM_HERE, |
88 base::Bind(&base::DoNothing), | 69 base::Bind(&base::DoNothing), |
89 run_loop.QuitClosure())) { | 70 run_loop.QuitClosure())) { |
90 NOTREACHED(); | 71 NOTREACHED(); |
91 } | 72 } |
92 run_loop.Run(); | 73 run_loop.Run(); |
93 } | 74 } |
94 | 75 |
95 void FakeSyncManager::Init( | 76 void FakeSyncManager::Init( |
96 const base::FilePath& database_location, | 77 const base::FilePath& database_location, |
97 const WeakHandle<JsEventHandler>& event_handler, | 78 const WeakHandle<JsEventHandler>& event_handler, |
98 const std::string& sync_server_and_path, | 79 const std::string& sync_server_and_path, |
99 int sync_server_port, | 80 int sync_server_port, |
100 bool use_ssl, | 81 bool use_ssl, |
101 scoped_ptr<HttpPostProviderFactory> post_factory, | 82 scoped_ptr<HttpPostProviderFactory> post_factory, |
102 const std::vector<ModelSafeWorker*>& workers, | 83 const std::vector<ModelSafeWorker*>& workers, |
103 ExtensionsActivityMonitor* extensions_activity_monitor, | 84 ExtensionsActivityMonitor* extensions_activity_monitor, |
104 ChangeDelegate* change_delegate, | 85 ChangeDelegate* change_delegate, |
105 const SyncCredentials& credentials, | 86 const SyncCredentials& credentials, |
106 scoped_ptr<Invalidator> invalidator, | |
107 const std::string& invalidator_client_id, | 87 const std::string& invalidator_client_id, |
108 const std::string& restored_key_for_bootstrapping, | 88 const std::string& restored_key_for_bootstrapping, |
109 const std::string& restored_keystore_key_for_bootstrapping, | 89 const std::string& restored_keystore_key_for_bootstrapping, |
110 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 90 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
111 Encryptor* encryptor, | 91 Encryptor* encryptor, |
112 UnrecoverableErrorHandler* unrecoverable_error_handler, | 92 UnrecoverableErrorHandler* unrecoverable_error_handler, |
113 ReportUnrecoverableErrorFunction | 93 ReportUnrecoverableErrorFunction |
114 report_unrecoverable_error_function, | 94 report_unrecoverable_error_function, |
115 bool use_oauth2_token) { | 95 bool use_oauth2_token) { |
116 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 96 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 134 } |
155 progress_marker_types_.RemoveAll(partial_types); | 135 progress_marker_types_.RemoveAll(partial_types); |
156 cleaned_types_.PutAll(partial_types); | 136 cleaned_types_.PutAll(partial_types); |
157 return true; | 137 return true; |
158 } | 138 } |
159 | 139 |
160 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 140 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
161 NOTIMPLEMENTED(); | 141 NOTIMPLEMENTED(); |
162 } | 142 } |
163 | 143 |
164 void FakeSyncManager::UpdateEnabledTypes(ModelTypeSet types) { | |
165 enabled_types_ = types; | |
166 } | |
167 | |
168 void FakeSyncManager::RegisterInvalidationHandler( | |
169 InvalidationHandler* handler) { | |
170 registrar_.RegisterHandler(handler); | |
171 } | |
172 | |
173 void FakeSyncManager::UpdateRegisteredInvalidationIds( | |
174 InvalidationHandler* handler, | |
175 const ObjectIdSet& ids) { | |
176 registrar_.UpdateRegisteredIds(handler, ids); | |
177 } | |
178 | |
179 void FakeSyncManager::UnregisterInvalidationHandler( | |
180 InvalidationHandler* handler) { | |
181 registrar_.UnregisterHandler(handler); | |
182 } | |
183 | |
184 void FakeSyncManager::AcknowledgeInvalidation(const invalidation::ObjectId& id, | |
185 const AckHandle& ack_handle) { | |
186 // Do nothing. | |
187 } | |
188 | |
189 void FakeSyncManager::StartSyncingNormally( | 144 void FakeSyncManager::StartSyncingNormally( |
190 const ModelSafeRoutingInfo& routing_info) { | 145 const ModelSafeRoutingInfo& routing_info) { |
191 // Do nothing. | 146 // Do nothing. |
192 } | 147 } |
193 | 148 |
194 void FakeSyncManager::ConfigureSyncer( | 149 void FakeSyncManager::ConfigureSyncer( |
195 ConfigureReason reason, | 150 ConfigureReason reason, |
196 ModelTypeSet to_download, | 151 ModelTypeSet to_download, |
197 ModelTypeSet to_journal, | 152 ModelTypeSet to_journal, |
198 ModelTypeSet to_unapply, | 153 ModelTypeSet to_unapply, |
199 ModelTypeSet to_ignore, | 154 ModelTypeSet to_ignore, |
200 const ModelSafeRoutingInfo& new_routing_info, | 155 const ModelSafeRoutingInfo& new_routing_info, |
201 const base::Closure& ready_task, | 156 const base::Closure& ready_task, |
202 const base::Closure& retry_task) { | 157 const base::Closure& retry_task) { |
203 last_configure_reason_ = reason; | 158 last_configure_reason_ = reason; |
204 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 159 enabled_types_ = GetRoutingInfoTypes(new_routing_info); |
205 ModelTypeSet disabled_types = Difference( | 160 ModelTypeSet disabled_types = Difference( |
206 ModelTypeSet::All(), enabled_types); | 161 ModelTypeSet::All(), enabled_types_); |
207 disabled_types.RemoveAll(to_ignore); | 162 disabled_types.RemoveAll(to_ignore); |
208 ModelTypeSet success_types = to_download; | 163 ModelTypeSet success_types = to_download; |
209 success_types.RemoveAll(configure_fail_types_); | 164 success_types.RemoveAll(configure_fail_types_); |
210 | 165 |
211 DVLOG(1) << "Faking configuration. Downloading: " | 166 DVLOG(1) << "Faking configuration. Downloading: " |
212 << ModelTypeSetToString(success_types) << ". Cleaning: " | 167 << ModelTypeSetToString(success_types) << ". Cleaning: " |
213 << ModelTypeSetToString(disabled_types); | 168 << ModelTypeSetToString(disabled_types); |
214 | 169 |
215 // Update our fake directory by clearing and fake-downloading as necessary. | 170 // Update our fake directory by clearing and fake-downloading as necessary. |
216 UserShare* share = GetUserShare(); | 171 UserShare* share = GetUserShare(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 242 } |
288 | 243 |
289 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { | 244 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { |
290 return fake_encryption_handler_.get(); | 245 return fake_encryption_handler_.get(); |
291 } | 246 } |
292 | 247 |
293 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { | 248 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { |
294 last_refresh_request_types_ = types; | 249 last_refresh_request_types_ = types; |
295 } | 250 } |
296 | 251 |
297 void FakeSyncManager::InvalidateOnSyncThread( | 252 void FakeSyncManager::OnIncomingInvalidation( |
298 const ObjectIdInvalidationMap& invalidation_map) { | 253 const ObjectIdInvalidationMap& invalidation_map) { |
299 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 254 // Do nothing. |
300 registrar_.DispatchInvalidationsToHandlers(invalidation_map); | |
301 } | |
302 | |
303 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( | |
304 InvalidatorState state) { | |
305 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
306 registrar_.UpdateInvalidatorState(state); | |
307 } | 255 } |
308 | 256 |
309 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { | 257 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { |
310 return last_refresh_request_types_; | 258 return last_refresh_request_types_; |
311 } | 259 } |
312 | 260 |
| 261 void FakeSyncManager::OnInvalidatorStateChange(InvalidatorState state) { |
| 262 // Do nothing. |
| 263 } |
| 264 |
313 } // namespace syncer | 265 } // namespace syncer |
OLD | NEW |