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 ImmutableChangeRecordList ChangeReorderBuffer::GetAllChangesInTreeOrder( | 124 bool ChangeReorderBuffer::GetAllChangesInTreeOrder( |
125 const BaseTransaction* sync_trans) { | 125 const BaseTransaction* sync_trans, |
| 126 ImmutableChangeRecordList* changes) { |
126 syncable::BaseTransaction* trans = sync_trans->GetWrappedTrans(); | 127 syncable::BaseTransaction* trans = sync_trans->GetWrappedTrans(); |
127 | 128 |
128 // Step 1: Iterate through the operations, doing three things: | 129 // Step 1: Iterate through the operations, doing three things: |
129 // (a) Push deleted items straight into the |changelist|. | 130 // (a) Push deleted items straight into the |changelist|. |
130 // (b) Construct a traversal spanning all non-deleted items. | 131 // (b) Construct a traversal spanning all non-deleted items. |
131 // (c) Construct a set of all parent nodes of any position changes. | 132 // (c) Construct a set of all parent nodes of any position changes. |
132 set<int64> parents_of_position_changes; | 133 set<int64> parents_of_position_changes; |
133 Traversal traversal; | 134 Traversal traversal; |
134 | 135 |
135 ChangeRecordList changelist; | 136 ChangeRecordList changelist; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 Traversal::LinkSet::const_iterator j = traversal.begin_children(next); | 194 Traversal::LinkSet::const_iterator j = traversal.begin_children(next); |
194 Traversal::LinkSet::const_iterator end = traversal.end_children(next); | 195 Traversal::LinkSet::const_iterator end = traversal.end_children(next); |
195 for (; j != end; ++j) { | 196 for (; j != end; ++j) { |
196 CHECK(j->first == next); | 197 CHECK(j->first == next); |
197 to_visit.push(j->second); | 198 to_visit.push(j->second); |
198 } | 199 } |
199 } else { | 200 } else { |
200 // There were ordering changes on the children of this parent, so | 201 // There were ordering changes on the children of this parent, so |
201 // enumerate all the children in the sibling order. | 202 // enumerate all the children in the sibling order. |
202 syncable::Entry parent(trans, syncable::GET_BY_HANDLE, next); | 203 syncable::Entry parent(trans, syncable::GET_BY_HANDLE, next); |
203 syncable::Id id = trans->directory()-> | 204 syncable::Id id; |
204 GetFirstChildId(trans, parent.Get(syncable::ID)); | 205 if (!trans->directory()->GetFirstChildId( |
| 206 trans, parent.Get(syncable::ID), &id)) { |
| 207 *changes = ImmutableChangeRecordList(); |
| 208 return false; |
| 209 } |
205 while (!id.IsRoot()) { | 210 while (!id.IsRoot()) { |
206 syncable::Entry child(trans, syncable::GET_BY_ID, id); | 211 syncable::Entry child(trans, syncable::GET_BY_ID, id); |
207 CHECK(child.good()); | 212 CHECK(child.good()); |
208 int64 handle = child.Get(syncable::META_HANDLE); | 213 int64 handle = child.Get(syncable::META_HANDLE); |
209 to_visit.push(handle); | 214 to_visit.push(handle); |
210 // If there is no operation on this child node, record it as as an | 215 // If there is no operation on this child node, record it as as an |
211 // update, so that the listener gets notified of all nodes in the new | 216 // update, so that the listener gets notified of all nodes in the new |
212 // ordering. | 217 // ordering. |
213 if (operations_.find(handle) == operations_.end()) | 218 if (operations_.find(handle) == operations_.end()) |
214 operations_[handle] = OP_UPDATE_POSITION_AND_PROPERTIES; | 219 operations_[handle] = OP_UPDATE_POSITION_AND_PROPERTIES; |
215 id = child.Get(syncable::NEXT_ID); | 220 id = child.Get(syncable::NEXT_ID); |
216 } | 221 } |
217 } | 222 } |
218 } | 223 } |
219 | 224 |
220 return ImmutableChangeRecordList(&changelist); | 225 *changes = ImmutableChangeRecordList(&changelist); |
| 226 return true; |
221 } | 227 } |
222 | 228 |
223 } // namespace sync_api | 229 } // namespace sync_api |
OLD | NEW |