Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. | |
|
tbansal1
2016/10/26 18:36:23
One last nit: Can you update the comment to say th
megjablon
2016/10/26 18:50:08
Done.
| |
| 50 */ | |
| 51 private static final String SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES = | |
| 52 "displayed_data_reduction_snackbar_promo_saved_bytes"; | |
| 37 | 53 |
| 38 /** | 54 /** |
| 39 * Returns whether any of the data reduction proxy promotions can be display ed. Checks if the | 55 * 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 | 56 * 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 | 57 * the data reduction proxy is managed by an administrator's policy, the use r should not be |
| 42 * given a promotion to enable it. | 58 * given a promotion to enable it. |
| 43 * | 59 * |
| 44 * @return Whether the any data reduction proxy promotion has been displayed . | 60 * @return Whether the any data reduction proxy promotion has been displayed . |
| 45 */ | 61 */ |
| 46 public static boolean canShowPromos() { | 62 public static boolean canShowPromos() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 148 |
| 133 /** | 149 /** |
| 134 * Returns whether the data reduction proxy infobar promo has been displayed before. | 150 * Returns whether the data reduction proxy infobar promo has been displayed before. |
| 135 * | 151 * |
| 136 * @return Whether the data reduction proxy infobar promo has been displayed . | 152 * @return Whether the data reduction proxy infobar promo has been displayed . |
| 137 */ | 153 */ |
| 138 public static boolean getDisplayedInfoBarPromo() { | 154 public static boolean getDisplayedInfoBarPromo() { |
| 139 return ContextUtils.getAppSharedPreferences().getBoolean( | 155 return ContextUtils.getAppSharedPreferences().getBoolean( |
| 140 SHARED_PREF_DISPLAYED_INFOBAR_PROMO, false); | 156 SHARED_PREF_DISPLAYED_INFOBAR_PROMO, false); |
| 141 } | 157 } |
| 158 | |
| 159 /** See {@link #SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES}. */ | |
| 160 public static void saveSnackbarPromoDisplayed(long dataSavingInBytes) { | |
| 161 ContextUtils.getAppSharedPreferences() | |
| 162 .edit() | |
| 163 .putLong(SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES, dataS avingInBytes) | |
| 164 .apply(); | |
| 165 } | |
| 166 | |
| 167 /** | |
| 168 * Returns the data saving in bytes from when the promo snackbar was last di splayed. | |
| 169 * | |
| 170 * @return The data saving in bytes, or -1 if the promo has not been display ed before. | |
| 171 */ | |
| 172 public static long getDisplayedSnackbarPromoSavedBytes() { | |
| 173 return ContextUtils.getAppSharedPreferences().getLong( | |
| 174 SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES, -1); | |
| 175 } | |
| 176 | |
| 177 /** | |
| 178 * Saves a shared pref indicating the data saving in bytes on the first upgr ade to the version | |
| 179 * that shows the snackbar. | |
| 180 */ | |
| 181 public static void saveSnackbarPromoInitWithStartingSavedBytes(long dataSavi ngInBytes) { | |
| 182 ContextUtils.getAppSharedPreferences() | |
| 183 .edit() | |
| 184 .putLong(SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES, dataS avingInBytes) | |
| 185 .apply(); | |
| 186 } | |
| 187 | |
| 188 /** | |
| 189 * Returns a boolean indicating that the data savings in bytes on the first upgrade to the | |
| 190 * version that shows the snackbar has been initialized. | |
| 191 * | |
| 192 * @return Whether that the starting saved bytes have been initialized. | |
| 193 */ | |
| 194 public static boolean hasSnackbarPromoBeenInitWithStartingSavedBytes() { | |
| 195 return ContextUtils.getAppSharedPreferences() | |
| 196 .contains(SHARED_PREF_DISPLAYED_SNACKBAR_PROMO_SAVED_BYTES); | |
| 197 } | |
| 142 } | 198 } |
| OLD | NEW |