Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sessions/model_type_registry.h" | 5 #include "sync/sessions/model_type_registry.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "sync/engine/directory_commit_contributor.h" | 10 #include "sync/engine/directory_commit_contributor.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 base::Bind(&ModelTypeSyncWorkerImpl::EnqueueForCommit, worker_, list)); | 104 base::Bind(&ModelTypeSyncWorkerImpl::EnqueueForCommit, worker_, list)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 ModelTypeRegistry::ModelTypeRegistry( | 109 ModelTypeRegistry::ModelTypeRegistry( |
| 110 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, | 110 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, |
| 111 syncable::Directory* directory, | 111 syncable::Directory* directory, |
| 112 NudgeHandler* nudge_handler) | 112 NudgeHandler* nudge_handler) |
| 113 : directory_(directory), | 113 : directory_(directory), |
| 114 cryptographer_provider_(directory_), | |
| 115 nudge_handler_(nudge_handler), | 114 nudge_handler_(nudge_handler), |
| 116 weak_ptr_factory_(this) { | 115 weak_ptr_factory_(this) { |
| 117 for (size_t i = 0u; i < workers.size(); ++i) { | 116 for (size_t i = 0u; i < workers.size(); ++i) { |
| 118 workers_map_.insert( | 117 workers_map_.insert( |
| 119 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); | 118 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); |
| 120 } | 119 } |
| 121 } | 120 } |
| 122 | 121 |
| 123 ModelTypeRegistry::~ModelTypeRegistry() {} | 122 ModelTypeRegistry::~ModelTypeRegistry() { |
| 123 } | |
| 124 | 124 |
| 125 void ModelTypeRegistry::SetEnabledDirectoryTypes( | 125 void ModelTypeRegistry::SetEnabledDirectoryTypes( |
| 126 const ModelSafeRoutingInfo& routing_info) { | 126 const ModelSafeRoutingInfo& routing_info) { |
| 127 // Remove all existing directory processors and delete them. The | 127 // Remove all existing directory processors and delete them. The |
| 128 // DebugInfoEmitters are not deleted here, since we want to preserve their | 128 // DebugInfoEmitters are not deleted here, since we want to preserve their |
| 129 // counters. | 129 // counters. |
| 130 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); | 130 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); |
| 131 it.Good(); it.Inc()) { | 131 it.Good(); it.Inc()) { |
| 132 size_t result1 = update_handler_map_.erase(it.Get()); | 132 size_t result1 = update_handler_map_.erase(it.Get()); |
| 133 size_t result2 = commit_contributor_map_.erase(it.Get()); | 133 size_t result2 = commit_contributor_map_.erase(it.Get()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 ModelType type, | 191 ModelType type, |
| 192 const DataTypeState& data_type_state, | 192 const DataTypeState& data_type_state, |
| 193 const UpdateResponseDataList& saved_pending_updates, | 193 const UpdateResponseDataList& saved_pending_updates, |
| 194 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, | 194 const scoped_refptr<base::SequencedTaskRunner>& type_task_runner, |
| 195 const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy_impl) { | 195 const base::WeakPtr<ModelTypeSyncProxyImpl>& proxy_impl) { |
| 196 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); | 196 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); |
| 197 | 197 |
| 198 // Initialize Worker -> Proxy communication channel. | 198 // Initialize Worker -> Proxy communication channel. |
| 199 scoped_ptr<ModelTypeSyncProxy> proxy( | 199 scoped_ptr<ModelTypeSyncProxy> proxy( |
| 200 new ModelTypeSyncProxyWrapper(proxy_impl, type_task_runner)); | 200 new ModelTypeSyncProxyWrapper(proxy_impl, type_task_runner)); |
| 201 scoped_ptr<Cryptographer> cryptographer_copy; | |
| 202 if (encrypted_types_.Has(type)) | |
| 203 cryptographer_copy.reset(new Cryptographer(*cryptographer_)); | |
| 204 | |
| 201 scoped_ptr<ModelTypeSyncWorkerImpl> worker( | 205 scoped_ptr<ModelTypeSyncWorkerImpl> worker( |
| 202 new ModelTypeSyncWorkerImpl(type, | 206 new ModelTypeSyncWorkerImpl(type, |
| 203 data_type_state, | 207 data_type_state, |
| 204 saved_pending_updates, | 208 saved_pending_updates, |
| 205 &cryptographer_provider_, | 209 cryptographer_copy.Pass(), |
| 206 nudge_handler_, | 210 nudge_handler_, |
| 207 proxy.Pass())); | 211 proxy.Pass())); |
| 208 | 212 |
| 209 // Initialize Proxy -> Worker communication channel. | 213 // Initialize Proxy -> Worker communication channel. |
| 210 scoped_ptr<ModelTypeSyncWorker> wrapped_worker( | 214 scoped_ptr<ModelTypeSyncWorker> wrapped_worker( |
| 211 new ModelTypeSyncWorkerWrapper(worker->AsWeakPtr(), | 215 new ModelTypeSyncWorkerWrapper(worker->AsWeakPtr(), |
| 212 scoped_refptr<base::SequencedTaskRunner>( | 216 scoped_refptr<base::SequencedTaskRunner>( |
| 213 base::ThreadTaskRunnerHandle::Get()))); | 217 base::ThreadTaskRunnerHandle::Get()))); |
| 214 type_task_runner->PostTask(FROM_HERE, | 218 type_task_runner->PostTask(FROM_HERE, |
| 215 base::Bind(&ModelTypeSyncProxyImpl::OnConnect, | 219 base::Bind(&ModelTypeSyncProxyImpl::OnConnect, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 it->second->EmitCommitCountersUpdate(); | 296 it->second->EmitCommitCountersUpdate(); |
| 293 it->second->EmitUpdateCountersUpdate(); | 297 it->second->EmitUpdateCountersUpdate(); |
| 294 it->second->EmitStatusCountersUpdate(); | 298 it->second->EmitStatusCountersUpdate(); |
| 295 } | 299 } |
| 296 } | 300 } |
| 297 | 301 |
| 298 base::WeakPtr<SyncContext> ModelTypeRegistry::AsWeakPtr() { | 302 base::WeakPtr<SyncContext> ModelTypeRegistry::AsWeakPtr() { |
| 299 return weak_ptr_factory_.GetWeakPtr(); | 303 return weak_ptr_factory_.GetWeakPtr(); |
| 300 } | 304 } |
| 301 | 305 |
| 306 void ModelTypeRegistry::OnPassphraseRequired( | |
| 307 PassphraseRequiredReason reason, | |
| 308 const sync_pb::EncryptedData& pending_keys) { | |
| 309 } | |
| 310 | |
| 311 void ModelTypeRegistry::OnPassphraseAccepted() { | |
| 312 } | |
| 313 | |
| 314 void ModelTypeRegistry::OnBootstrapTokenUpdated( | |
| 315 const std::string& bootstrap_token, | |
| 316 BootstrapTokenType type) { | |
| 317 } | |
| 318 | |
| 319 void ModelTypeRegistry::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | |
| 320 bool encrypt_everything) { | |
| 321 VLOG(1) << "MTR: OnEncryptedTypesChanged"; | |
| 322 encrypted_types_ = encrypted_types; | |
| 323 OnEncryptionStateChanged(); | |
| 324 } | |
| 325 | |
| 326 void ModelTypeRegistry::OnEncryptionComplete() { | |
| 327 } | |
| 328 | |
| 329 void ModelTypeRegistry::OnCryptographerStateChanged( | |
| 330 Cryptographer* cryptographer) { | |
| 331 VLOG(1) << "MTR: OnCryptographerStateChanged"; | |
| 332 cryptographer_.reset(new Cryptographer(*cryptographer)); | |
| 333 OnEncryptionStateChanged(); | |
| 334 } | |
| 335 | |
| 336 void ModelTypeRegistry::OnPassphraseTypeChanged(PassphraseType type, | |
| 337 base::Time passphrase_time) { | |
| 338 } | |
| 339 | |
| 302 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { | 340 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { |
| 303 return enabled_directory_types_; | 341 return enabled_directory_types_; |
| 304 } | 342 } |
| 305 | 343 |
| 344 void ModelTypeRegistry::OnEncryptionStateChanged() { | |
| 345 VLOG(1) << "MTR: OnEncryptionStateChanged"; | |
| 346 for (ScopedVector<ModelTypeSyncWorkerImpl>::iterator it = | |
| 347 model_type_sync_workers_.begin(); | |
| 348 it != model_type_sync_workers_.end(); | |
| 349 ++it) { | |
| 350 if (encrypted_types_.Has((*it)->GetModelType())) { | |
| 351 (*it)->UpdateCryptographer( | |
| 352 make_scoped_ptr<Cryptographer>(new Cryptographer(*cryptographer_))); | |
|
stanisc
2014/08/11 21:05:42
I think the "<Cryptographer>" part is redundant.
rlarocque
2014/08/11 21:50:22
You're right. Fixed.
| |
| 353 } | |
| 354 } | |
| 355 } | |
| 356 | |
| 306 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { | 357 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { |
| 307 ModelTypeSet enabled_off_thread_types; | 358 ModelTypeSet enabled_off_thread_types; |
| 308 for (ScopedVector<ModelTypeSyncWorkerImpl>::const_iterator it = | 359 for (ScopedVector<ModelTypeSyncWorkerImpl>::const_iterator it = |
| 309 model_type_sync_workers_.begin(); | 360 model_type_sync_workers_.begin(); |
| 310 it != model_type_sync_workers_.end(); | 361 it != model_type_sync_workers_.end(); |
| 311 ++it) { | 362 ++it) { |
| 312 enabled_off_thread_types.Put((*it)->GetModelType()); | 363 enabled_off_thread_types.Put((*it)->GetModelType()); |
| 313 } | 364 } |
| 314 return enabled_off_thread_types; | 365 return enabled_off_thread_types; |
| 315 } | 366 } |
| 316 | 367 |
| 317 } // namespace syncer | 368 } // namespace syncer |
| OLD | NEW |