Implements prerendering FINAL_STATUS_{CELLULAR_NETWORK,PRERENDERONG_DISABLED}

Before, prerender manager was silently ignoring when a adding a
prerender if prerendering was disabled or the mobile on cellular
network. This adds the two new prerender final status so these
cases get also counted on Prerender.*FinalStatus UMA histograms.

BUG=565897

Review URL: https://codereview.chromium.org/1496263003

Cr-Commit-Position: refs/heads/master@{#368046}
diff --git a/chrome/browser/net/prediction_options.cc b/chrome/browser/net/prediction_options.cc
index 40abb5ab..4533c93 100644
--- a/chrome/browser/net/prediction_options.cc
+++ b/chrome/browser/net/prediction_options.cc
@@ -18,17 +18,21 @@
 
 // Since looking up preferences and current network connection are presumably
 // both cheap, we do not cache them here.
-bool CanPrefetchAndPrerender(int network_prediction_options) {
+NetworkPredictionStatus CanPrefetchAndPrerender(
+    int network_prediction_options) {
   switch (network_prediction_options) {
     case NETWORK_PREDICTION_ALWAYS:
-      return true;
+      break;
     case NETWORK_PREDICTION_NEVER:
-      return false;
+      return NetworkPredictionStatus::DISABLED_ALWAYS;
     default:
       DCHECK_EQ(NETWORK_PREDICTION_WIFI_ONLY, network_prediction_options);
-      return !net::NetworkChangeNotifier::IsConnectionCellular(
-                 net::NetworkChangeNotifier::GetConnectionType());
+      if (net::NetworkChangeNotifier::IsConnectionCellular(
+                 net::NetworkChangeNotifier::GetConnectionType())) {
+        return NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK;
+      }
   }
+  return NetworkPredictionStatus::ENABLED;
 }
 
 bool CanPreresolveAndPreconnect(int network_prediction_options) {
@@ -47,14 +51,15 @@
       user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
 }
 
-bool CanPrefetchAndPrerenderIO(ProfileIOData* profile_io_data) {
+NetworkPredictionStatus CanPrefetchAndPrerenderIO(
+    ProfileIOData* profile_io_data) {
   DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
   DCHECK(profile_io_data);
   return CanPrefetchAndPrerender(
       profile_io_data->network_prediction_options()->GetValue());
 }
 
-bool CanPrefetchAndPrerenderUI(PrefService* prefs) {
+NetworkPredictionStatus CanPrefetchAndPrerenderUI(PrefService* prefs) {
   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
   DCHECK(prefs);
   return CanPrefetchAndPrerender(
diff --git a/chrome/browser/net/prediction_options.h b/chrome/browser/net/prediction_options.h
index 6a2f8df..9029157d 100644
--- a/chrome/browser/net/prediction_options.h
+++ b/chrome/browser/net/prediction_options.h
@@ -24,6 +24,12 @@
   NETWORK_PREDICTION_DEFAULT = NETWORK_PREDICTION_WIFI_ONLY,
 };
 
+enum class NetworkPredictionStatus {
+  ENABLED,
+  DISABLED_ALWAYS,
+  DISABLED_DUE_TO_NETWORK,
+};
+
 void RegisterPredictionOptionsProfilePrefs(
     user_prefs::PrefRegistrySyncable* registry);
 
@@ -31,10 +37,11 @@
 // and prerendering are enabled, based on preferences and network type.
 
 // To be executed on the IO thread only.
-bool CanPrefetchAndPrerenderIO(ProfileIOData* profile_io_data);
+NetworkPredictionStatus CanPrefetchAndPrerenderIO(
+    ProfileIOData* profile_io_data);
 
 // To be executed on the UI thread only.
-bool CanPrefetchAndPrerenderUI(PrefService* prefs);
+NetworkPredictionStatus CanPrefetchAndPrerenderUI(PrefService* prefs);
 
 // The following two global functions determine whether TCP preconnect
 // and DNS preresolution are enabled, based on preferences.
diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc
index ee5278c..f2d91b90 100644
--- a/chrome/browser/net/predictor.cc
+++ b/chrome/browser/net/predictor.cc
@@ -899,12 +899,14 @@
 }
 
 bool Predictor::CanPrefetchAndPrerender() const {
+  chrome_browser_net::NetworkPredictionStatus status;
   if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
-    return chrome_browser_net::CanPrefetchAndPrerenderUI(user_prefs_);
+    status = chrome_browser_net::CanPrefetchAndPrerenderUI(user_prefs_);
   } else {
     DCHECK_CURRENTLY_ON(BrowserThread::IO);
-    return chrome_browser_net::CanPrefetchAndPrerenderIO(profile_io_data_);
+    status = chrome_browser_net::CanPrefetchAndPrerenderIO(profile_io_data_);
   }
+  return status == chrome_browser_net::NetworkPredictionStatus::ENABLED;
 }
 
 bool Predictor::CanPreresolveAndPreconnect() const {