| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ptr_util.h" |
| 11 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 12 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 13 #include "sync/engine/commit_queue.h" | 15 #include "sync/engine/commit_queue.h" |
| 14 #include "sync/engine/directory_commit_contributor.h" | 16 #include "sync/engine/directory_commit_contributor.h" |
| 15 #include "sync/engine/directory_update_handler.h" | 17 #include "sync/engine/directory_update_handler.h" |
| 16 #include "sync/engine/model_type_worker.h" | 18 #include "sync/engine/model_type_worker.h" |
| 17 #include "sync/internal_api/public/activation_context.h" | 19 #include "sync/internal_api/public/activation_context.h" |
| 18 #include "sync/internal_api/public/model_type_processor.h" | 20 #include "sync/internal_api/public/model_type_processor.h" |
| 19 #include "sync/sessions/directory_type_debug_info_emitter.h" | 21 #include "sync/sessions/directory_type_debug_info_emitter.h" |
| 20 #include "sync/util/cryptographer.h" | 22 #include "sync/util/cryptographer.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 DCHECK(inserted2) << "Attempt to override existing type handler in map"; | 134 DCHECK(inserted2) << "Attempt to override existing type handler in map"; |
| 133 enabled_directory_types_.Put(type); | 135 enabled_directory_types_.Put(type); |
| 134 } | 136 } |
| 135 | 137 |
| 136 DCHECK(Intersection(GetEnabledDirectoryTypes(), | 138 DCHECK(Intersection(GetEnabledDirectoryTypes(), |
| 137 GetEnabledNonBlockingTypes()).Empty()); | 139 GetEnabledNonBlockingTypes()).Empty()); |
| 138 } | 140 } |
| 139 | 141 |
| 140 void ModelTypeRegistry::ConnectSyncTypeToWorker( | 142 void ModelTypeRegistry::ConnectSyncTypeToWorker( |
| 141 ModelType type, | 143 ModelType type, |
| 142 scoped_ptr<syncer_v2::ActivationContext> activation_context) { | 144 std::unique_ptr<syncer_v2::ActivationContext> activation_context) { |
| 143 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); | 145 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); |
| 144 | 146 |
| 145 // Initialize Worker -> Processor communication channel. | 147 // Initialize Worker -> Processor communication channel. |
| 146 syncer_v2::ModelTypeProcessor* type_processor = | 148 syncer_v2::ModelTypeProcessor* type_processor = |
| 147 activation_context->type_processor.get(); | 149 activation_context->type_processor.get(); |
| 148 | 150 |
| 149 scoped_ptr<Cryptographer> cryptographer_copy; | 151 std::unique_ptr<Cryptographer> cryptographer_copy; |
| 150 if (encrypted_types_.Has(type)) | 152 if (encrypted_types_.Has(type)) |
| 151 cryptographer_copy.reset(new Cryptographer(*cryptographer_)); | 153 cryptographer_copy.reset(new Cryptographer(*cryptographer_)); |
| 152 | 154 |
| 153 scoped_ptr<syncer_v2::ModelTypeWorker> worker(new syncer_v2::ModelTypeWorker( | 155 std::unique_ptr<syncer_v2::ModelTypeWorker> worker( |
| 154 type, activation_context->data_type_state, std::move(cryptographer_copy), | 156 new syncer_v2::ModelTypeWorker( |
| 155 nudge_handler_, std::move(activation_context->type_processor))); | 157 type, activation_context->data_type_state, |
| 158 std::move(cryptographer_copy), nudge_handler_, |
| 159 std::move(activation_context->type_processor))); |
| 156 | 160 |
| 157 // Initialize Processor -> Worker communication channel. | 161 // Initialize Processor -> Worker communication channel. |
| 158 scoped_ptr<syncer_v2::CommitQueue> commit_queue_proxy(new CommitQueueProxy( | 162 std::unique_ptr<syncer_v2::CommitQueue> commit_queue_proxy( |
| 159 worker->AsWeakPtr(), scoped_refptr<base::SequencedTaskRunner>( | 163 new CommitQueueProxy(worker->AsWeakPtr(), |
| 164 scoped_refptr<base::SequencedTaskRunner>( |
| 160 base::ThreadTaskRunnerHandle::Get()))); | 165 base::ThreadTaskRunnerHandle::Get()))); |
| 161 | 166 |
| 162 type_processor->ConnectSync(std::move(commit_queue_proxy)); | 167 type_processor->ConnectSync(std::move(commit_queue_proxy)); |
| 163 | 168 |
| 164 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); | 169 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); |
| 165 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); | 170 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); |
| 166 | 171 |
| 167 update_handler_map_.insert(std::make_pair(type, worker.get())); | 172 update_handler_map_.insert(std::make_pair(type, worker.get())); |
| 168 commit_contributor_map_.insert(std::make_pair(type, worker.get())); | 173 commit_contributor_map_.insert(std::make_pair(type, worker.get())); |
| 169 | 174 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { | 287 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { |
| 283 return enabled_directory_types_; | 288 return enabled_directory_types_; |
| 284 } | 289 } |
| 285 | 290 |
| 286 void ModelTypeRegistry::OnEncryptionStateChanged() { | 291 void ModelTypeRegistry::OnEncryptionStateChanged() { |
| 287 for (ScopedVector<syncer_v2::ModelTypeWorker>::iterator it = | 292 for (ScopedVector<syncer_v2::ModelTypeWorker>::iterator it = |
| 288 model_type_workers_.begin(); | 293 model_type_workers_.begin(); |
| 289 it != model_type_workers_.end(); ++it) { | 294 it != model_type_workers_.end(); ++it) { |
| 290 if (encrypted_types_.Has((*it)->GetModelType())) { | 295 if (encrypted_types_.Has((*it)->GetModelType())) { |
| 291 (*it)->UpdateCryptographer( | 296 (*it)->UpdateCryptographer( |
| 292 make_scoped_ptr(new Cryptographer(*cryptographer_))); | 297 base::WrapUnique(new Cryptographer(*cryptographer_))); |
| 293 } | 298 } |
| 294 } | 299 } |
| 295 } | 300 } |
| 296 | 301 |
| 297 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { | 302 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { |
| 298 ModelTypeSet enabled_non_blocking_types; | 303 ModelTypeSet enabled_non_blocking_types; |
| 299 for (ScopedVector<syncer_v2::ModelTypeWorker>::const_iterator it = | 304 for (ScopedVector<syncer_v2::ModelTypeWorker>::const_iterator it = |
| 300 model_type_workers_.begin(); | 305 model_type_workers_.begin(); |
| 301 it != model_type_workers_.end(); ++it) { | 306 it != model_type_workers_.end(); ++it) { |
| 302 enabled_non_blocking_types.Put((*it)->GetModelType()); | 307 enabled_non_blocking_types.Put((*it)->GetModelType()); |
| 303 } | 308 } |
| 304 return enabled_non_blocking_types; | 309 return enabled_non_blocking_types; |
| 305 } | 310 } |
| 306 | 311 |
| 307 } // namespace syncer | 312 } // namespace syncer |
| OLD | NEW |