| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/internal_api/change_reorder_buffer.h" | 5 #include "chrome/browser/sync/internal_api/change_reorder_buffer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> // for pair<> | 10 #include <utility> // for pair<> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(Traversal); | 115 DISALLOW_COPY_AND_ASSIGN(Traversal); |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 ChangeReorderBuffer::ChangeReorderBuffer() { | 118 ChangeReorderBuffer::ChangeReorderBuffer() { |
| 119 } | 119 } |
| 120 | 120 |
| 121 ChangeReorderBuffer::~ChangeReorderBuffer() { | 121 ChangeReorderBuffer::~ChangeReorderBuffer() { |
| 122 } | 122 } |
| 123 | 123 |
| 124 void ChangeReorderBuffer::GetAllChangesInTreeOrder( | 124 ImmutableChangeRecordList ChangeReorderBuffer::GetAllChangesInTreeOrder( |
| 125 const BaseTransaction* sync_trans, | 125 const BaseTransaction* sync_trans) { |
| 126 vector<ChangeRecord>* changelist) { | |
| 127 syncable::BaseTransaction* trans = sync_trans->GetWrappedTrans(); | 126 syncable::BaseTransaction* trans = sync_trans->GetWrappedTrans(); |
| 128 | 127 |
| 129 // Step 1: Iterate through the operations, doing three things: | 128 // Step 1: Iterate through the operations, doing three things: |
| 130 // (a) Push deleted items straight into the |changelist|. | 129 // (a) Push deleted items straight into the |changelist|. |
| 131 // (b) Construct a traversal spanning all non-deleted items. | 130 // (b) Construct a traversal spanning all non-deleted items. |
| 132 // (c) Construct a set of all parent nodes of any position changes. | 131 // (c) Construct a set of all parent nodes of any position changes. |
| 133 set<int64> parents_of_position_changes; | 132 set<int64> parents_of_position_changes; |
| 134 Traversal traversal; | 133 Traversal traversal; |
| 135 | 134 |
| 135 ChangeRecordList changelist; |
| 136 |
| 136 OperationMap::const_iterator i; | 137 OperationMap::const_iterator i; |
| 137 for (i = operations_.begin(); i != operations_.end(); ++i) { | 138 for (i = operations_.begin(); i != operations_.end(); ++i) { |
| 138 if (i->second == OP_DELETE) { | 139 if (i->second == OP_DELETE) { |
| 139 ChangeRecord record; | 140 ChangeRecord record; |
| 140 record.id = i->first; | 141 record.id = i->first; |
| 141 record.action = ChangeRecord::ACTION_DELETE; | 142 record.action = ChangeRecord::ACTION_DELETE; |
| 142 if (specifics_.find(record.id) != specifics_.end()) | 143 if (specifics_.find(record.id) != specifics_.end()) |
| 143 record.specifics = specifics_[record.id]; | 144 record.specifics = specifics_[record.id]; |
| 144 if (extra_data_.find(record.id) != extra_data_.end()) | 145 if (extra_data_.find(record.id) != extra_data_.end()) |
| 145 record.extra = extra_data_[record.id]; | 146 record.extra = extra_data_[record.id]; |
| 146 changelist->push_back(record); | 147 changelist.push_back(record); |
| 147 } else { | 148 } else { |
| 148 traversal.ExpandToInclude(trans, i->first); | 149 traversal.ExpandToInclude(trans, i->first); |
| 149 if (i->second == OP_ADD || | 150 if (i->second == OP_ADD || |
| 150 i->second == OP_UPDATE_POSITION_AND_PROPERTIES) { | 151 i->second == OP_UPDATE_POSITION_AND_PROPERTIES) { |
| 151 ReadNode node(sync_trans); | 152 ReadNode node(sync_trans); |
| 152 CHECK(node.InitByIdLookup(i->first)); | 153 CHECK(node.InitByIdLookup(i->first)); |
| 153 | 154 |
| 154 // We only care about parents of entry's with position-sensitive models. | 155 // We only care about parents of entry's with position-sensitive models. |
| 155 if (syncable::ShouldMaintainPosition( | 156 if (syncable::ShouldMaintainPosition( |
| 156 node.GetEntry()->GetModelType())) { | 157 node.GetEntry()->GetModelType())) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 174 ChangeRecord record; | 175 ChangeRecord record; |
| 175 record.id = next; | 176 record.id = next; |
| 176 if (i->second == OP_ADD) | 177 if (i->second == OP_ADD) |
| 177 record.action = ChangeRecord::ACTION_ADD; | 178 record.action = ChangeRecord::ACTION_ADD; |
| 178 else | 179 else |
| 179 record.action = ChangeRecord::ACTION_UPDATE; | 180 record.action = ChangeRecord::ACTION_UPDATE; |
| 180 if (specifics_.find(record.id) != specifics_.end()) | 181 if (specifics_.find(record.id) != specifics_.end()) |
| 181 record.specifics = specifics_[record.id]; | 182 record.specifics = specifics_[record.id]; |
| 182 if (extra_data_.find(record.id) != extra_data_.end()) | 183 if (extra_data_.find(record.id) != extra_data_.end()) |
| 183 record.extra = extra_data_[record.id]; | 184 record.extra = extra_data_[record.id]; |
| 184 changelist->push_back(record); | 185 changelist.push_back(record); |
| 185 } | 186 } |
| 186 | 187 |
| 187 // Now add the children of |next| to |to_visit|. | 188 // Now add the children of |next| to |to_visit|. |
| 188 if (parents_of_position_changes.find(next) == | 189 if (parents_of_position_changes.find(next) == |
| 189 parents_of_position_changes.end()) { | 190 parents_of_position_changes.end()) { |
| 190 // No order changes on this parent -- traverse only the nodes listed | 191 // No order changes on this parent -- traverse only the nodes listed |
| 191 // in the traversal (and not in sibling order). | 192 // in the traversal (and not in sibling order). |
| 192 Traversal::LinkSet::const_iterator j = traversal.begin_children(next); | 193 Traversal::LinkSet::const_iterator j = traversal.begin_children(next); |
| 193 Traversal::LinkSet::const_iterator end = traversal.end_children(next); | 194 Traversal::LinkSet::const_iterator end = traversal.end_children(next); |
| 194 for (; j != end; ++j) { | 195 for (; j != end; ++j) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 208 to_visit.push(handle); | 209 to_visit.push(handle); |
| 209 // If there is no operation on this child node, record it as as an | 210 // If there is no operation on this child node, record it as as an |
| 210 // update, so that the listener gets notified of all nodes in the new | 211 // update, so that the listener gets notified of all nodes in the new |
| 211 // ordering. | 212 // ordering. |
| 212 if (operations_.find(handle) == operations_.end()) | 213 if (operations_.find(handle) == operations_.end()) |
| 213 operations_[handle] = OP_UPDATE_POSITION_AND_PROPERTIES; | 214 operations_[handle] = OP_UPDATE_POSITION_AND_PROPERTIES; |
| 214 id = child.Get(syncable::NEXT_ID); | 215 id = child.Get(syncable::NEXT_ID); |
| 215 } | 216 } |
| 216 } | 217 } |
| 217 } | 218 } |
| 219 |
| 220 return ImmutableChangeRecordList(&changelist); |
| 218 } | 221 } |
| 219 | 222 |
| 220 } // namespace sync_api | 223 } // namespace sync_api |
| OLD | NEW |