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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoUtils.java

Issue 2005623002: Logic for the Data Saver InfoBar Promo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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/datareduction/DataReductionPromoUtils.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..de9fc422a533a458e418a3a8f93e75dbf9079592
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/datareduction/DataReductionPromoUtils.java
@@ -0,0 +1,209 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.preferences.datareduction;
+
+import org.chromium.base.ContextUtils;
+import org.chromium.base.FieldTrialList;
+import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
+import org.chromium.chrome.browser.preferences.PrefServiceBridge;
+import org.chromium.chrome.browser.preferences.PrefServiceBridge.AboutVersionStrings;
+import org.chromium.components.variations.VariationsAssociatedData;
+
+/**
+ * Helper functions for displaying the various Data Reduction Proxy promos. The promo screens
+ * inform users of the benefits of Data Saver.
+ */
+public class DataReductionPromoUtils {
+ /**
+ * Key used to save whether the promo screen is shown and the time in milliseconds since epoch,
+ * it was shown.
+ */
+ private static final String SHARED_PREF_DISPLAYED_PROMO = "displayed_data_reduction_fre_promo";
+ private static final String SHARED_PREF_DISPLAYED_INFOBAR_PROMO =
+ "displayed_data_reduction_infobar_promo";
+ private static final String SHARED_PREF_DISPLAYED_PROMO_TIME_MS =
+ "displayed_data_reduction_promo_time_ms";
+ private static final String SHARED_PREF_DISPLAYED_PROMO_VERSION =
+ "displayed_data_reduction_promo_version";
+ private static final String SHARED_PREF_DISPLAYED_INFOBAR_PROMO_VERSION =
+ "displayed_data_reduction_infobar_promo_version";
+ private static final String SHARED_PREF_FRE_PROMO_OPT_OUT = "fre_promo_opt_out";
+ private static final String SHARED_PREF_INFOBAR_PROMO_OPT_OUT =
+ "data_reduction_infobar_promo_opt_out";
+ private static final String SHARED_PREF_INFOBAR_PROMO_OPT_OUT_EPOCH =
+ "data_reduction_infobar_promo_opt_out_epoch";
+
+ private static final String FIELD_TRIAL_INFOBAR_PROMO = "DataReductionProxyInfoBarPromo";
+ private static final String FIELD_TRIAL_INFOBAR_PROMO_OPT_OUT_EPOCH = "opt_out_epoch";
+
+ /**
+ * Returns whether any of the Data Reduction Proxies can be displayed. Checks if the proxy is
+ * allowed by the config, already on, or if the user is managed.
+ *
+ * @return Whether the any Data Reduction Proxy promo has been displayed.
+ */
+ public static boolean canShowDataReductionPromos() {
+ if (!DataReductionProxySettings.getInstance().isDataReductionProxyPromoAllowed()) {
+ return false;
+ }
+ if (DataReductionProxySettings.getInstance().isDataReductionProxyManaged()) return false;
+ if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return false;
+ return true;
+ }
+
+ /**
+ * Returns whether the Data Reduction Proxy InfoBar promo Field Trial is enabled.
+ *
+ * @return Whether he Data Reduction Proxy InfoBar promo Field Trial is enabled.
+ */
+ public static boolean getDataReductionInfoBarPromoFieldTrialEnabled() {
+ return FieldTrialList.findFullName(FIELD_TRIAL_INFOBAR_PROMO).startsWith("Enabled");
+ }
+
+ /**
+ * Saves shared prefs indicating that the Data Reduction Proxy promo screen has been displayed
+ * at the current time.
+ */
+ public static void saveDataReductionPromoDisplayed() {
+ AboutVersionStrings versionStrings = PrefServiceBridge.getInstance()
+ .getAboutVersionStrings();
+ ContextUtils.getAppSharedPreferences()
+ .edit()
+ .putBoolean(SHARED_PREF_DISPLAYED_PROMO, true)
+ .putLong(SHARED_PREF_DISPLAYED_PROMO_TIME_MS, System.currentTimeMillis())
+ .putString(SHARED_PREF_DISPLAYED_PROMO_VERSION,
+ versionStrings.getApplicationVersion())
+ .apply();
+ }
+
+ /**
+ * Returns whether the Data Reduction Proxy promo has been displayed before.
+ *
+ * @return Whether the Data Reduction Proxy promo has been displayed.
+ */
+ public static boolean getDisplayedDataReductionPromo() {
+ return ContextUtils.getAppSharedPreferences().getBoolean(
+ SHARED_PREF_DISPLAYED_PROMO, false);
+ }
+
+ /**
+ * Returns the version the Data Reduction Proxy promo was displayed on. If the promo has not
+ * been displayed, returns an empty string.
+ *
+ * @return The version the Data Reduction Proxy promo was displayed on.
+ */
+ public static String getDisplayedDataReductionPromoVersion() {
+ return ContextUtils.getAppSharedPreferences()
+ .getString(SHARED_PREF_DISPLAYED_PROMO_VERSION, "");
+ }
+
+ /**
+ * Saves shared prefs indicating that the Data Reduction Proxy First Run Experience promo screen
+ * was displayed and the user opted out.
+ *
+ * @param optOut Whether the user opted out of using the Data Reduction Proxy.
+ */
+ public static void saveDataReductionFrePromoOptOut(boolean optOut) {
+ ContextUtils.getAppSharedPreferences()
+ .edit()
+ .putBoolean(SHARED_PREF_FRE_PROMO_OPT_OUT, optOut)
+ .apply();
+ }
+
+ /**
+ * Returns whether the user saw the Data Reduction Proxy FRE promo and opted out.
+ *
+ * @return Whether the user opted out of the Data Reduction Proxy FRE promo.
+ */
+ public static boolean getDataReductionFrePromoOptOut() {
+ return ContextUtils.getAppSharedPreferences().getBoolean(
+ SHARED_PREF_FRE_PROMO_OPT_OUT, false);
+ }
+
+ /**
+ * Saves shared prefs indicating that the Data Reduction Proxy InfoBar promo has been displayed
+ * at the current time.
+ */
+ public static void saveDataReductionInfoBarPromoDisplayed() {
+ AboutVersionStrings versionStrings = PrefServiceBridge.getInstance()
+ .getAboutVersionStrings();
+ ContextUtils.getAppSharedPreferences()
+ .edit()
+ .putBoolean(SHARED_PREF_DISPLAYED_INFOBAR_PROMO, true)
+ .putString(SHARED_PREF_DISPLAYED_INFOBAR_PROMO_VERSION,
+ versionStrings.getApplicationVersion())
+ .apply();
+ }
+
+ /**
+ * Saves shared prefs indicating that the Data Reduction Proxy InfoBar promo was displayed and
+ * the user opted out.
+ *
+ * @param optOut Whether the user opted out of using the Data Reduction Proxy.
+ */
+ public static void saveDataReductionInfoBarPromoOptOut(boolean optOut) {
+ ContextUtils.getAppSharedPreferences()
+ .edit()
+ .putBoolean(SHARED_PREF_INFOBAR_PROMO_OPT_OUT, optOut)
+ .apply();
+ }
+
+ /**
+ * Returns whether the Data Reduction Proxy InfoBar promo has been displayed before.
+ *
+ * @return Whether the Data Reduction Proxy InfoBar promo has been displayed.
+ */
+ public static boolean getDisplayedDataReductionInfoBarPromo() {
+ return ContextUtils.getAppSharedPreferences().getBoolean(
+ SHARED_PREF_DISPLAYED_INFOBAR_PROMO, false);
+ }
+
+ /**
+ * Returns the version the Data Reduction Proxy InfoBar promo was displayed on. If the promo has
+ * not been displayed, returns an empty string.
+ *
+ * @return The version the Data Reduction Proxy InfoBar promo was displayed on.
+ */
+ public static String getDisplayedDataReductionInfoBarPromoVersion() {
+ return ContextUtils.getAppSharedPreferences()
+ .getString(SHARED_PREF_DISPLAYED_INFOBAR_PROMO_VERSION, "");
+ }
+
+ /**
+ * Returns whether the user saw the Data Reduction Proxy InfoBar promo and opted out.
+ *
+ * @return Whether the user opted out of the Data Reduction Proxy InfoBar promo.
+ */
+ public static boolean getDataReductionInfoBarPromoOptOut() {
+ return ContextUtils.getAppSharedPreferences().getBoolean(
+ SHARED_PREF_INFOBAR_PROMO_OPT_OUT, false);
+ }
+
+ /**
+ * Any time the InfoBar promo opt out epoch value is incremented via Finch, reset the opt out
+ * state so that the InfoBar will be shown again.
+ */
+ public static void maybeResetDataReductionInfoBarPromoOptOut() {
+ int currentEpoch = ContextUtils.getAppSharedPreferences()
+ .getInt(SHARED_PREF_INFOBAR_PROMO_OPT_OUT_EPOCH, 0);
+ int newEpoch;
+
+ String varationsValueString = VariationsAssociatedData.getVariationParamValue(
+ FIELD_TRIAL_INFOBAR_PROMO, FIELD_TRIAL_INFOBAR_PROMO_OPT_OUT_EPOCH);
+ try {
+ newEpoch = Integer.parseInt(varationsValueString);
+ } catch (NumberFormatException e) {
+ newEpoch = 0;
+ }
+
+ if (newEpoch > currentEpoch) {
+ saveDataReductionInfoBarPromoOptOut(false);
+ ContextUtils.getAppSharedPreferences()
+ .edit()
+ .putInt(SHARED_PREF_INFOBAR_PROMO_OPT_OUT_EPOCH, newEpoch)
+ .apply();
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698