Address race condition between IPC and font lookup table getting ready

If a renderer asks for the font lookup table asynchronously using
GetUniqueNameLookupTableIfAvailable and recevied the information that
it's not ready yet, then queues a callback for receiving it, but the
font table has become ready in between, callbacks may be missed. Cover
for the situation in QueueShareMemoryRegionWhenReady() by posting
callbacks if the table was already prepared. We cannot DCHECK on
!font_table_built_.IsSignaled() as there is a small time window in which
the table gets ready between the two IPCs reaching the browser process.

Bug: 977283
Tbr: pkasting
Change-Id: I9e7b8d7b9a7afe761a5a0e9d11c894eedc0e452a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1675353
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672056}
diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc
index 488e069..d603265 100644
--- a/chrome/browser/ui/browser_navigator_browsertest.cc
+++ b/chrome/browser/ui/browser_navigator_browsertest.cc
@@ -1435,9 +1435,8 @@
   EXPECT_FALSE(web_contents->IsCrashed());
 }
 
-// Flaky crbug.com/977510
 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
-                       DISABLED_NavigateFromDefaultToOptionsInSameTab) {
+                       NavigateFromDefaultToOptionsInSameTab) {
   {
     content::WindowedNotificationObserver observer(
         content::NOTIFICATION_LOAD_STOP,
diff --git a/content/browser/renderer_host/dwrite_font_lookup_table_builder_win.cc b/content/browser/renderer_host/dwrite_font_lookup_table_builder_win.cc
index 11c8ee1..8bfb6b9 100644
--- a/content/browser/renderer_host/dwrite_font_lookup_table_builder_win.cc
+++ b/content/browser/renderer_host/dwrite_font_lookup_table_builder_win.cc
@@ -335,9 +335,12 @@
   TRACE_EVENT0("dwrite,fonts",
                "DWriteFontLookupTableBuilder::QueueShareMemoryRegionWhenReady");
   DCHECK(!HasDWriteUniqueFontLookups());
-  // TODO(crbug.com/977283): Triggers in tests causing flakiness.
-  // DCHECK(!font_table_built_.IsSignaled());
   pending_callbacks_.emplace_back(std::move(task_runner), std::move(callback));
+  // Cover for the condition in which the font table becomes ready briefly after
+  // a renderer asking for GetUniqueNameLookupTableIfAvailable(), receiving the
+  // information that it wasn't ready.
+  if (font_table_built_.IsSignaled())
+    PostCallbacks();
 }
 
 bool DWriteFontLookupTableBuilder::FontUniqueNameTableReady() {