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