[Sync] Fix bookmarks initial merge for local entities.

Currently, during the initial merge of bookmarks it may be possible that
processing of local creation may cause crash if the previous neighbour
wasn't processed yet (due to matching by GUID with some remote update).

This patch fixes that behaviour by finding the last tracked entity. That
entity will be used to calculate next UniquePosition.

Bug: 1050776
Change-Id: I5275aee07d5bd5f4e4ac534734c209ec2ed78b85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144160
Commit-Queue: Rushan Suleymanov <[email protected]>
Reviewed-by: Mikel Astiz <[email protected]>
Cr-Commit-Position: refs/heads/master@{#758159}
diff --git a/components/sync_bookmarks/bookmark_model_merger.h b/components/sync_bookmarks/bookmark_model_merger.h
index 9758ee9..500df95 100644
--- a/components/sync_bookmarks/bookmark_model_merger.h
+++ b/components/sync_bookmarks/bookmark_model_merger.h
@@ -11,6 +11,7 @@
 #include <vector>
 
 #include "base/macros.h"
+#include "components/sync/base/unique_position.h"
 #include "components/sync/engine/non_blocking_sync_common.h"
 
 namespace bookmarks {
@@ -181,6 +182,13 @@
       const bookmarks::BookmarkNode* local_parent,
       size_t starting_child_index) const;
 
+  // Used to generate a unique position for the current locally created
+  // bookmark.
+  syncer::UniquePosition GenerateUniquePositionForLocalCreation(
+      const bookmarks::BookmarkNode* parent,
+      size_t index,
+      const std::string& suffix) const;
+
   bookmarks::BookmarkModel* const bookmark_model_;
   favicon::FaviconService* const favicon_service_;
   SyncedBookmarkTracker* const bookmark_tracker_;