Reland "Reland "Avoid recycling sync tabs if commit pending""

This is a reland of a61d2bb4304df828da60af07f0b05f33e49fd18f

The flaky test has been excluded from this patch, will be
reintroduced in a separate patch.

Original change's description:
> Reland "Avoid recycling sync tabs if commit pending"
>
> This is a reland of 62414cfcde8b704599847d6acc731d254479655f
>
> Test improved to avoid flakes.
>
> Original change's description:
> > Avoid recycling sync tabs if commit pending
> >
> > When a tab is closed, it's possible that the corresponding history
> > hasn't been committed yet, and hence there is a risk that synced history
> > is lost if the entity is recycled (for another tab that is opened).
> >
> > In this patch, and behind a feature toggle, this issue is prevented by
> > *not* freeing tab nodes while the sync entity is unsynced. Old tabs are
> > excluded from this (to avoid problems with expired history) and a max
> > cap is also introduced to the number of tabs in this state, in order to
> > avoid memory regressions.
> >
> > Bug: 882489
> > Change-Id: I6dd796642f9553f2713a0814731897a4ffb13f0b
> > Reviewed-on: https://chromium-review.googlesource.com/c/1356541
> > Commit-Queue: Mikel Astiz <[email protected]>
> > Reviewed-by: Marc Treib <[email protected]>
> > Cr-Commit-Position: refs/heads/master@{#612971}
>
> [email protected]
>
> Bug: 882489
> Change-Id: Ib3f3ff9e4d620512435d9b22ba7b2c338f92203f
> Reviewed-on: https://chromium-review.googlesource.com/c/1357086
> Reviewed-by: Mikel Astiz <[email protected]>
> Commit-Queue: Mikel Astiz <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#612980}

[email protected]

Bug: 882489
Change-Id: Iaa6490f896257baa8a843ca0e7c92f2d7dc11c8c
Reviewed-on: https://chromium-review.googlesource.com/c/1356808
Reviewed-by: Mikel Astiz <[email protected]>
Commit-Queue: Mikel Astiz <[email protected]>
Cr-Commit-Position: refs/heads/master@{#613028}
diff --git a/components/sync_sessions/local_session_event_handler_impl.h b/components/sync_sessions/local_session_event_handler_impl.h
index 43bdf59..39c6182 100644
--- a/components/sync_sessions/local_session_event_handler_impl.h
+++ b/components/sync_sessions/local_session_event_handler_impl.h
@@ -48,6 +48,7 @@
    public:
     virtual ~Delegate();
     virtual std::unique_ptr<WriteBatch> CreateLocalSessionWriteBatch() = 0;
+    virtual bool IsTabNodeUnsynced(int tab_node_id) = 0;
     // Analogous to SessionsGlobalIdMapper.
     virtual void TrackLocalNavigationId(base::Time timestamp,
                                         int unique_id) = 0;
@@ -79,6 +80,8 @@
  private:
   enum ReloadTabsOption { RELOAD_TABS, DONT_RELOAD_TABS };
 
+  void CleanupLocalTabs(WriteBatch* batch);
+
   void AssociateWindows(ReloadTabsOption option,
                         WriteBatch* batch);