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

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

Issue 2367403005: Snackbar for promoting Data Saver to existing users (Closed)
Patch Set: rename "data saving" to "data savings" for consistency Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.preferences.datareduction; 5 package org.chromium.chrome.browser.preferences.datareduction;
6 6
7 import org.chromium.base.ContextUtils; 7 import org.chromium.base.ContextUtils;
8 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; 8 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
9 import org.chromium.chrome.browser.preferences.PrefServiceBridge; 9 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
10 import org.chromium.chrome.browser.preferences.PrefServiceBridge.AboutVersionStr ings; 10 import org.chromium.chrome.browser.preferences.PrefServiceBridge.AboutVersionStr ings;
11 11
12 /** 12 /**
13 * Helper functions for displaying the various data reduction proxy promos. The promo screens 13 * Helper functions for displaying the various data reduction proxy promos. The promo screens
14 * inform users of the benefits of Data Saver. 14 * inform users of the benefits of Data Saver.
15 */ 15 */
16 public class DataReductionPromoUtils { 16 public class DataReductionPromoUtils {
17 /** 17 /**
18 * Keys used to save whether the first run experience or second run promo sc reen has been shown, 18 * Key used to save whether the first run experience or second run promo scr een has been shown.
19 * the time in milliseconds since epoch it was shown, the Chrome version it was shown in, and
20 * whether the user opted out of the data reduction proxy in the FRE promo.
21 */ 19 */
22 private static final String SHARED_PREF_DISPLAYED_FRE_OR_SECOND_RUN_PROMO = 20 private static final String SHARED_PREF_DISPLAYED_FRE_OR_SECOND_RUN_PROMO =
23 "displayed_data_reduction_promo"; 21 "displayed_data_reduction_promo";
22 /**
23 * Key used to save the time in milliseconds since epoch that the first run experience or second
24 * run promo was shown.
25 */
24 private static final String SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_TIME_M S = 26 private static final String SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_TIME_M S =
25 "displayed_data_reduction_promo_time_ms"; 27 "displayed_data_reduction_promo_time_ms";
28 /**
29 * Key used to save the Chrome version the first run experience or second ru n promo was shown
30 * in.
31 */
26 private static final String SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSIO N = 32 private static final String SHARED_PREF_DISPLAYED_FRE_OR_SECOND_PROMO_VERSIO N =
27 "displayed_data_reduction_promo_version"; 33 "displayed_data_reduction_promo_version";
34 /**
35 * Key used to save whether the user opted out of the data reduction proxy i n the FRE promo.
36 */
28 private static final String SHARED_PREF_FRE_PROMO_OPT_OUT = "fre_promo_opt_o ut"; 37 private static final String SHARED_PREF_FRE_PROMO_OPT_OUT = "fre_promo_opt_o ut";
29
30 /** 38 /**
31 * Keys used to save whether the infobar promo is shown and the Chrome versi on it was shown in. 39 * Key used to save whether the infobar promo has been shown.
32 */ 40 */
33 private static final String SHARED_PREF_DISPLAYED_INFOBAR_PROMO = 41 private static final String SHARED_PREF_DISPLAYED_INFOBAR_PROMO =
34 "displayed_data_reduction_infobar_promo"; 42 "displayed_data_reduction_infobar_promo";
43 /**
44 * Key used to save the Chrome version the infobar promo was shown in.
45 */
35 private static final String SHARED_PREF_DISPLAYED_INFOBAR_PROMO_VERSION = 46 private static final String SHARED_PREF_DISPLAYED_INFOBAR_PROMO_VERSION =
36 "displayed_data_reduction_infobar_promo_version"; 47 "displayed_data_reduction_infobar_promo_version";
48 /**
49 * Key used to save the saved bytes when the snackbar promo was last shown. This value is
50 * initialized to the bytes saved for data saver users that had data saver t urned on when this
51 * pref was added. This prevents us from showing promo for savings that have already happened
52 * for existing users.
53 */
54 private static final String SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES =
55 "displayed_data_reduction_snackbar_promo_saved_bytes";
37 56
38 /** 57 /**
39 * Returns whether any of the data reduction proxy promotions can be display ed. Checks if the 58 * Returns whether any of the data reduction proxy promotions can be display ed. Checks if the
40 * proxy is allowed by the DataReductionProxyConfig, already on, or if the u ser is managed. If 59 * proxy is allowed by the DataReductionProxyConfig, already on, or if the u ser is managed. If
41 * the data reduction proxy is managed by an administrator's policy, the use r should not be 60 * the data reduction proxy is managed by an administrator's policy, the use r should not be
42 * given a promotion to enable it. 61 * given a promotion to enable it.
43 * 62 *
44 * @return Whether the any data reduction proxy promotion has been displayed . 63 * @return Whether the any data reduction proxy promotion has been displayed .
45 */ 64 */
46 public static boolean canShowPromos() { 65 public static boolean canShowPromos() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 151
133 /** 152 /**
134 * Returns whether the data reduction proxy infobar promo has been displayed before. 153 * Returns whether the data reduction proxy infobar promo has been displayed before.
135 * 154 *
136 * @return Whether the data reduction proxy infobar promo has been displayed . 155 * @return Whether the data reduction proxy infobar promo has been displayed .
137 */ 156 */
138 public static boolean getDisplayedInfoBarPromo() { 157 public static boolean getDisplayedInfoBarPromo() {
139 return ContextUtils.getAppSharedPreferences().getBoolean( 158 return ContextUtils.getAppSharedPreferences().getBoolean(
140 SHARED_PREF_DISPLAYED_INFOBAR_PROMO, false); 159 SHARED_PREF_DISPLAYED_INFOBAR_PROMO, false);
141 } 160 }
161
162 /** See {@link #SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES}. */
163 public static void saveSnackbarPromoDisplayed(long dataSavingsInBytes) {
164 ContextUtils.getAppSharedPreferences()
165 .edit()
166 .putLong(SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES, dataS avingsInBytes)
167 .apply();
168 }
169
170 /**
171 * Returns the data savings in bytes from when the promo snackbar was last d isplayed.
172 *
173 * @return The data savings in bytes, or -1 if the promo has not been displa yed before.
174 */
175 public static long getDisplayedSnackbarPromoSavedBytes() {
176 return ContextUtils.getAppSharedPreferences().getLong(
177 SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES, -1);
178 }
179
180 /**
181 * Returns a boolean indicating that the data savings in bytes on the first upgrade to the
182 * version that shows the snackbar has been initialized.
183 *
184 * @return Whether that the starting saved bytes have been initialized.
185 */
186 public static boolean hasSnackbarPromoBeenInitWithStartingSavedBytes() {
187 return ContextUtils.getAppSharedPreferences()
188 .contains(SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES);
189 }
142 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698