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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java

Issue 2022313002: UI for the Data Saver InfoBar Promo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@infobarPromo
Patch Set: use message layout Created 4 years, 6 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/infobar/DataReductionPromoInfoBar.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java
index 973f7fe08fad62dc704aabe74a11fc17ae8ab08a..1b36020f34f56d21bef3d7b2f554d60414b13611 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/DataReductionPromoInfoBar.java
@@ -7,13 +7,19 @@ package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import org.chromium.base.CommandLine;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.UrlConstants;
+import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils;
+import org.chromium.chrome.browser.preferences.datareduction.DataReductionProxyUma;
import org.chromium.content_public.browser.WebContents;
import org.chromium.net.GURLUtils;
+import org.chromium.ui.widget.Toast;
import java.net.HttpURLConnection;
import java.sql.Date;
@@ -21,12 +27,16 @@ import java.util.Calendar;
import java.util.TimeZone;
/**
- * Generates an InfoBar to promote the data reduction proxy. The InfoBar contains a message and a
- * button to enable the proxy.
+ * Generates an InfoBar to promote the data reduction proxy to non-users of it. The InfoBar contains
+ * a message and a button to enable the proxy. The InfoBar is displayed when it has not been shown
+ * previously, the page is HTTP pages, and certain milestone restrictions are met. Once the proxy is
+ * enabled from the InfoBar a confirmation toast message is shown.
*/
-public class DataReductionPromoInfoBar {
+public class DataReductionPromoInfoBar extends ConfirmInfoBar {
private static final String M48_STABLE_RELEASE_DATE = "2016-01-26";
+ private static final String ENABLE_INFOBAR_SWITCH = "enable-data-reduction-promo-infobar";
+ private static Bitmap sIcon;
private static String sTitle;
private static String sText;
private static String sPrimaryButtonText;
@@ -81,14 +91,16 @@ public class DataReductionPromoInfoBar {
}
// Only show the promo if the current version is at least two milestones after the last
- // promo was displayed. If the last promo was shown before M51 then |freOrSecondRunVersion|
- // will be empty and it is safe to show the InfoBar promo.
- if (!freOrSecondRunVersion.isEmpty() && currentMilestone < getMilestoneFromVersionNumber(
- freOrSecondRunVersion) + 2) {
+ // promo was displayed or the command line switch is on. If the last promo was shown before
+ // M51 then |freOrSecondRunVersion| will be empty and it is safe to show the InfoBar promo.
+ if (!CommandLine.getInstance().hasSwitch(ENABLE_INFOBAR_SWITCH)
+ && !freOrSecondRunVersion.isEmpty()
+ && currentMilestone < getMilestoneFromVersionNumber(freOrSecondRunVersion) + 2) {
return;
}
DataReductionPromoInfoBar.launch(webContents,
+ BitmapFactory.decodeResource(context.getResources(), R.mipmap.app_icon),
context.getString(R.string.data_reduction_promo_infobar_title),
context.getString(R.string.data_reduction_promo_infobar_text),
context.getString(R.string.data_reduction_promo_infobar_button),
@@ -145,11 +157,14 @@ public class DataReductionPromoInfoBar {
* text. Clicking the link will open the specified settings page.
*
* @param webContents The {@link WebContents} in which to open the {@link InfoBar}.
- * @param title The text to display in the {@link InfoBar}.
+ * @param icon Bitmap to use for the InfoBar icon.
+ * @param title The title to display in the {@link InfoBar}.
+ * @param text The text to display in the {@link InfoBar}.
* @param primaryButtonText The text to display on the primary button.
* @param secondaryButtonText The text to display on the secondary button.
*/
private static void launch(WebContents webContents,
+ Bitmap icon,
String title,
String text,
String primaryButtonText,
@@ -158,7 +173,41 @@ public class DataReductionPromoInfoBar {
sText = text;
sPrimaryButtonText = primaryButtonText;
sSecondaryButtonText = secondaryButtonText;
- // TODO(megjablon): Show infobar.
+ sIcon = icon;
+ DataReductionPromoInfoBarDelegate.launch(webContents);
DataReductionPromoUtils.saveInfoBarPromoDisplayed();
}
+
+ DataReductionPromoInfoBar() {
+ super(0, sIcon, sTitle, null, sPrimaryButtonText, sSecondaryButtonText);
+ }
+
+ @Override
+ public void onButtonClicked(boolean isPrimaryButton) {
+ super.onButtonClicked(isPrimaryButton);
gone 2016/06/27 20:44:58 Functionality like this should handled by the Data
megjablon 2016/06/27 22:16:44 Done.
+ if (isPrimaryButton) {
+ DataReductionProxyUma
+ .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_ENABLED);
+ DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
+ getContext(), true);
+ Toast.makeText(getContext(),
+ getContext().getString(R.string.data_reduction_enabled_toast),
+ Toast.LENGTH_LONG).show();
+ }
+ }
+
+ @Override
+ public void onInfoBarClosed() {
+ super.onInfoBarClosed();
+ if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return;
gone 2016/06/27 20:44:58 Ditto for this.
megjablon 2016/06/27 22:16:44 Done.
+ DataReductionProxyUma
+ .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_INFOBAR_DISMISSED);
gone 2016/06/27 20:44:58 "Dismiss" is an explicit closure by the user click
megjablon 2016/06/27 22:16:44 Yep, I saw the InfoBarDismissed, but that doesn't
gone 2016/06/27 23:12:13 You should update the histograms file, then. It c
megjablon 2016/06/29 17:01:51 Ah ya I could see how that's confusing. I meant no
+ }
+
+ @Override
+ public void createContent(InfoBarLayout layout) {
+ super.createContent(layout);
+ InfoBarControlLayout mMessageLayout = layout.getMessageLayout();
gone 2016/06/27 20:44:58 getMessageLayout() exists to add subtitles (like d
megjablon 2016/06/27 22:16:44 Done. Is there a way to increase the line spacing
gone 2016/06/27 23:12:13 Eh, don't increase the spacing on it. Their mocks
megjablon 2016/06/29 17:01:51 SGTM
+ mMessageLayout.addDescription(sText);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698