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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/change_reorder_buffer.cc
diff --git a/sync/internal_api/change_reorder_buffer.cc b/sync/internal_api/change_reorder_buffer.cc
index 572f56dc11fe9aa4770e74ba6e282166a99ad383..c585bd78ed97ccd091bc0c5363404dfe420373fa 100644
--- a/sync/internal_api/change_reorder_buffer.cc
+++ b/sync/internal_api/change_reorder_buffer.cc
@@ -59,8 +59,15 @@ class ChangeReorderBuffer::Traversal {
top_ = node.GetMetahandle();
} else {
// Otherwise, get the parent ID so that we can add a ParentChildLink.
- syncable::Entry parent(trans, syncable::GET_BY_ID,
- node.GetParentId());
+
+ // Treat nodes with unset parent ID as if they were linked to the root.
+ // That is a valid way to traverse the tree because all hierarchical
+ // datatypes must have a valid parent ID and the ones with unset parent
+ // ID have flat hierarchy where the order doesn't matter.
+ const syncable::Id& parent_id = !node.GetParentId().IsNull()
+ ? node.GetParentId()
+ : syncable::Id::GetRoot();
+ syncable::Entry parent(trans, syncable::GET_BY_ID, parent_id);
CHECK(parent.good());
node_parent = parent.GetMetahandle();
« 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