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