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_purge, | 152 ModelTypeSet to_purge, |
198 ModelTypeSet to_journal, | 153 ModelTypeSet to_journal, |
199 ModelTypeSet to_unapply, | 154 ModelTypeSet to_unapply, |
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 success_types = to_download; | 160 ModelTypeSet success_types = to_download; |
206 success_types.RemoveAll(configure_fail_types_); | 161 success_types.RemoveAll(configure_fail_types_); |
207 | 162 |
208 DVLOG(1) << "Faking configuration. Downloading: " | 163 DVLOG(1) << "Faking configuration. Downloading: " |
209 << ModelTypeSetToString(success_types) << ". Cleaning: " | 164 << ModelTypeSetToString(success_types) << ". Cleaning: " |
210 << ModelTypeSetToString(to_purge); | 165 << ModelTypeSetToString(to_purge); |
211 | 166 |
212 // Update our fake directory by clearing and fake-downloading as necessary. | 167 // Update our fake directory by clearing and fake-downloading as necessary. |
213 UserShare* share = GetUserShare(); | 168 UserShare* share = GetUserShare(); |
214 share->directory->PurgeEntriesWithTypeIn(to_purge, | 169 share->directory->PurgeEntriesWithTypeIn(to_purge, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 239 } |
285 | 240 |
286 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { | 241 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { |
287 return fake_encryption_handler_.get(); | 242 return fake_encryption_handler_.get(); |
288 } | 243 } |
289 | 244 |
290 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { | 245 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { |
291 last_refresh_request_types_ = types; | 246 last_refresh_request_types_ = types; |
292 } | 247 } |
293 | 248 |
294 void FakeSyncManager::InvalidateOnSyncThread( | 249 void FakeSyncManager::OnIncomingInvalidation( |
295 const ObjectIdInvalidationMap& invalidation_map) { | 250 const ObjectIdInvalidationMap& invalidation_map) { |
296 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 251 // Do nothing. |
297 registrar_.DispatchInvalidationsToHandlers(invalidation_map); | |
298 } | |
299 | |
300 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( | |
301 InvalidatorState state) { | |
302 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
303 registrar_.UpdateInvalidatorState(state); | |
304 } | 252 } |
305 | 253 |
306 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { | 254 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { |
307 return last_refresh_request_types_; | 255 return last_refresh_request_types_; |
308 } | 256 } |
309 | 257 |
| 258 void FakeSyncManager::OnInvalidatorStateChange(InvalidatorState state) { |
| 259 // Do nothing. |
| 260 } |
| 261 |
310 } // namespace syncer | 262 } // namespace syncer |
OLD | NEW |