[Sync] Try to fix race conditions in CookieJarMismatch.
When we navigate to a URL in sync integration tests, sometimes, usually
when this is the first navigation, we see two separate commits. The
first has most of the data correctly set, but lacks a title. Later on
the title is updated through a second commit. This test case has
previously been updated in an attempt to resilient to this quirk, but
it was not enough.
In the flake in attached bug, what appeared to have happened was that
the first navigation created two commits, but only the first one was
needed to satisfy the WaitForURLOnServer check. Then we call
OnGaiaAccountsInCookieUpdated but the affect is asynchronous. Before
the posted task to update cookie information reaches the sync thread,
but after the second histogram checker is created, a second commit from
navigating to kURL1 executes and we get histogram data that we're not
expecting, leading to a failure.
I was not able to repro locally, so it is unclear if both of the
following fixes were actually needed. Regardless, this should make us
significantly more resilient to races and flakiness.
First, changed the way blocking for sessions changes works, to only
consider data that has a title set. When used in a way, this should
force both commits to happen (if there are going to be two), and less
likely the later will leak out.
Second, added a callback to the mechanism that sets cookie information.
This allows us to truly block until the sync thread has been updated.
It is a significant amount of boilerplate for a very simple concept,