Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: sync/sessions/ordered_commit_set.cc

Issue 23694004: sync: Remove IDs from OrderedCommitSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/sessions/ordered_commit_set.h ('k') | sync/sessions/ordered_commit_set_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sessions/ordered_commit_set.h" 5 #include "sync/sessions/ordered_commit_set.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace syncer { 11 namespace syncer {
12 namespace sessions { 12 namespace sessions {
13 13
14 OrderedCommitSet::OrderedCommitSet(const ModelSafeRoutingInfo& routes) 14 OrderedCommitSet::OrderedCommitSet(const ModelSafeRoutingInfo& routes)
15 : routes_(routes) { 15 : routes_(routes) {
16 } 16 }
17 17
18 OrderedCommitSet::~OrderedCommitSet() {} 18 OrderedCommitSet::~OrderedCommitSet() {}
19 19
20 void OrderedCommitSet::AddCommitItem(const int64 metahandle, 20 void OrderedCommitSet::AddCommitItem(const int64 metahandle,
21 const syncable::Id& commit_id,
22 ModelType type) { 21 ModelType type) {
23 if (!HaveCommitItem(metahandle)) { 22 if (!HaveCommitItem(metahandle)) {
24 inserted_metahandles_.insert(metahandle); 23 inserted_metahandles_.insert(metahandle);
25 metahandle_order_.push_back(metahandle); 24 metahandle_order_.push_back(metahandle);
26 commit_ids_.push_back(commit_id);
27 projections_[GetGroupForModelType(type, routes_)].push_back( 25 projections_[GetGroupForModelType(type, routes_)].push_back(
28 commit_ids_.size() - 1); 26 inserted_metahandles_.size() - 1);
29 types_.push_back(type); 27 types_.push_back(type);
30 types_in_list_.Put(type); 28 types_in_list_.Put(type);
31 } 29 }
32 } 30 }
33 31
32 void OrderedCommitSet::AddCommitItems(
33 const std::vector<int64> metahandles,
34 ModelType type) {
35 for (std::vector<int64>::const_iterator it = metahandles.begin();
36 it != metahandles.end(); ++it) {
37 AddCommitItem(*it, type);
38 }
39 }
40
34 const OrderedCommitSet::Projection& OrderedCommitSet::GetCommitIdProjection( 41 const OrderedCommitSet::Projection& OrderedCommitSet::GetCommitIdProjection(
35 ModelSafeGroup group) const { 42 ModelSafeGroup group) const {
36 Projections::const_iterator i = projections_.find(group); 43 Projections::const_iterator i = projections_.find(group);
37 DCHECK(i != projections_.end()); 44 DCHECK(i != projections_.end());
38 return i->second; 45 return i->second;
39 } 46 }
40 47
41 void OrderedCommitSet::Append(const OrderedCommitSet& other) { 48 void OrderedCommitSet::Append(const OrderedCommitSet& other) {
42 for (size_t i = 0; i < other.Size(); ++i) { 49 for (size_t i = 0; i < other.Size(); ++i) {
43 CommitItem item = other.GetCommitItemAt(i); 50 CommitItem item = other.GetCommitItemAt(i);
44 AddCommitItem(item.meta, item.id, item.group); 51 AddCommitItem(item.meta, item.group);
45 } 52 }
46 } 53 }
47 54
48 void OrderedCommitSet::AppendReverse(const OrderedCommitSet& other) { 55 void OrderedCommitSet::AppendReverse(const OrderedCommitSet& other) {
49 for (int i = other.Size() - 1; i >= 0; i--) { 56 for (int i = other.Size() - 1; i >= 0; i--) {
50 CommitItem item = other.GetCommitItemAt(i); 57 CommitItem item = other.GetCommitItemAt(i);
51 AddCommitItem(item.meta, item.id, item.group); 58 AddCommitItem(item.meta, item.group);
52 } 59 }
53 } 60 }
54 61
55 void OrderedCommitSet::Truncate(size_t max_size) { 62 void OrderedCommitSet::Truncate(size_t max_size) {
56 if (max_size < metahandle_order_.size()) { 63 if (max_size < metahandle_order_.size()) {
57 for (size_t i = max_size; i < metahandle_order_.size(); ++i) { 64 for (size_t i = max_size; i < metahandle_order_.size(); ++i) {
58 inserted_metahandles_.erase(metahandle_order_[i]); 65 inserted_metahandles_.erase(metahandle_order_[i]);
59 } 66 }
60 67
61 // Some projections may refer to indices that are getting chopped. 68 // Some projections may refer to indices that are getting chopped.
62 // Since projections are in increasing order, it's easy to fix. Except 69 // Since projections are in increasing order, it's easy to fix. Except
63 // that you can't erase(..) using a reverse_iterator, so we use binary 70 // that you can't erase(..) using a reverse_iterator, so we use binary
64 // search to find the chop point. 71 // search to find the chop point.
65 Projections::iterator it = projections_.begin(); 72 Projections::iterator it = projections_.begin();
66 for (; it != projections_.end(); ++it) { 73 for (; it != projections_.end(); ++it) {
67 // For each projection, chop off any indices larger than or equal to 74 // For each projection, chop off any indices larger than or equal to
68 // max_size by looking for max_size using binary search. 75 // max_size by looking for max_size using binary search.
69 Projection& p = it->second; 76 Projection& p = it->second;
70 Projection::iterator element = std::lower_bound(p.begin(), p.end(), 77 Projection::iterator element = std::lower_bound(p.begin(), p.end(),
71 max_size); 78 max_size);
72 if (element != p.end()) 79 if (element != p.end())
73 p.erase(element, p.end()); 80 p.erase(element, p.end());
74 } 81 }
75 commit_ids_.resize(max_size);
76 metahandle_order_.resize(max_size); 82 metahandle_order_.resize(max_size);
77 types_.resize(max_size); 83 types_.resize(max_size);
78 } 84 }
79 } 85 }
80 86
81 void OrderedCommitSet::Clear() { 87 void OrderedCommitSet::Clear() {
82 inserted_metahandles_.clear(); 88 inserted_metahandles_.clear();
83 commit_ids_.clear();
84 metahandle_order_.clear(); 89 metahandle_order_.clear();
85 for (Projections::iterator it = projections_.begin(); 90 for (Projections::iterator it = projections_.begin();
86 it != projections_.end(); ++it) { 91 it != projections_.end(); ++it) {
87 it->second.clear(); 92 it->second.clear();
88 } 93 }
89 types_.clear(); 94 types_.clear();
90 types_in_list_.Clear(); 95 types_in_list_.Clear();
91 } 96 }
92 97
93 OrderedCommitSet::CommitItem OrderedCommitSet::GetCommitItemAt( 98 OrderedCommitSet::CommitItem OrderedCommitSet::GetCommitItemAt(
94 const size_t position) const { 99 const size_t position) const {
95 DCHECK(position < Size()); 100 DCHECK(position < Size());
96 CommitItem return_item = {metahandle_order_[position], 101 CommitItem return_item = {metahandle_order_[position],
97 commit_ids_[position],
98 types_[position]}; 102 types_[position]};
99 return return_item; 103 return return_item;
100 } 104 }
101 105
102 bool OrderedCommitSet::HasBookmarkCommitId() const { 106 bool OrderedCommitSet::HasBookmarkCommitId() const {
103 ModelSafeRoutingInfo::const_iterator group = routes_.find(BOOKMARKS); 107 ModelSafeRoutingInfo::const_iterator group = routes_.find(BOOKMARKS);
104 if (group == routes_.end()) 108 if (group == routes_.end())
105 return false; 109 return false;
106 Projections::const_iterator proj = projections_.find(group->second); 110 Projections::const_iterator proj = projections_.find(group->second);
107 if (proj == projections_.end()) 111 if (proj == projections_.end())
108 return false; 112 return false;
109 DCHECK_LE(proj->second.size(), types_.size()); 113 DCHECK_LE(proj->second.size(), types_.size());
110 for (size_t i = 0; i < proj->second.size(); i++) { 114 for (size_t i = 0; i < proj->second.size(); i++) {
111 if (types_[proj->second[i]] == BOOKMARKS) 115 if (types_[proj->second[i]] == BOOKMARKS)
112 return true; 116 return true;
113 } 117 }
114 return false; 118 return false;
115 } 119 }
116 120
117 void OrderedCommitSet::operator=(const OrderedCommitSet& other) { 121 void OrderedCommitSet::operator=(const OrderedCommitSet& other) {
118 inserted_metahandles_ = other.inserted_metahandles_; 122 inserted_metahandles_ = other.inserted_metahandles_;
119 commit_ids_ = other.commit_ids_;
120 metahandle_order_ = other.metahandle_order_; 123 metahandle_order_ = other.metahandle_order_;
121 projections_ = other.projections_; 124 projections_ = other.projections_;
122 types_ = other.types_; 125 types_ = other.types_;
123 routes_ = other.routes_; 126 routes_ = other.routes_;
124 } 127 }
125 128
126 } // namespace sessions 129 } // namespace sessions
127 } // namespace syncer 130 } // namespace syncer
128 131
OLDNEW
« no previous file with comments | « sync/sessions/ordered_commit_set.h ('k') | sync/sessions/ordered_commit_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698