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
3 // found in the LICENSE file.
5 #include "sync/sessions/model_type_registry.h"
7 #include "sync/engine/sync_directory_commit_contributor.h"
8 #include "sync/engine/sync_directory_update_handler.h"
12 ModelTypeRegistry::ModelTypeRegistry(
13 const std::vector
<scoped_refptr
<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
) {
20 std::make_pair(workers
[i
]->GetModelSafeGroup(), workers
[i
]));
24 ModelTypeRegistry::~ModelTypeRegistry() {}
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();
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
;
42 SyncDirectoryCommitContributor
* committer
=
43 new SyncDirectoryCommitContributor(directory_
, type
);
44 SyncDirectoryUpdateHandler
* updater
=
45 new SyncDirectoryUpdateHandler(directory_
, type
, worker
);
48 update_handler_map_
.insert(std::make_pair(type
, updater
)).second
;
49 DCHECK(inserted1
) << "Attempt to override existing type handler in map";
52 commit_contributor_map_
.insert(std::make_pair(type
, committer
)).second
;
53 DCHECK(inserted2
) << "Attempt to override existing type handler in map";
58 UpdateHandlerMap
* ModelTypeRegistry::update_handler_map() {
59 return &update_handler_map_
;
62 CommitContributorMap
* ModelTypeRegistry::commit_contributor_map() {
63 return &commit_contributor_map_
;