[bfcache] Restore pages from the cache immediately before committing.

With this CL, we now call BackForwardCache::RestoreDocument at the end
of the navigation just before committing, instead of at the start of
the navigation.

This shrinks the window of time where an eviction can occur after
the document has been removed from the cache, but before it
has been committed.

Before this patch, if an eviction arrived after the navigation started,
the behavior was undefined. With this patch, that case is now handled by
canceling the navigation. In a follow-up CL, it will be handled by
restarting the same session history navigation.

This CL also has the (pleasant) side effect of fixing an issue where
throttling wasn't handled correctly in the case of a BackForwardCache
restore, (test added in this CL).

Change-Id: I65a1600cef04f2e10f0d28a5df750b26c85e917a
Bug: 976697,995316
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760220
Reviewed-by: Nasko Oskov <[email protected]>
Reviewed-by: Arthur Sonzogni <[email protected]>
Commit-Queue: Lowell Manners <[email protected]>
Cr-Commit-Position: refs/heads/master@{#689507}
diff --git a/content/browser/frame_host/navigation_controller_impl.cc b/content/browser/frame_host/navigation_controller_impl.cc
index 4bc8bd4..d151840 100644
--- a/content/browser/frame_host/navigation_controller_impl.cc
+++ b/content/browser/frame_host/navigation_controller_impl.cc
@@ -2511,7 +2511,7 @@
 
   // BackForwardCache:
   // Navigate immediately if the document is in the BackForwardCache.
-  if (back_forward_cache_.ContainsDocument(nav_entry_id)) {
+  if (back_forward_cache_.GetDocument(nav_entry_id)) {
     DCHECK_EQ(reload_type, ReloadType::NONE);
     auto navigation_request = CreateNavigationRequestFromEntry(
         root, pending_entry_, pending_entry_->GetFrameEntry(root),