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

Side by Side Diff: sync/internal_api/change_reorder_buffer.cc

Issue 993153002: Sync: ChangeReorderBuffer::Traversal should handle nodes with unset Parent ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | sync/internal_api/sync_manager_impl_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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/internal_api/change_reorder_buffer.h" 5 #include "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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 CHECK(node.good()); 52 CHECK(node.good());
53 if (node.GetId().IsRoot()) { 53 if (node.GetId().IsRoot()) {
54 // If we've hit the root, and the root isn't already in the tree 54 // If we've hit the root, and the root isn't already in the tree
55 // (it would have to be |top_| if it were), start a new expansion 55 // (it would have to be |top_| if it were), start a new expansion
56 // upwards from |top_| to unite the original traversal with the 56 // upwards from |top_| to unite the original traversal with the
57 // path we just added that goes from |child_handle| to the root. 57 // path we just added that goes from |child_handle| to the root.
58 node_to_include = top_; 58 node_to_include = top_;
59 top_ = node.GetMetahandle(); 59 top_ = node.GetMetahandle();
60 } else { 60 } else {
61 // Otherwise, get the parent ID so that we can add a ParentChildLink. 61 // Otherwise, get the parent ID so that we can add a ParentChildLink.
62 syncable::Entry parent(trans, syncable::GET_BY_ID, 62
63 node.GetParentId()); 63 // Treat nodes with unset parent ID as if they were linked to the root.
64 // That is a valid way to traverse the tree because all hierarchical
65 // datatypes must have a valid parent ID and the ones with unset parent
66 // ID have flat hierarchy where the order doesn't matter.
67 const syncable::Id& parent_id = !node.GetParentId().IsNull()
68 ? node.GetParentId()
69 : syncable::Id::GetRoot();
70 syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id);
64 CHECK(parent.good()); 71 CHECK(parent.good());
65 node_parent = parent.GetMetahandle(); 72 node_parent = parent.GetMetahandle();
66 73
67 ParentChildLink link(node_parent, node_to_include); 74 ParentChildLink link(node_parent, node_to_include);
68 75
69 // If the link exists in the LinkSet |links_|, we don't need to search 76 // If the link exists in the LinkSet |links_|, we don't need to search
70 // any higher; we are done. 77 // any higher; we are done.
71 if (links_.find(link) != links_.end()) 78 if (links_.find(link) != links_.end())
72 return; 79 return;
73 80
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 CHECK(j->first == next); 215 CHECK(j->first == next);
209 to_visit.push(j->second); 216 to_visit.push(j->second);
210 } 217 }
211 } 218 }
212 219
213 *changes = ImmutableChangeRecordList(&changelist); 220 *changes = ImmutableChangeRecordList(&changelist);
214 return true; 221 return true;
215 } 222 }
216 223
217 } // namespace syncer 224 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698