Index: chrome/browser/prerender/prerender_field_trial.cc |
diff --git a/chrome/browser/prerender/prerender_field_trial.cc b/chrome/browser/prerender/prerender_field_trial.cc |
index 4dbac4be74a3efbd6bbffb2ba72993ce1cf76605..92762f65c0d87512130f3069471db7e8944f9f54 100644 |
--- a/chrome/browser/prerender/prerender_field_trial.cc |
+++ b/chrome/browser/prerender/prerender_field_trial.cc |
@@ -11,6 +11,7 @@ |
#include "base/prefs/pref_service.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_split.h" |
+#include "chrome/browser/net/prediction_options.h" |
#include "chrome/browser/predictors/autocomplete_action_predictor.h" |
#include "chrome/browser/prerender/prerender_manager.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -18,6 +19,7 @@ |
#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/chrome_version_info.h" |
+#include "chrome/common/pref_names.h" |
#include "components/metrics/metrics_service.h" |
#include "components/variations/variations_associated_data.h" |
@@ -41,6 +43,9 @@ const char kLocalPredictorSpecTrialName[] = "PrerenderLocalPredictorSpec"; |
const char kLocalPredictorKeyName[] = "LocalPredictor"; |
const char kLocalPredictorUnencryptedSyncOnlyKeyName[] = |
"LocalPredictorUnencryptedSyncOnly"; |
+const char kLocalPredictorNetworkPredictionEnabledOnly[] = |
+ "LocalPredictorNetworkPredictionEnabledOnly"; |
+const char kLocalPredictorOnCellularOnly[] = "LocalPredictorOnCellularOnly"; |
const char kSideEffectFreeWhitelistKeyName[] = "SideEffectFreeWhitelist"; |
const char kPrerenderLaunchKeyName[] = "PrerenderLaunch"; |
const char kPrerenderAlwaysControlKeyName[] = "PrerenderAlwaysControl"; |
@@ -338,6 +343,52 @@ bool DisableLocalPredictorBasedOnSyncAndConfiguration(Profile* profile) { |
!IsUnencryptedSyncEnabled(profile); |
} |
+bool TemporarilyDisableLocalPredictorBasedOnPreferencesAndNetwork( |
+ Profile* profile) { |
+ bool on_cellular = |
+ net::NetworkChangeNotifier::IsConnectionCellular( |
+ net::NetworkChangeNotifier::GetConnectionType()); |
+ // If the user is not on a cellular connection, but we require a cellular |
+ // connection, we must temporarily disable our local predictions. |
+ if (GetLocalPredictorSpecValue(kLocalPredictorOnCellularOnly) == |
+ kEnabledGroup && !on_cellular) { |
jkarlin
2014/09/23 14:54:03
Put !on_cellular first in the conditional since it
tburkard
2014/09/24 15:15:34
Done.
|
+ return true; |
+ } |
+ |
+ // If we don't care whether or not network prediction will actually be |
+ // exercised, we do not need to temporarily disable our predictions. |
+ if (GetLocalPredictorSpecValue(kLocalPredictorNetworkPredictionEnabledOnly) != |
+ kEnabledGroup) { |
+ return false; |
+ } |
+ |
+ // We should temporarily disable iff the predictive network action would |
+ // not be exercised. |
+ |
+ int network_prediction_preference = |
jkarlin
2014/09/23 14:54:03
Can you replace lines 368 and below with:
return
tburkard
2014/09/24 15:15:34
Done.
|
+ profile->GetPrefs()->GetInteger(prefs::kNetworkPredictionOptions); |
+ |
+ // If the user has network predictions never selected, we must disable |
+ // predictions. |
+ if (network_prediction_preference == |
+ chrome_browser_net::NETWORK_PREDICTION_NEVER) { |
+ return true; |
+ } |
+ |
+ // If the user has network predictions enabled on wifi only, but we are |
+ // on cellular, any predictive actions would not be exercised, so we |
+ // must disable predictions. |
+ if (network_prediction_preference == |
+ chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY && on_cellular) { |
+ return true; |
+ } |
+ |
+ // In all other cases, network predictions will be exercised, so it is ok |
+ // to proceed. |
+ |
+ return false; |
+} |
+ |
bool IsLoggedInPredictorEnabled() { |
return IsLocalPredictorEnabled(); |
} |