| 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 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 95 sync_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 116 PurgePartiallySyncedTypes(); | 96 PurgePartiallySyncedTypes(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 133 } |
| 154 progress_marker_types_.RemoveAll(partial_types); | 134 progress_marker_types_.RemoveAll(partial_types); |
| 155 cleaned_types_.PutAll(partial_types); | 135 cleaned_types_.PutAll(partial_types); |
| 156 return true; | 136 return true; |
| 157 } | 137 } |
| 158 | 138 |
| 159 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { | 139 void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { |
| 160 NOTIMPLEMENTED(); | 140 NOTIMPLEMENTED(); |
| 161 } | 141 } |
| 162 | 142 |
| 163 void FakeSyncManager::UpdateEnabledTypes(ModelTypeSet types) { | |
| 164 enabled_types_ = types; | |
| 165 } | |
| 166 | |
| 167 void FakeSyncManager::RegisterInvalidationHandler( | |
| 168 InvalidationHandler* handler) { | |
| 169 registrar_.RegisterHandler(handler); | |
| 170 } | |
| 171 | |
| 172 void FakeSyncManager::UpdateRegisteredInvalidationIds( | |
| 173 InvalidationHandler* handler, | |
| 174 const ObjectIdSet& ids) { | |
| 175 registrar_.UpdateRegisteredIds(handler, ids); | |
| 176 } | |
| 177 | |
| 178 void FakeSyncManager::UnregisterInvalidationHandler( | |
| 179 InvalidationHandler* handler) { | |
| 180 registrar_.UnregisterHandler(handler); | |
| 181 } | |
| 182 | |
| 183 void FakeSyncManager::AcknowledgeInvalidation(const invalidation::ObjectId& id, | |
| 184 const AckHandle& ack_handle) { | |
| 185 // Do nothing. | |
| 186 } | |
| 187 | |
| 188 void FakeSyncManager::StartSyncingNormally( | 143 void FakeSyncManager::StartSyncingNormally( |
| 189 const ModelSafeRoutingInfo& routing_info) { | 144 const ModelSafeRoutingInfo& routing_info) { |
| 190 // Do nothing. | 145 // Do nothing. |
| 191 } | 146 } |
| 192 | 147 |
| 193 void FakeSyncManager::ConfigureSyncer( | 148 void FakeSyncManager::ConfigureSyncer( |
| 194 ConfigureReason reason, | 149 ConfigureReason reason, |
| 195 ModelTypeSet types_to_config, | 150 ModelTypeSet types_to_config, |
| 196 ModelTypeSet failed_types, | 151 ModelTypeSet failed_types, |
| 197 const ModelSafeRoutingInfo& new_routing_info, | 152 const ModelSafeRoutingInfo& new_routing_info, |
| 198 const base::Closure& ready_task, | 153 const base::Closure& ready_task, |
| 199 const base::Closure& retry_task) { | 154 const base::Closure& retry_task) { |
| 200 last_configure_reason_ = reason; | 155 last_configure_reason_ = reason; |
| 201 ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); | 156 enabled_types_ = GetRoutingInfoTypes(new_routing_info); |
| 202 ModelTypeSet disabled_types = Difference( | 157 ModelTypeSet disabled_types = Difference( |
| 203 ModelTypeSet::All(), enabled_types); | 158 ModelTypeSet::All(), enabled_types_); |
| 204 ModelTypeSet success_types = types_to_config; | 159 ModelTypeSet success_types = types_to_config; |
| 205 success_types.RemoveAll(configure_fail_types_); | 160 success_types.RemoveAll(configure_fail_types_); |
| 206 | 161 |
| 207 DVLOG(1) << "Faking configuration. Downloading: " | 162 DVLOG(1) << "Faking configuration. Downloading: " |
| 208 << ModelTypeSetToString(success_types) << ". Cleaning: " | 163 << ModelTypeSetToString(success_types) << ". Cleaning: " |
| 209 << ModelTypeSetToString(disabled_types); | 164 << ModelTypeSetToString(disabled_types); |
| 210 | 165 |
| 211 // Update our fake directory by clearing and fake-downloading as necessary. | 166 // Update our fake directory by clearing and fake-downloading as necessary. |
| 212 UserShare* share = GetUserShare(); | 167 UserShare* share = GetUserShare(); |
| 213 share->directory->PurgeEntriesWithTypeIn(disabled_types, ModelTypeSet()); | 168 share->directory->PurgeEntriesWithTypeIn(disabled_types, ModelTypeSet()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 236 } |
| 282 | 237 |
| 283 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { | 238 SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { |
| 284 return fake_encryption_handler_.get(); | 239 return fake_encryption_handler_.get(); |
| 285 } | 240 } |
| 286 | 241 |
| 287 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { | 242 void FakeSyncManager::RefreshTypes(ModelTypeSet types) { |
| 288 last_refresh_request_types_ = types; | 243 last_refresh_request_types_ = types; |
| 289 } | 244 } |
| 290 | 245 |
| 291 void FakeSyncManager::InvalidateOnSyncThread( | 246 void FakeSyncManager::OnIncomingInvalidation( |
| 292 const ObjectIdInvalidationMap& invalidation_map) { | 247 const ObjectIdInvalidationMap& invalidation_map) { |
| 293 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | 248 // Do nothing. |
| 294 registrar_.DispatchInvalidationsToHandlers(invalidation_map); | |
| 295 } | |
| 296 | |
| 297 void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( | |
| 298 InvalidatorState state) { | |
| 299 DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); | |
| 300 registrar_.UpdateInvalidatorState(state); | |
| 301 } | 249 } |
| 302 | 250 |
| 303 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { | 251 ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { |
| 304 return last_refresh_request_types_; | 252 return last_refresh_request_types_; |
| 305 } | 253 } |
| 306 | 254 |
| 255 void FakeSyncManager::OnInvalidatorStateChange(InvalidatorState state) { |
| 256 // Do nothing. |
| 257 } |
| 258 |
| 307 } // namespace syncer | 259 } // namespace syncer |
| OLD | NEW |