OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sync/engine/model_type_registry.h" |
| 6 |
| 7 #include "sync/engine/committer_list.h" |
| 8 #include "sync/engine/sync_directory_commit_contributor.h" |
| 9 #include "sync/engine/sync_directory_update_handler.h" |
| 10 #include "sync/engine/updater_list.h" |
| 11 |
| 12 namespace syncer { |
| 13 |
| 14 ModelTypeRegistry::ModelTypeRegistry( |
| 15 const std::vector<ModelSafeWorker* >& workers, |
| 16 syncable::Directory* directory) |
| 17 : update_handler_deleter_(&update_handler_map_), |
| 18 commit_contributor_deleter_(&commit_contributor_map_), |
| 19 directory_(directory) { |
| 20 for (size_t i = 0u; i < workers.size(); ++i) { |
| 21 workers_map_.insert( |
| 22 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); |
| 23 } |
| 24 } |
| 25 |
| 26 ModelTypeRegistry::~ModelTypeRegistry() {} |
| 27 |
| 28 void ModelTypeRegistry::SetEnabledDirectoryTypes( |
| 29 const ModelSafeRoutingInfo& routing_info) { |
| 30 STLDeleteValues(&update_handler_map_); |
| 31 STLDeleteValues(&commit_contributor_map_); |
| 32 update_handler_map_.clear(); |
| 33 commit_contributor_map_.clear(); |
| 34 |
| 35 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); |
| 36 routing_iter != routing_info.end(); ++routing_iter) { |
| 37 ModelType type = routing_iter->first; |
| 38 ModelSafeGroup group = routing_iter->second; |
| 39 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> >::iterator |
| 40 worker_it = workers_map_.find(group); |
| 41 DCHECK(worker_it != workers_map_.end()); |
| 42 scoped_refptr<ModelSafeWorker> worker = worker_it->second; |
| 43 |
| 44 SyncDirectoryCommitContributor* committer = |
| 45 new SyncDirectoryCommitContributor(directory_, type); |
| 46 SyncDirectoryUpdateHandler* updater = |
| 47 new SyncDirectoryUpdateHandler(directory_, type, worker); |
| 48 |
| 49 bool inserted1 = |
| 50 update_handler_map_.insert(std::make_pair(type, updater)).second; |
| 51 DCHECK(inserted1) << "Attempt to override existing type handler in map"; |
| 52 |
| 53 bool inserted2 = |
| 54 commit_contributor_map_.insert(std::make_pair(type, committer)).second; |
| 55 DCHECK(inserted2) << "Attempt to override existing type handler in map"; |
| 56 |
| 57 } |
| 58 } |
| 59 |
| 60 UpdateHandlerMap* ModelTypeRegistry::update_handler_map() { |
| 61 return &update_handler_map_; |
| 62 } |
| 63 |
| 64 CommitContributorMap* ModelTypeRegistry::commit_contributor_map() { |
| 65 return &commit_contributor_map_; |
| 66 } |
| 67 |
| 68 } // namespace syncer |
OLD | NEW |