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

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

Issue 25638003: sync: Implement per-type commit interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Attempt to fix win compile Created 7 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sync/sessions/ordered_commit_set.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10
11 namespace syncer {
12 namespace sessions {
13
14 OrderedCommitSet::OrderedCommitSet() {}
15
16 OrderedCommitSet::~OrderedCommitSet() {}
17
18 void OrderedCommitSet::AddCommitItem(const int64 metahandle,
19 ModelType type) {
20 if (!HaveCommitItem(metahandle)) {
21 inserted_metahandles_.insert(metahandle);
22 metahandle_order_.push_back(metahandle);
23 types_.push_back(type);
24 types_in_list_.Put(type);
25 }
26 }
27
28 void OrderedCommitSet::AddCommitItems(
29 const std::vector<int64> metahandles,
30 ModelType type) {
31 for (std::vector<int64>::const_iterator it = metahandles.begin();
32 it != metahandles.end(); ++it) {
33 AddCommitItem(*it, type);
34 }
35 }
36
37 void OrderedCommitSet::Append(const OrderedCommitSet& other) {
38 for (size_t i = 0; i < other.Size(); ++i) {
39 CommitItem item = other.GetCommitItemAt(i);
40 AddCommitItem(item.meta, item.group);
41 }
42 }
43
44 void OrderedCommitSet::AppendReverse(const OrderedCommitSet& other) {
45 for (int i = other.Size() - 1; i >= 0; i--) {
46 CommitItem item = other.GetCommitItemAt(i);
47 AddCommitItem(item.meta, item.group);
48 }
49 }
50
51 void OrderedCommitSet::Truncate(size_t max_size) {
52 if (max_size < metahandle_order_.size()) {
53 for (size_t i = max_size; i < metahandle_order_.size(); ++i) {
54 inserted_metahandles_.erase(metahandle_order_[i]);
55 }
56
57 metahandle_order_.resize(max_size);
58 types_.resize(max_size);
59 }
60 }
61
62 void OrderedCommitSet::Clear() {
63 inserted_metahandles_.clear();
64 metahandle_order_.clear();
65 types_.clear();
66 types_in_list_.Clear();
67 }
68
69 OrderedCommitSet::CommitItem OrderedCommitSet::GetCommitItemAt(
70 const size_t position) const {
71 DCHECK(position < Size());
72 CommitItem return_item = {metahandle_order_[position],
73 types_[position]};
74 return return_item;
75 }
76
77 bool OrderedCommitSet::HasBookmarkCommitId() const {
78 for (size_t i = 0; i < types_.size(); i++) {
79 if (types_[i] == BOOKMARKS)
80 return true;
81 }
82 return false;
83 }
84
85 void OrderedCommitSet::operator=(const OrderedCommitSet& other) {
86 inserted_metahandles_ = other.inserted_metahandles_;
87 metahandle_order_ = other.metahandle_order_;
88 types_ = other.types_;
89 }
90
91 } // namespace sessions
92 } // namespace syncer
93
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