Avoid spare (already initialized!) RenderProcessHost for tab discarding.

This CL makes sure that the spare RenderProcessHost (which is already
initialized and backed by an actual OS process) is not used in cases
where WebContents shouldn't (yet) be associated with an OS process.
Two most prominent examples of such scenario are: tab discarding
and session restore.

After this CL, the callers of WebContents::Create can specify 3 desired
states of the renderer process associated with the WebContents being
created: kNoRendererProcess, kOkayToHaveRendererProcess and
kEnsureRenderViewInitialization.  The distinction between the last 2
desired states is needed to accomodate WebContentsImpl::CreateNewWindow
which needs to copy session storage state *before* the RenderView gets
initialized.

After this CL, tab discarding and session restore explicitly specify
kNoRendererProcess (this CL also adds a regression test to ensure
that WebContents associated with a discarded tab is not backed by an
actual OS process).  Presence of kNoRendererProcess is recorded in a
SiteInstanceImpl in a generic (i.e. non-spare-RPH-related) field
and also enforced by a DCHECK in SiteInstanceImpl::GetProcess.

Bug: 840409
Change-Id: Id277343e9042195214e06bcf0b9b88412d6d6672
Reviewed-on: https://chromium-review.googlesource.com/1080091
Reviewed-by: Ted Choc <[email protected]>
Reviewed-by: Peter Kasting <[email protected]>
Reviewed-by: François Doray <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Commit-Queue: Łukasz Anforowicz <[email protected]>
Cr-Commit-Position: refs/heads/master@{#564554}
diff --git a/content/browser/site_instance_impl.cc b/content/browser/site_instance_impl.cc
index 8e3ffe29..0f7b70d 100644
--- a/content/browser/site_instance_impl.cc
+++ b/content/browser/site_instance_impl.cc
@@ -36,6 +36,7 @@
       active_frame_count_(0),
       browsing_instance_(browsing_instance),
       process_(nullptr),
+      can_associate_with_spare_process_(true),
       has_site_(false),
       process_reuse_policy_(ProcessReusePolicy::DEFAULT),
       is_for_service_worker_(false) {
@@ -159,6 +160,14 @@
   return process_;
 }
 
+bool SiteInstanceImpl::CanAssociateWithSpareProcess() {
+  return can_associate_with_spare_process_;
+}
+
+void SiteInstanceImpl::PreventAssociationWithSpareProcess() {
+  can_associate_with_spare_process_ = false;
+}
+
 void SiteInstanceImpl::SetSite(const GURL& url) {
   TRACE_EVENT2("navigation", "SiteInstanceImpl::SetSite",
                "site id", id_, "url", url.possibly_invalid_spec());