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

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: Add space for TalkBack 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 content length when the snackbar promo was last show n.
50 */
51 private static final String SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_CONTENT_LEN GTH =
52 "displayed_data_reduction_snackbar_promo_content_length";
53 /**
54 * Key used to save if the user has initialized the content length for the s nackbar promo on the
55 * first upgrade to the version that shows the snackbar. This is for existin g users. If they're
56 * already past a promo data saving content length when upgrading, they will skip seeing that
57 * promo.
58 */
59 private static final String SHARED_PREF_SNACKBAR_PROMO_INIT_WITH_STARTING_CO NTENT_LENGTH =
60 "data_reduction_snackbar_promo_init_with_starting_content_length";
37 61
38 /** 62 /**
39 * Returns whether any of the data reduction proxy promotions can be display ed. Checks if the 63 * 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 64 * 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 65 * the data reduction proxy is managed by an administrator's policy, the use r should not be
42 * given a promotion to enable it. 66 * given a promotion to enable it.
43 * 67 *
44 * @return Whether the any data reduction proxy promotion has been displayed . 68 * @return Whether the any data reduction proxy promotion has been displayed .
45 */ 69 */
46 public static boolean canShowPromos() { 70 public static boolean canShowPromos() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 156
133 /** 157 /**
134 * Returns whether the data reduction proxy infobar promo has been displayed before. 158 * Returns whether the data reduction proxy infobar promo has been displayed before.
135 * 159 *
136 * @return Whether the data reduction proxy infobar promo has been displayed . 160 * @return Whether the data reduction proxy infobar promo has been displayed .
137 */ 161 */
138 public static boolean getDisplayedInfoBarPromo() { 162 public static boolean getDisplayedInfoBarPromo() {
139 return ContextUtils.getAppSharedPreferences().getBoolean( 163 return ContextUtils.getAppSharedPreferences().getBoolean(
140 SHARED_PREF_DISPLAYED_INFOBAR_PROMO, false); 164 SHARED_PREF_DISPLAYED_INFOBAR_PROMO, false);
141 } 165 }
166
167 /** See {@link #SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_CONTENT_LENGTH}. */
168 public static void saveSnackbarPromoDisplayed(long contentLength) {
169 ContextUtils.getAppSharedPreferences()
170 .edit()
171 .putLong(SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_CONTENT_LENGTH, co ntentLength)
172 .apply();
173 }
174
175 /**
176 * Returns the content length from when the promo snackbar was last displaye d.
177 *
178 * @return The content length, or -1 if the promo has not been displayed bef ore.
179 */
180 public static long getDisplayedSnackbarPromoContentLength() {
181 return ContextUtils.getAppSharedPreferences().getLong(
182 SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_CONTENT_LENGTH, -1);
183 }
184
185 /**
186 * Saves a shared pref indicating the content length on the first upgrade to the version that
187 * shows the snackbar. Also, saves a boolean indicating that the content len gth has been
188 * initialized.
189 */
190 public static void saveSnackbarPromoInitWithStartingContentLength(long conte ntLength) {
tbansal1 2016/10/25 23:15:13 Is the argument content length or saved bytes?
megjablon 2016/10/25 23:49:57 Done.
191 ContextUtils.getAppSharedPreferences()
192 .edit()
193 .putBoolean(SHARED_PREF_SNACKBAR_PROMO_INIT_WITH_STARTING_CONTEN T_LENGTH, true)
194 .putLong(SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_CONTENT_LENGTH, co ntentLength)
195 .apply();
196 }
197
198 /**
199 * Returns a boolean indicating that the content length on the first upgrade or install to the
200 * version that shows the snackbar has been initialized.
201 *
202 * @return Whether that the starting content length has been initialized.
203 */
204 public static boolean hasSnackbarPromoBeenInitWithStartingContentLength() {
205 return ContextUtils.getAppSharedPreferences().getBoolean(
206 SHARED_PREF_SNACKBAR_PROMO_INIT_WITH_STARTING_CONTENT_LENGTH, fa lse);
207 }
142 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698