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.infobar; | 5 package org.chromium.chrome.browser.infobar; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.pm.PackageInfo; | 8 import android.content.pm.PackageInfo; |
9 import android.content.pm.PackageManager.NameNotFoundException; | 9 import android.content.pm.PackageManager.NameNotFoundException; |
10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
11 import android.graphics.BitmapFactory; | 11 import android.graphics.BitmapFactory; |
12 import android.os.StrictMode; | |
12 | 13 |
13 import org.chromium.base.CommandLine; | 14 import org.chromium.base.CommandLine; |
14 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
15 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
16 import org.chromium.chrome.browser.UrlConstants; | 17 import org.chromium.chrome.browser.UrlConstants; |
17 import org.chromium.chrome.browser.omaha.VersionNumberGetter; | 18 import org.chromium.chrome.browser.omaha.VersionNumberGetter; |
18 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 19 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
19 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoU tils; | 20 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoU tils; |
20 import org.chromium.content_public.browser.WebContents; | 21 import org.chromium.content_public.browser.WebContents; |
21 import org.chromium.net.GURLUtils; | 22 import org.chromium.net.GURLUtils; |
(...skipping 12 matching lines...) Expand all Loading... | |
34 public class DataReductionPromoInfoBar extends ConfirmInfoBar { | 35 public class DataReductionPromoInfoBar extends ConfirmInfoBar { |
35 private static final String M48_STABLE_RELEASE_DATE = "2016-01-26"; | 36 private static final String M48_STABLE_RELEASE_DATE = "2016-01-26"; |
36 private static final String ENABLE_INFOBAR_SWITCH = "enable-data-reduction-p romo-infobar"; | 37 private static final String ENABLE_INFOBAR_SWITCH = "enable-data-reduction-p romo-infobar"; |
37 private static final int NO_INSTALL_TIME = 0; | 38 private static final int NO_INSTALL_TIME = 0; |
38 | 39 |
39 private static Bitmap sIcon; | 40 private static Bitmap sIcon; |
40 private static String sTitle; | 41 private static String sTitle; |
41 private static String sText; | 42 private static String sText; |
42 private static String sPrimaryButtonText; | 43 private static String sPrimaryButtonText; |
43 private static String sSecondaryButtonText; | 44 private static String sSecondaryButtonText; |
45 | |
44 /** | 46 /** |
45 * Launch the data reduction infobar promo, if it needs to be displayed. | 47 * Launch the data reduction infobar promo, if it needs to be displayed. |
46 * | 48 * |
47 * @param context An Android context. | 49 * @param context An Android context. |
48 * @param webContents The WebContents of the tab on which the infobar should show. | 50 * @param webContents The WebContents of the tab on which the infobar should show. |
49 * @param url The URL of the page on which the infobar should show. | 51 * @param url The URL of the page on which the infobar should show. |
50 * @param isFragmentNavigation Whether the main frame navigation did not cau se changes to the | 52 * @param isFragmentNavigation Whether the main frame navigation did not cau se changes to the |
51 * document (for example scrolling to a named anchor PopState). | 53 * document (for example scrolling to a named anchor PopState). |
52 * @param statusCode The HTTP status code of the navigation. | 54 * @param statusCode The HTTP status code of the navigation. |
53 * @return boolean Whether the promo was launched. | 55 * @return boolean Whether the promo was launched. |
(...skipping 19 matching lines...) Expand all Loading... | |
73 if (DataReductionPromoUtils.getDisplayedInfoBarPromo()) return false; | 75 if (DataReductionPromoUtils.getDisplayedInfoBarPromo()) return false; |
74 | 76 |
75 // Only show the promo on HTTP pages. | 77 // Only show the promo on HTTP pages. |
76 if (!GURLUtils.getScheme(url).concat("://").equals(UrlConstants.HTTP_SCH EME)) return false; | 78 if (!GURLUtils.getScheme(url).concat("://").equals(UrlConstants.HTTP_SCH EME)) return false; |
77 | 79 |
78 int currentMilestone = VersionNumberGetter.getMilestoneFromVersionNumber ( | 80 int currentMilestone = VersionNumberGetter.getMilestoneFromVersionNumber ( |
79 PrefServiceBridge.getInstance().getAboutVersionStrings().getAppl icationVersion()); | 81 PrefServiceBridge.getInstance().getAboutVersionStrings().getAppl icationVersion()); |
80 String freOrSecondRunVersion = | 82 String freOrSecondRunVersion = |
81 DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion() ; | 83 DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion() ; |
82 | 84 |
83 Calendar releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZ one("UTC")); | 85 Calendar releaseDateOfM48Stable = null; |
84 releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE)); | |
85 long packageInstallTime = getPackageInstallTime(context); | |
86 | 86 |
87 // The boolean pref that stores whether user opted out on the first run experience was | 87 // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577 185 |
88 // added in M51. If the last promo was shown before M51, then |freOrSeco ndRunVersion| will | 88 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
89 // be empty. If Chrome was installed after the FRE promo was added in M4 8 and before M51, | 89 try { |
90 // assume the user opted out from the FRE and don't show the infobar. | 90 releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZone(" UTC")); |
91 if (freOrSecondRunVersion.isEmpty() | 91 |
gone
2016/07/12 23:28:07
Moving all of this code into this try block won't
megjablon
2016/07/13 01:03:28
The flakiness is addressed in the Infobar tests. T
gone
2016/07/13 01:09:04
Acknowledged.
| |
92 && packageInstallTime > releaseDateOfM48Stable.getTimeInMillis() ) { | 92 releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE) ); |
93 return false; | 93 long packageInstallTime = getPackageInstallTime(context); |
94 | |
95 // The boolean pref that stores whether user opted out on the first run experience was | |
96 // added in M51. If the last promo was shown before M51, then |freOr SecondRunVersion| | |
97 // will be empty. If Chrome was installed after the FRE promo was ad ded in M48 and | |
98 // beforeM51,assume the user opted out from the FRE and don't show t he infobar. | |
99 if (freOrSecondRunVersion.isEmpty() | |
100 && packageInstallTime > releaseDateOfM48Stable.getTimeInMill is()) { | |
101 return false; | |
102 } | |
103 | |
104 // Only show the promo if the current version is at least two milest ones after the last | |
105 // promo was displayed or the command line switch is on. If the last promo was shown | |
106 // before M51 then |freOrSecondRunVersion| will be empty and it is s afe to show the | |
107 // infobar promo. | |
108 if (!CommandLine.getInstance().hasSwitch(ENABLE_INFOBAR_SWITCH) | |
109 && !freOrSecondRunVersion.isEmpty() | |
110 && currentMilestone < VersionNumberGetter | |
111 .getMilestoneFromVersionNumber(freOrSecondRunVersion ) + 2) { | |
112 return false; | |
113 } | |
114 | |
115 DataReductionPromoInfoBar.launch(webContents, | |
116 BitmapFactory.decodeResource(context.getResources(), R.mipma p.app_icon), | |
117 context.getString(R.string.data_reduction_promo_infobar_titl e), | |
118 context.getString(R.string.data_reduction_promo_infobar_text ), | |
119 context.getString(R.string.data_reduction_promo_infobar_butt on), | |
120 context.getString(R.string.no_thanks)); | |
121 | |
122 return true; | |
123 } finally { | |
124 StrictMode.setThreadPolicy(oldPolicy); | |
94 } | 125 } |
95 | |
96 // Only show the promo if the current version is at least two milestones after the last | |
97 // promo was displayed or the command line switch is on. If the last pro mo was shown before | |
98 // M51 then |freOrSecondRunVersion| will be empty and it is safe to show the infobar promo. | |
99 if (!CommandLine.getInstance().hasSwitch(ENABLE_INFOBAR_SWITCH) | |
100 && !freOrSecondRunVersion.isEmpty() | |
101 && currentMilestone < VersionNumberGetter | |
102 .getMilestoneFromVersionNumber(freOrSecondRunVersion) + 2) { | |
103 return false; | |
104 } | |
105 | |
106 DataReductionPromoInfoBar.launch(webContents, | |
107 BitmapFactory.decodeResource(context.getResources(), R.mipmap.ap p_icon), | |
108 context.getString(R.string.data_reduction_promo_infobar_title), | |
109 context.getString(R.string.data_reduction_promo_infobar_text), | |
110 context.getString(R.string.data_reduction_promo_infobar_button), | |
111 context.getString(R.string.no_thanks)); | |
112 | |
113 return true; | |
114 } | 126 } |
115 | 127 |
116 /** | 128 /** |
117 * Gets the time at which this app was first installed in milliseconds since January 1, 1970 | 129 * Gets the time at which this app was first installed in milliseconds since January 1, 1970 |
118 * 00:00:00.0 UTC. | 130 * 00:00:00.0 UTC. |
119 * | 131 * |
120 * @param context An Android context. | 132 * @param context An Android context. |
121 * @return The time at which this app was first installed in milliseconds si nce the epoch or | 133 * @return The time at which this app was first installed in milliseconds si nce the epoch or |
122 * zero if the time cannot be retrieved. | 134 * zero if the time cannot be retrieved. |
123 */ | 135 */ |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 super(0, sIcon, sTitle, null, sPrimaryButtonText, sSecondaryButtonText); | 173 super(0, sIcon, sTitle, null, sPrimaryButtonText, sSecondaryButtonText); |
162 } | 174 } |
163 | 175 |
164 @Override | 176 @Override |
165 public void createContent(InfoBarLayout layout) { | 177 public void createContent(InfoBarLayout layout) { |
166 super.createContent(layout); | 178 super.createContent(layout); |
167 InfoBarControlLayout control = layout.addControlLayout(); | 179 InfoBarControlLayout control = layout.addControlLayout(); |
168 control.addDescription(sText); | 180 control.addDescription(sText); |
169 } | 181 } |
170 } | 182 } |
OLD | NEW |