| 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 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 namespace sessions { | 12 namespace sessions { |
| 13 | 13 |
| 14 OrderedCommitSet::OrderedCommitSet( | 14 OrderedCommitSet::OrderedCommitSet(const ModelSafeRoutingInfo& routes) |
| 15 const syncer::ModelSafeRoutingInfo& routes) | |
| 16 : routes_(routes) { | 15 : routes_(routes) { |
| 17 } | 16 } |
| 18 | 17 |
| 19 OrderedCommitSet::~OrderedCommitSet() {} | 18 OrderedCommitSet::~OrderedCommitSet() {} |
| 20 | 19 |
| 21 void OrderedCommitSet::AddCommitItem(const int64 metahandle, | 20 void OrderedCommitSet::AddCommitItem(const int64 metahandle, |
| 22 const syncable::Id& commit_id, | 21 const syncable::Id& commit_id, |
| 23 syncer::ModelType type) { | 22 ModelType type) { |
| 24 if (!HaveCommitItem(metahandle)) { | 23 if (!HaveCommitItem(metahandle)) { |
| 25 inserted_metahandles_.insert(metahandle); | 24 inserted_metahandles_.insert(metahandle); |
| 26 metahandle_order_.push_back(metahandle); | 25 metahandle_order_.push_back(metahandle); |
| 27 commit_ids_.push_back(commit_id); | 26 commit_ids_.push_back(commit_id); |
| 28 projections_[GetGroupForModelType(type, routes_)].push_back( | 27 projections_[GetGroupForModelType(type, routes_)].push_back( |
| 29 commit_ids_.size() - 1); | 28 commit_ids_.size() - 1); |
| 30 types_.push_back(type); | 29 types_.push_back(type); |
| 31 } | 30 } |
| 32 } | 31 } |
| 33 | 32 |
| 34 const OrderedCommitSet::Projection& OrderedCommitSet::GetCommitIdProjection( | 33 const OrderedCommitSet::Projection& OrderedCommitSet::GetCommitIdProjection( |
| 35 syncer::ModelSafeGroup group) const { | 34 ModelSafeGroup group) const { |
| 36 Projections::const_iterator i = projections_.find(group); | 35 Projections::const_iterator i = projections_.find(group); |
| 37 DCHECK(i != projections_.end()); | 36 DCHECK(i != projections_.end()); |
| 38 return i->second; | 37 return i->second; |
| 39 } | 38 } |
| 40 | 39 |
| 41 void OrderedCommitSet::Append(const OrderedCommitSet& other) { | 40 void OrderedCommitSet::Append(const OrderedCommitSet& other) { |
| 42 for (size_t i = 0; i < other.Size(); ++i) { | 41 for (size_t i = 0; i < other.Size(); ++i) { |
| 43 CommitItem item = other.GetCommitItemAt(i); | 42 CommitItem item = other.GetCommitItemAt(i); |
| 44 AddCommitItem(item.meta, item.id, item.group); | 43 AddCommitItem(item.meta, item.id, item.group); |
| 45 } | 44 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 OrderedCommitSet::CommitItem OrderedCommitSet::GetCommitItemAt( | 91 OrderedCommitSet::CommitItem OrderedCommitSet::GetCommitItemAt( |
| 93 const size_t position) const { | 92 const size_t position) const { |
| 94 DCHECK(position < Size()); | 93 DCHECK(position < Size()); |
| 95 CommitItem return_item = {metahandle_order_[position], | 94 CommitItem return_item = {metahandle_order_[position], |
| 96 commit_ids_[position], | 95 commit_ids_[position], |
| 97 types_[position]}; | 96 types_[position]}; |
| 98 return return_item; | 97 return return_item; |
| 99 } | 98 } |
| 100 | 99 |
| 101 bool OrderedCommitSet::HasBookmarkCommitId() const { | 100 bool OrderedCommitSet::HasBookmarkCommitId() const { |
| 102 ModelSafeRoutingInfo::const_iterator group | 101 ModelSafeRoutingInfo::const_iterator group = routes_.find(BOOKMARKS); |
| 103 = routes_.find(syncer::BOOKMARKS); | |
| 104 if (group == routes_.end()) | 102 if (group == routes_.end()) |
| 105 return false; | 103 return false; |
| 106 Projections::const_iterator proj = projections_.find(group->second); | 104 Projections::const_iterator proj = projections_.find(group->second); |
| 107 if (proj == projections_.end()) | 105 if (proj == projections_.end()) |
| 108 return false; | 106 return false; |
| 109 DCHECK_LE(proj->second.size(), types_.size()); | 107 DCHECK_LE(proj->second.size(), types_.size()); |
| 110 for (size_t i = 0; i < proj->second.size(); i++) { | 108 for (size_t i = 0; i < proj->second.size(); i++) { |
| 111 if (types_[proj->second[i]] == syncer::BOOKMARKS) | 109 if (types_[proj->second[i]] == BOOKMARKS) |
| 112 return true; | 110 return true; |
| 113 } | 111 } |
| 114 return false; | 112 return false; |
| 115 } | 113 } |
| 116 | 114 |
| 117 void OrderedCommitSet::operator=(const OrderedCommitSet& other) { | 115 void OrderedCommitSet::operator=(const OrderedCommitSet& other) { |
| 118 inserted_metahandles_ = other.inserted_metahandles_; | 116 inserted_metahandles_ = other.inserted_metahandles_; |
| 119 commit_ids_ = other.commit_ids_; | 117 commit_ids_ = other.commit_ids_; |
| 120 metahandle_order_ = other.metahandle_order_; | 118 metahandle_order_ = other.metahandle_order_; |
| 121 projections_ = other.projections_; | 119 projections_ = other.projections_; |
| 122 types_ = other.types_; | 120 types_ = other.types_; |
| 123 routes_ = other.routes_; | 121 routes_ = other.routes_; |
| 124 } | 122 } |
| 125 | 123 |
| 126 } // namespace sessions | 124 } // namespace sessions |
| 127 } // namespace syncer | 125 } // namespace syncer |
| 128 | 126 |
| OLD | NEW |