| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 downloaded_types_.Clear(); | 47 downloaded_types_.Clear(); |
| 48 return downloaded_types; | 48 return downloaded_types; |
| 49 } | 49 } |
| 50 | 50 |
| 51 ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { | 51 ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { |
| 52 ModelTypeSet enabled_types = enabled_types_; | 52 ModelTypeSet enabled_types = enabled_types_; |
| 53 enabled_types_.Clear(); | 53 enabled_types_.Clear(); |
| 54 return enabled_types; | 54 return enabled_types; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void FakeSyncManager::Invalidate( | |
| 58 const ObjectIdInvalidationMap& invalidation_map) { | |
| 59 if (!sync_task_runner_->PostTask( | |
| 60 FROM_HERE, | |
| 61 base::Bind(&FakeSyncManager::InvalidateOnSyncThread, | |
| 62 base::Unretained(this), invalidation_map))) { | |
| 63 NOTREACHED(); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void FakeSyncManager::UpdateInvalidatorState(InvalidatorState state) { | |
| 68 if (!sync_task_runner_->PostTask( | |
| 69 FROM_HERE, | |
| 70 base::Bind(&FakeSyncManager::UpdateInvalidatorStateOnSyncThread, | |
| 71 base::Unretained(this), state))) { | |
| 72 NOTREACHED(); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void FakeSyncManager::WaitForSyncThread() { | 57 void FakeSyncManager::WaitForSyncThread() { |
| 77 // Post a task to |sync_task_runner_| and block until it runs. | 58 // Post a task to |sync_task_runner_| and block until it runs. |
| 78 base::RunLoop run_loop; | 59 base::RunLoop run_loop; |
| 79 if (!sync_task_runner_->PostTaskAndReply( | 60 if (!sync_task_runner_->PostTaskAndReply( |
| 80 FROM_HERE, | 61 FROM_HERE, |
| 81 base::Bind(&base::DoNothing), | 62 base::Bind(&base::DoNothing), |
| 82 run_loop.QuitClosure())) { | 63 run_loop.QuitClosure())) { |
| 83 NOTREACHED(); | 64 NOTREACHED(); |
| 84 } | 65 } |
| 85 run_loop.Run(); | 66 run_loop.Run(); |
| 86 } | 67 } |
| 87 | 68 |
| 88 void FakeSyncManager::Init( | 69 void FakeSyncManager::Init( |
| 89 const base::FilePath& database_location, | 70 const base::FilePath& database_location, |
| 90 const WeakHandle<JsEventHandler>& event_handler, | 71 const WeakHandle<JsEventHandler>& event_handler, |
| 91 const std::string& sync_server_and_path, | 72 const std::string& sync_server_and_path, |
| 92 int sync_server_port, | 73 int sync_server_port, |
| 93 bool use_ssl, | 74 bool use_ssl, |
| 94 scoped_ptr<HttpPostProviderFactory> post_factory, | 75 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 95 const std::vector<ModelSafeWorker*>& workers, | 76 const std::vector<ModelSafeWorker*>& workers, |
| 96 ExtensionsActivityMonitor* extensions_activity_monitor, | 77 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 97 ChangeDelegate* change_delegate, | 78 ChangeDelegate* change_delegate, |
| 98 const SyncCredentials& credentials, | 79 const SyncCredentials& credentials, |
| 99 scoped_ptr<Invalidator> invalidator, | |
| 100 const std::string& invalidator_client_id, | 80 const std::string& invalidator_client_id, |
| 101 const std::string& restored_key_for_bootstrapping, | 81 const std::string& restored_key_for_bootstrapping, |
| 102 const std::string& restored_keystore_key_for_bootstrapping, | 82 const std::string& restored_keystore_key_for_bootstrapping, |
| 103 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 83 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 104 Encryptor* encryptor, | 84 Encryptor* encryptor, |
| 105 UnrecoverableErrorHandler* unrecoverable_error_handler, | 85 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 106 ReportUnrecoverableErrorFunction | 86 ReportUnrecoverableErrorFunction |
| 107 report_unrecoverable_error_function) { | 87 report_unrecoverable_error_function) { |
| 108 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 88 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 109 PurgePartiallySyncedTypes(); | 89 PurgePartiallySyncedTypes(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 126 } |
| 147 progress_marker_types_.RemoveAll(partial_types); | 127 progress_marker_types_.RemoveAll(partial_types); |
| 148 cleaned_types_.PutAll(partial_types); | 128 cleaned_types_.PutAll(partial_types); |
| 149 return true; | 129 return true; |
| 150 } | 130 } |
| 151 | 131 |
| 152 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 132 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
| 153 NOTIMPLEMENTED(); | 133 NOTIMPLEMENTED(); |
| 154 } | 134 } |
| 155 | 135 |
| 156 void FakeSyncManager::UpdateEnabledTypes(ModelTypeSet types) { | |
| 157 enabled_types_ = types; | |
| 158 } | |
| 159 | |
| 160 void FakeSyncManager::RegisterInvalidationHandler( | |
| 161 InvalidationHandler* handler) { | |
| 162 registrar_.RegisterHandler(handler); | |
| 163 } | |
| 164 | |
| 165 void FakeSyncManager::UpdateRegisteredInvalidationIds( | |
| 166 InvalidationHandler* handler, | |
| 167 const ObjectIdSet& ids) { | |
| 168 registrar_.UpdateRegisteredIds(handler, ids); | |
| 169 } | |
| 170 | |
| 171 void FakeSyncManager::UnregisterInvalidationHandler( | |
| 172 InvalidationHandler* handler) { | |
| 173 registrar_.UnregisterHandler(handler); | |
| 174 } | |
| 175 | |
| 176 void FakeSyncManager::AcknowledgeInvalidation(const invalidation::ObjectId& id, | |
| 177 const AckHandle& ack_handle) { | |
| 178 // Do nothing. | |
| 179 } | |
| 180 | |
| 181 void FakeSyncManager::StartSyncingNormally( | 136 void FakeSyncManager::StartSyncingNormally( |
| 182 const ModelSafeRoutingInfo& routing_info) { | 137 const ModelSafeRoutingInfo& routing_info) { |
| 183 // Do nothing. | 138 // Do nothing. |
| 184 } | 139 } |
| 185 | 140 |
| 186 void FakeSyncManager::ConfigureSyncer( | 141 void FakeSyncManager::ConfigureSyncer( |
| 187 ConfigureReason reason, | 142 ConfigureReason reason, |
| 188 ModelTypeSet types_to_config, | 143 ModelTypeSet types_to_config, |
| 189 ModelTypeSet failed_types, | 144 ModelTypeSet failed_types, |
| 190 const ModelSafeRoutingInfo& new_routing_info, | 145 const ModelSafeRoutingInfo& new_routing_info, |
| 191 const base::Closure& ready_task, | 146 const base::Closure& ready_task, |
| 192 const base::Closure& retry_task) { | 147 const base::Closure& retry_task) { |
| 193 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 148 enabled_types_ = GetRoutingInfoTypes(new_routing_info); |
| 194 ModelTypeSet disabled_types = Difference( | 149 ModelTypeSet disabled_types = Difference( |
| 195 ModelTypeSet::All(), enabled_types); | 150 ModelTypeSet::All(), enabled_types_); |
| 196 ModelTypeSet success_types = types_to_config; | 151 ModelTypeSet success_types = types_to_config; |
| 197 success_types.RemoveAll(configure_fail_types_); | 152 success_types.RemoveAll(configure_fail_types_); |
| 198 | 153 |
| 199 DVLOG(1) << "Faking configuration. Downloading: " | 154 DVLOG(1) << "Faking configuration. Downloading: " |
| 200 << ModelTypeSetToString(success_types) << ". Cleaning: " | 155 << ModelTypeSetToString(success_types) << ". Cleaning: " |
| 201 << ModelTypeSetToString(disabled_types); | 156 << ModelTypeSetToString(disabled_types); |
| 202 | 157 |
| 203 // Update our fake directory by clearing and fake-downloading as necessary. | 158 // Update our fake directory by clearing and fake-downloading as necessary. |
| 204 UserShare* share = GetUserShare(); | 159 UserShare* share = GetUserShare(); |
| 205 share->directory->PurgeEntriesWithTypeIn(disabled_types, ModelTypeSet()); | 160 share->directory->PurgeEntriesWithTypeIn(disabled_types, ModelTypeSet()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 228 } |
| 274 | 229 |
| 275 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { | 230 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { |
| 276 return fake_encryption_handler_.get(); | 231 return fake_encryption_handler_.get(); |
| 277 } | 232 } |
| 278 | 233 |
| 279 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { | 234 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { |
| 280 last_refresh_request_types_ = types; | 235 last_refresh_request_types_ = types; |
| 281 } | 236 } |
| 282 | 237 |
| 283 void FakeSyncManager::InvalidateOnSyncThread( | 238 void FakeSyncManager::Invalidate( |
| 284 const ObjectIdInvalidationMap& invalidation_map) { | 239 const ObjectIdInvalidationMap& invalidation_map) { |
| 285 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 240 // Do nothing. |
| 286 registrar_.DispatchInvalidationsToHandlers(invalidation_map); | |
| 287 } | |
| 288 | |
| 289 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( | |
| 290 InvalidatorState state) { | |
| 291 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
| 292 registrar_.UpdateInvalidatorState(state); | |
| 293 } | 241 } |
| 294 | 242 |
| 295 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { | 243 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { |
| 296 return last_refresh_request_types_; | 244 return last_refresh_request_types_; |
| 297 } | 245 } |
| 298 | 246 |
| 247 void FakeSyncManager::UpdateInvalidatorState(InvalidatorState state) { |
| 248 // Do nothing. |
| 249 } |
| 250 |
| 299 } // namespace syncer | 251 } // namespace syncer |
| OLD | NEW |