Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferencesManager.java

Issue 1505963002: Revert of Remove migrateNetworkPredictionPreferences(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferencesManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferencesManager.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferencesManager.java
index d1f62b1bb832846ae763012fa655b016212aa33d..22a6cdbeb0626739292425a70a745863806fc497 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferencesManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/PrivacyPreferencesManager.java
@@ -15,6 +15,7 @@
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.device.DeviceClassManager;
+import org.chromium.chrome.browser.preferences.NetworkPredictionOptions;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
/**
@@ -24,8 +25,12 @@
static final String PREF_CRASH_DUMP_UPLOAD = "crash_dump_upload";
static final String PREF_CRASH_DUMP_UPLOAD_NO_CELLULAR = "crash_dump_upload_no_cellular";
+ private static final String PREF_NETWORK_PREDICTIONS = "network_predictions";
+ private static final String PREF_BANDWIDTH_OLD = "prefetch_bandwidth";
+ private static final String PREF_BANDWIDTH_NO_CELLULAR_OLD = "prefetch_bandwidth_no_cellular";
private static final String PREF_METRICS_REPORTING = "metrics_reporting";
private static final String PREF_CELLULAR_EXPERIMENT = "cellular_experiment";
+ private static final String ALLOW_PRERENDER_OLD = "allow_prefetch";
private static PrivacyPreferencesManager sInstance;
@@ -63,6 +68,109 @@
mCrashDumpNeverUpload);
}
+ /**
+ * Migrate and delete old preferences. Note that migration has to happen in Android-specific
+ * code because we need to access ALLOW_PRERENDER sharedPreference.
+ * TODO(bnc) https://crbug.com/394845. This change is planned for M38. After a year or so, it
+ * would be worth considering removing this migration code (also removing accessors in
+ * PrefServiceBridge and pref_service_bridge), and reverting to default for users
+ * who had set preferences but have not used Chrome for a year. This change would be subject to
+ * privacy review.
+ */
+ public void migrateNetworkPredictionPreferences() {
+ PrefServiceBridge prefService = PrefServiceBridge.getInstance();
+
+ // See if PREF_NETWORK_PREDICTIONS is an old boolean value.
+ boolean predictionOptionIsBoolean = false;
+ try {
+ mSharedPreferences.getString(PREF_NETWORK_PREDICTIONS, "");
+ } catch (ClassCastException ex) {
+ predictionOptionIsBoolean = true;
+ }
+
+ // Nothing to do if the user or this migration code has already set the new
+ // preference.
+ if (!predictionOptionIsBoolean
+ && prefService.networkPredictionOptionsHasUserSetting()) {
+ return;
+ }
+
+ // Nothing to do if the old preferences are unset.
+ if (!predictionOptionIsBoolean
+ && !mSharedPreferences.contains(PREF_BANDWIDTH_OLD)
+ && !mSharedPreferences.contains(PREF_BANDWIDTH_NO_CELLULAR_OLD)) {
+ return;
+ }
+
+ // Migrate if the old preferences are at their default values.
+ // (Note that for PREF_BANDWIDTH*, if the setting is default, then there is no way to tell
+ // whether the user has set it.)
+ final String prefBandwidthDefault = BandwidthType.PRERENDER_ON_WIFI.title();
+ final String prefBandwidth =
+ mSharedPreferences.getString(PREF_BANDWIDTH_OLD, prefBandwidthDefault);
+ boolean prefBandwidthNoCellularDefault = true;
+ boolean prefBandwidthNoCellular = mSharedPreferences.getBoolean(
+ PREF_BANDWIDTH_NO_CELLULAR_OLD, prefBandwidthNoCellularDefault);
+
+ if (!(prefBandwidthDefault.equals(prefBandwidth))
+ || (prefBandwidthNoCellular != prefBandwidthNoCellularDefault)) {
+ NetworkPredictionOptions newValue = NetworkPredictionOptions.DEFAULT;
+ // Observe PREF_BANDWIDTH on mobile network capable devices.
+ if (isMobileNetworkCapable()) {
+ if (mSharedPreferences.contains(PREF_BANDWIDTH_OLD)) {
+ BandwidthType prefetchBandwidthTypePref = BandwidthType.getBandwidthFromTitle(
+ prefBandwidth);
+ if (BandwidthType.NEVER_PRERENDER.equals(prefetchBandwidthTypePref)) {
+ newValue = NetworkPredictionOptions.NETWORK_PREDICTION_NEVER;
+ } else if (BandwidthType.PRERENDER_ON_WIFI.equals(prefetchBandwidthTypePref)) {
+ newValue = NetworkPredictionOptions.NETWORK_PREDICTION_WIFI_ONLY;
+ } else if (BandwidthType.ALWAYS_PRERENDER.equals(prefetchBandwidthTypePref)) {
+ newValue = NetworkPredictionOptions.NETWORK_PREDICTION_ALWAYS;
+ }
+ }
+ // Observe PREF_BANDWIDTH_NO_CELLULAR on devices without mobile network.
+ } else {
+ if (mSharedPreferences.contains(PREF_BANDWIDTH_NO_CELLULAR_OLD)) {
+ if (prefBandwidthNoCellular) {
+ newValue = NetworkPredictionOptions.NETWORK_PREDICTION_WIFI_ONLY;
+ } else {
+ newValue = NetworkPredictionOptions.NETWORK_PREDICTION_NEVER;
+ }
+ }
+ }
+ // But disable after all if kNetworkPredictionEnabled was disabled by the user.
+ if (prefService.networkPredictionEnabledHasUserSetting()
+ && !prefService.getNetworkPredictionEnabledUserPrefValue()) {
+ newValue = NetworkPredictionOptions.NETWORK_PREDICTION_NEVER;
+ }
+ // Save new value in Chrome PrefService.
+ prefService.setNetworkPredictionOptions(newValue);
+ }
+
+ // Delete old sharedPreferences.
+ SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
+ // Delete PREF_BANDWIDTH and PREF_BANDWIDTH_NO_CELLULAR: just migrated these options.
+ if (mSharedPreferences.contains(PREF_BANDWIDTH_OLD)) {
+ sharedPreferencesEditor.remove(PREF_BANDWIDTH_OLD);
+ }
+ if (mSharedPreferences.contains(PREF_BANDWIDTH_NO_CELLULAR_OLD)) {
+ sharedPreferencesEditor.remove(PREF_BANDWIDTH_NO_CELLULAR_OLD);
+ }
+ // Also delete ALLOW_PRERENDER, which was updated based on PREF_BANDWIDTH[_NO_CELLULAR] and
+ // network connectivity type, therefore does not carry additional information.
+ if (mSharedPreferences.contains(ALLOW_PRERENDER_OLD)) {
+ sharedPreferencesEditor.remove(ALLOW_PRERENDER_OLD);
+ }
+ // Delete bool PREF_NETWORK_PREDICTIONS so that string values can be stored. Note that this
+ // SharedPreference carries no information, because it used to be overwritten by
+ // kNetworkPredictionEnabled on startup, and now it is overwritten by
+ // kNetworkPredictionOptions on startup.
+ if (mSharedPreferences.contains(PREF_NETWORK_PREDICTIONS)) {
+ sharedPreferencesEditor.remove(PREF_NETWORK_PREDICTIONS);
+ }
+ sharedPreferencesEditor.apply();
+ }
+
private NetworkInfo getActiveNetworkInfo() {
ConnectivityManager connectivityManager =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -91,8 +199,9 @@
* @return Whether prerendering should be allowed.
*/
public boolean shouldPrerender() {
- return DeviceClassManager.enablePrerendering()
- && PrefServiceBridge.getInstance().canPredictNetworkActions();
+ if (!DeviceClassManager.enablePrerendering()) return false;
+ migrateNetworkPredictionPreferences();
+ return PrefServiceBridge.getInstance().canPredictNetworkActions();
}
/**

Powered by Google App Engine
This is Rietveld 408576698