| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/engine/commit_processor.h" | 5 #include "components/sync/engine_impl/commit_processor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "sync/engine/commit_contribution.h" | 12 #include "components/sync/engine_impl/commit_contribution.h" |
| 13 #include "sync/engine/commit_contributor.h" | 13 #include "components/sync/engine_impl/commit_contributor.h" |
| 14 #include "sync/protocol/sync.pb.h" | 14 #include "components/sync/protocol/sync.pb.h" |
| 15 | 15 |
| 16 namespace syncer { | 16 namespace syncer { |
| 17 | 17 |
| 18 typedef std::map<ModelType, size_t> TypeToIndexMap; | 18 typedef std::map<ModelType, size_t> TypeToIndexMap; |
| 19 | 19 |
| 20 CommitProcessor::CommitProcessor(CommitContributorMap* commit_contributor_map) | 20 CommitProcessor::CommitProcessor(CommitContributorMap* commit_contributor_map) |
| 21 : commit_contributor_map_(commit_contributor_map) {} | 21 : commit_contributor_map_(commit_contributor_map) {} |
| 22 | 22 |
| 23 CommitProcessor::~CommitProcessor() {} | 23 CommitProcessor::~CommitProcessor() {} |
| 24 | 24 |
| 25 void CommitProcessor::GatherCommitContributions( | 25 void CommitProcessor::GatherCommitContributions( |
| 26 ModelTypeSet commit_types, | 26 ModelTypeSet commit_types, |
| 27 size_t max_entries, | 27 size_t max_entries, |
| 28 bool cookie_jar_mismatch, | 28 bool cookie_jar_mismatch, |
| 29 bool cookie_jar_empty, | 29 bool cookie_jar_empty, |
| 30 Commit::ContributionMap* contributions) { | 30 Commit::ContributionMap* contributions) { |
| 31 size_t num_entries = 0; | 31 size_t num_entries = 0; |
| 32 for (ModelTypeSet::Iterator it = commit_types.First(); | 32 for (ModelTypeSet::Iterator it = commit_types.First(); it.Good(); it.Inc()) { |
| 33 it.Good(); it.Inc()) { | |
| 34 CommitContributorMap::iterator cm_it = | 33 CommitContributorMap::iterator cm_it = |
| 35 commit_contributor_map_->find(it.Get()); | 34 commit_contributor_map_->find(it.Get()); |
| 36 if (cm_it == commit_contributor_map_->end()) { | 35 if (cm_it == commit_contributor_map_->end()) { |
| 37 NOTREACHED() | 36 NOTREACHED() << "Could not find requested type " |
| 38 << "Could not find requested type " << ModelTypeToString(it.Get()) | 37 << ModelTypeToString(it.Get()) << " in contributor map."; |
| 39 << " in contributor map."; | |
| 40 continue; | 38 continue; |
| 41 } | 39 } |
| 42 size_t spaces_remaining = max_entries - num_entries; | 40 size_t spaces_remaining = max_entries - num_entries; |
| 43 std::unique_ptr<CommitContribution> contribution = | 41 std::unique_ptr<CommitContribution> contribution = |
| 44 cm_it->second->GetContribution(spaces_remaining); | 42 cm_it->second->GetContribution(spaces_remaining); |
| 45 if (contribution) { | 43 if (contribution) { |
| 46 num_entries += contribution->GetNumEntries(); | 44 num_entries += contribution->GetNumEntries(); |
| 47 contributions->insert(std::make_pair(it.Get(), std::move(contribution))); | 45 contributions->insert(std::make_pair(it.Get(), std::move(contribution))); |
| 48 | 46 |
| 49 if (it.Get() == SESSIONS) { | 47 if (it.Get() == SESSIONS) { |
| 50 UMA_HISTOGRAM_BOOLEAN("Sync.CookieJarMatchOnNavigation", | 48 UMA_HISTOGRAM_BOOLEAN("Sync.CookieJarMatchOnNavigation", |
| 51 !cookie_jar_mismatch); | 49 !cookie_jar_mismatch); |
| 52 if (cookie_jar_mismatch) { | 50 if (cookie_jar_mismatch) { |
| 53 UMA_HISTOGRAM_BOOLEAN("Sync.CookieJarEmptyOnMismatch", | 51 UMA_HISTOGRAM_BOOLEAN("Sync.CookieJarEmptyOnMismatch", |
| 54 cookie_jar_empty); | 52 cookie_jar_empty); |
| 55 } | 53 } |
| 56 } | 54 } |
| 57 } | 55 } |
| 58 if (num_entries >= max_entries) { | 56 if (num_entries >= max_entries) { |
| 59 DCHECK_EQ(num_entries, max_entries) | 57 DCHECK_EQ(num_entries, max_entries) |
| 60 << "Number of commit entries exceeeds maximum"; | 58 << "Number of commit entries exceeeds maximum"; |
| 61 break; | 59 break; |
| 62 } | 60 } |
| 63 } | 61 } |
| 64 } | 62 } |
| 65 | 63 |
| 66 } // namespace syncer | 64 } // namespace syncer |
| OLD | NEW |