| 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 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 12 #include "sync/engine/commit_queue.h" | 13 #include "sync/engine/commit_queue.h" |
| 13 #include "sync/engine/directory_commit_contributor.h" | 14 #include "sync/engine/directory_commit_contributor.h" |
| 14 #include "sync/engine/directory_update_handler.h" | 15 #include "sync/engine/directory_update_handler.h" |
| 15 #include "sync/engine/model_type_worker.h" | 16 #include "sync/engine/model_type_worker.h" |
| 16 #include "sync/internal_api/public/activation_context.h" | 17 #include "sync/internal_api/public/activation_context.h" |
| 17 #include "sync/internal_api/public/model_type_processor.h" | 18 #include "sync/internal_api/public/model_type_processor.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Initialize Worker -> Processor communication channel. | 141 // Initialize Worker -> Processor communication channel. |
| 141 syncer_v2::ModelTypeProcessor* type_processor = | 142 syncer_v2::ModelTypeProcessor* type_processor = |
| 142 activation_context->type_processor.get(); | 143 activation_context->type_processor.get(); |
| 143 | 144 |
| 144 scoped_ptr<Cryptographer> cryptographer_copy; | 145 scoped_ptr<Cryptographer> cryptographer_copy; |
| 145 if (encrypted_types_.Has(type)) | 146 if (encrypted_types_.Has(type)) |
| 146 cryptographer_copy.reset(new Cryptographer(*cryptographer_)); | 147 cryptographer_copy.reset(new Cryptographer(*cryptographer_)); |
| 147 | 148 |
| 148 scoped_ptr<syncer_v2::ModelTypeWorker> worker(new syncer_v2::ModelTypeWorker( | 149 scoped_ptr<syncer_v2::ModelTypeWorker> worker(new syncer_v2::ModelTypeWorker( |
| 149 type, activation_context->data_type_state, | 150 type, activation_context->data_type_state, |
| 150 activation_context->saved_pending_updates, cryptographer_copy.Pass(), | 151 activation_context->saved_pending_updates, std::move(cryptographer_copy), |
| 151 nudge_handler_, activation_context->type_processor.Pass())); | 152 nudge_handler_, std::move(activation_context->type_processor))); |
| 152 | 153 |
| 153 // Initialize Processor -> Worker communication channel. | 154 // Initialize Processor -> Worker communication channel. |
| 154 scoped_ptr<syncer_v2::CommitQueue> commit_queue_proxy(new CommitQueueProxy( | 155 scoped_ptr<syncer_v2::CommitQueue> commit_queue_proxy(new CommitQueueProxy( |
| 155 worker->AsWeakPtr(), scoped_refptr<base::SequencedTaskRunner>( | 156 worker->AsWeakPtr(), scoped_refptr<base::SequencedTaskRunner>( |
| 156 base::ThreadTaskRunnerHandle::Get()))); | 157 base::ThreadTaskRunnerHandle::Get()))); |
| 157 | 158 |
| 158 type_processor->OnConnect(commit_queue_proxy.Pass()); | 159 type_processor->OnConnect(std::move(commit_queue_proxy)); |
| 159 | 160 |
| 160 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); | 161 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); |
| 161 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); | 162 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); |
| 162 | 163 |
| 163 update_handler_map_.insert(std::make_pair(type, worker.get())); | 164 update_handler_map_.insert(std::make_pair(type, worker.get())); |
| 164 commit_contributor_map_.insert(std::make_pair(type, worker.get())); | 165 commit_contributor_map_.insert(std::make_pair(type, worker.get())); |
| 165 | 166 |
| 166 // The container takes ownership. | 167 // The container takes ownership. |
| 167 model_type_workers_.push_back(worker.Pass()); | 168 model_type_workers_.push_back(std::move(worker)); |
| 168 | 169 |
| 169 DCHECK(Intersection(GetEnabledDirectoryTypes(), | 170 DCHECK(Intersection(GetEnabledDirectoryTypes(), |
| 170 GetEnabledNonBlockingTypes()).Empty()); | 171 GetEnabledNonBlockingTypes()).Empty()); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void ModelTypeRegistry::DisconnectSyncWorker(ModelType type) { | 174 void ModelTypeRegistry::DisconnectSyncWorker(ModelType type) { |
| 174 DVLOG(1) << "Disabling an off-thread sync type: " << ModelTypeToString(type); | 175 DVLOG(1) << "Disabling an off-thread sync type: " << ModelTypeToString(type); |
| 175 DCHECK(update_handler_map_.find(type) != update_handler_map_.end()); | 176 DCHECK(update_handler_map_.find(type) != update_handler_map_.end()); |
| 176 DCHECK(commit_contributor_map_.find(type) != commit_contributor_map_.end()); | 177 DCHECK(commit_contributor_map_.find(type) != commit_contributor_map_.end()); |
| 177 | 178 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 ModelTypeSet enabled_off_thread_types; | 295 ModelTypeSet enabled_off_thread_types; |
| 295 for (ScopedVector<syncer_v2::ModelTypeWorker>::const_iterator it = | 296 for (ScopedVector<syncer_v2::ModelTypeWorker>::const_iterator it = |
| 296 model_type_workers_.begin(); | 297 model_type_workers_.begin(); |
| 297 it != model_type_workers_.end(); ++it) { | 298 it != model_type_workers_.end(); ++it) { |
| 298 enabled_off_thread_types.Put((*it)->GetModelType()); | 299 enabled_off_thread_types.Put((*it)->GetModelType()); |
| 299 } | 300 } |
| 300 return enabled_off_thread_types; | 301 return enabled_off_thread_types; |
| 301 } | 302 } |
| 302 | 303 |
| 303 } // namespace syncer | 304 } // namespace syncer |
| OLD | NEW |