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/engine/commit_processor.h"
9 #include "sync/engine/commit_contribution.h"
10 #include "sync/engine/commit_contributor.h"
11 #include "sync/protocol/sync.pb.h"
15 typedef std::map
<ModelType
, size_t> TypeToIndexMap
;
17 CommitProcessor::CommitProcessor(CommitContributorMap
* commit_contributor_map
)
18 : commit_contributor_map_(commit_contributor_map
) {}
20 CommitProcessor::~CommitProcessor() {}
22 void CommitProcessor::GatherCommitContributions(
23 ModelTypeSet commit_types
,
25 Commit::ContributionMap
* contributions
) {
26 size_t num_entries
= 0;
27 for (ModelTypeSet::Iterator it
= commit_types
.First();
28 it
.Good(); it
.Inc()) {
29 CommitContributorMap::iterator cm_it
=
30 commit_contributor_map_
->find(it
.Get());
31 if (cm_it
== commit_contributor_map_
->end()) {
33 << "Could not find requested type " << ModelTypeToString(it
.Get())
34 << " in contributor map.";
37 size_t spaces_remaining
= max_entries
- num_entries
;
38 scoped_ptr
<CommitContribution
> contribution
=
39 cm_it
->second
->GetContribution(spaces_remaining
);
41 num_entries
+= contribution
->GetNumEntries();
42 contributions
->insert(it
.Get(), contribution
.Pass());
44 if (num_entries
>= max_entries
) {
45 DCHECK_EQ(num_entries
, max_entries
)
46 << "Number of commit entries exceeeds maximum";