| OLD | NEW |
| 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 if (!HaveCommitItem(metahandle)) { | 24 if (!HaveCommitItem(metahandle)) { |
| 25 inserted_metahandles_.insert(metahandle); | 25 inserted_metahandles_.insert(metahandle); |
| 26 metahandle_order_.push_back(metahandle); | 26 metahandle_order_.push_back(metahandle); |
| 27 commit_ids_.push_back(commit_id); | 27 commit_ids_.push_back(commit_id); |
| 28 projections_[GetGroupForModelType(type, routes_)].push_back( | 28 projections_[GetGroupForModelType(type, routes_)].push_back( |
| 29 commit_ids_.size() - 1); | 29 commit_ids_.size() - 1); |
| 30 types_.push_back(type); | 30 types_.push_back(type); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 const OrderedCommitSet::Projection& OrderedCommitSet::GetCommitIdProjection( |
| 35 browser_sync::ModelSafeGroup group) const { |
| 36 Projections::const_iterator i = projections_.find(group); |
| 37 DCHECK(i != projections_.end()); |
| 38 return i->second; |
| 39 } |
| 40 |
| 34 void OrderedCommitSet::Append(const OrderedCommitSet& other) { | 41 void OrderedCommitSet::Append(const OrderedCommitSet& other) { |
| 35 for (int i = 0; i < other.Size(); ++i) { | 42 for (size_t i = 0; i < other.Size(); ++i) { |
| 36 CommitItem item = other.GetCommitItemAt(i); | 43 CommitItem item = other.GetCommitItemAt(i); |
| 37 AddCommitItem(item.meta, item.id, item.group); | 44 AddCommitItem(item.meta, item.id, item.group); |
| 38 } | 45 } |
| 39 } | 46 } |
| 40 | 47 |
| 41 void OrderedCommitSet::AppendReverse(const OrderedCommitSet& other) { | 48 void OrderedCommitSet::AppendReverse(const OrderedCommitSet& other) { |
| 42 for (int i = other.Size() - 1; i >= 0; i--) { | 49 for (int i = other.Size() - 1; i >= 0; 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.id, item.group); |
| 45 } | 52 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 64 max_size); | 71 max_size); |
| 65 if (element != p.end()) | 72 if (element != p.end()) |
| 66 p.erase(element, p.end()); | 73 p.erase(element, p.end()); |
| 67 } | 74 } |
| 68 commit_ids_.resize(max_size); | 75 commit_ids_.resize(max_size); |
| 69 metahandle_order_.resize(max_size); | 76 metahandle_order_.resize(max_size); |
| 70 types_.resize(max_size); | 77 types_.resize(max_size); |
| 71 } | 78 } |
| 72 } | 79 } |
| 73 | 80 |
| 81 void OrderedCommitSet::Clear() { |
| 82 inserted_metahandles_.clear(); |
| 83 commit_ids_.clear(); |
| 84 metahandle_order_.clear(); |
| 85 for (Projections::iterator it = projections_.begin(); |
| 86 it != projections_.end(); ++it) { |
| 87 it->second.clear(); |
| 88 } |
| 89 types_.clear(); |
| 90 } |
| 91 |
| 74 OrderedCommitSet::CommitItem OrderedCommitSet::GetCommitItemAt( | 92 OrderedCommitSet::CommitItem OrderedCommitSet::GetCommitItemAt( |
| 75 const int position) const { | 93 const size_t position) const { |
| 76 DCHECK(position < Size()); | 94 DCHECK(position < Size()); |
| 77 CommitItem return_item = {metahandle_order_[position], | 95 CommitItem return_item = {metahandle_order_[position], |
| 78 commit_ids_[position], | 96 commit_ids_[position], |
| 79 types_[position]}; | 97 types_[position]}; |
| 80 return return_item; | 98 return return_item; |
| 81 } | 99 } |
| 82 | 100 |
| 83 bool OrderedCommitSet::HasBookmarkCommitId() const { | 101 bool OrderedCommitSet::HasBookmarkCommitId() const { |
| 84 ModelSafeRoutingInfo::const_iterator group | 102 ModelSafeRoutingInfo::const_iterator group |
| 85 = routes_.find(syncable::BOOKMARKS); | 103 = routes_.find(syncable::BOOKMARKS); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 101 commit_ids_ = other.commit_ids_; | 119 commit_ids_ = other.commit_ids_; |
| 102 metahandle_order_ = other.metahandle_order_; | 120 metahandle_order_ = other.metahandle_order_; |
| 103 projections_ = other.projections_; | 121 projections_ = other.projections_; |
| 104 types_ = other.types_; | 122 types_ = other.types_; |
| 105 routes_ = other.routes_; | 123 routes_ = other.routes_; |
| 106 } | 124 } |
| 107 | 125 |
| 108 } // namespace sessions | 126 } // namespace sessions |
| 109 } // namespace browser_sync | 127 } // namespace browser_sync |
| 110 | 128 |
| OLD | NEW |