Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / prefetch / prefetch.cc
index ccf13e2..c38147f 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "base/metrics/field_trial.h"
 #include "base/strings/string_util.h"
+#include "chrome/browser/net/prediction_options.h"
 #include "chrome/browser/prefetch/prefetch_field_trial.h"
 #include "chrome/browser/profiles/profile_io_data.h"
 #include "net/base/network_change_notifier.h"
@@ -17,16 +18,20 @@ namespace prefetch {
 bool IsPrefetchEnabled(content::ResourceContext* resource_context) {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
 
-  // TODO(jkarlin): Eventually tie this to a new Chrome preference to predict
-  // network actions when on cellular connections.  See crbug.com/370454.
-  if (net::NetworkChangeNotifier::IsConnectionCellular(
-          net::NetworkChangeNotifier::GetConnectionType()))
+  ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
+  DCHECK(io_data);
+
+  // TODO(bnc): Remove this condition once the new
+  // predictive preference is used on all platforms. See crbug.com/334602.
+  if (io_data->network_prediction_options()->GetValue() ==
+          chrome_browser_net::NETWORK_PREDICTION_UNSET &&
+      net::NetworkChangeNotifier::IsConnectionCellular(
+          net::NetworkChangeNotifier::GetConnectionType())) {
     return false;
+  }
 
-  ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
-  if (io_data != NULL && io_data->network_prediction_enabled()->GetValue())
-    return IsPrefetchFieldTrialEnabled();
-  return false;
+  return chrome_browser_net::CanPrefetchAndPrerenderIO(io_data) &&
+         !DisableForFieldTrial();
 }
 
 }  // namespace prefetch