Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / sync / engine / commit_processor.cc
bloba5149acdb4e258e7f9aa55e3534885674ee2b499
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"
7 #include <map>
9 #include "sync/engine/commit_contribution.h"
10 #include "sync/engine/commit_contributor.h"
11 #include "sync/protocol/sync.pb.h"
13 namespace syncer {
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,
24 size_t max_entries,
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()) {
32 NOTREACHED()
33 << "Could not find requested type " << ModelTypeToString(it.Get())
34 << " in contributor map.";
35 continue;
37 size_t spaces_remaining = max_entries - num_entries;
38 scoped_ptr<CommitContribution> contribution =
39 cm_it->second->GetContribution(spaces_remaining);
40 if (contribution) {
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";
47 break;
52 } // namespace syncer