org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils Java Examples

The following examples show how to use org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataReductionPromoInfoBar.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a data reduction proxy {@link InfoBar} with the specified title and link
 * text. Clicking the link will open the specified settings page.
 *
 * @param webContents The {@link WebContents} in which to open the {@link InfoBar}.
 * @param icon Bitmap to use for the {@link 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,
        String secondaryButtonText) {
    sTitle = title;
    sText = text;
    sPrimaryButtonText = primaryButtonText;
    sSecondaryButtonText = secondaryButtonText;
    sIcon = icon;
    DataReductionPromoInfoBarDelegate.launch(webContents);
    DataReductionPromoUtils.saveInfoBarPromoDisplayed();
}
 
Example #2
Source File: DataReductionPromoSnackbarController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the Data Reduction Proxy promo snackbar if the current data savings are over
 * specific thresholds set by finch and the snackbar has not been shown for that
 *
 * @param dataSavingsInBytes The amount of data the Data Reduction Proxy has saved in bytes.
 */
public void maybeShowDataReductionPromoSnackbar(long dataSavingsInBytes) {
    // Prevents users who upgrade and have already saved mPromoDataSavingsInMB from seeing the
    // promo.
    if (!DataReductionPromoUtils.hasSnackbarPromoBeenInitWithStartingSavedBytes()) {
        DataReductionPromoUtils.saveSnackbarPromoDisplayed(dataSavingsInBytes);
        return;
    }

    for (int promoDataSavingsMB : mPromoDataSavingsMB) {
        long promoDataSavingsBytes = promoDataSavingsMB * BYTES_PER_MEGABYTE;
        if (promoDataSavingsMB > 0 && dataSavingsInBytes >= promoDataSavingsBytes
                && DataReductionPromoUtils
                        .getDisplayedSnackbarPromoSavedBytes() < promoDataSavingsBytes) {
            mSnackbarManager.showSnackbar(Snackbar
                    .make(getStringForBytes(promoDataSavingsBytes),
                            this,
                            Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DATA_REDUCTION_PROMO)
                    .setAction(
                            mContext.getString(R.string.data_reduction_promo_snackbar_button),
                            null));
            DataReductionProxyUma.dataReductionProxySnackbarPromo(promoDataSavingsMB);
            DataReductionPromoUtils.saveSnackbarPromoDisplayed(dataSavingsInBytes);
            break;
        }
    }
}
 
Example #3
Source File: DataReductionPromoInfoBar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a data reduction proxy {@link InfoBar} with the specified title and link
 * text. Clicking the link will open the specified settings page.
 *
 * @param webContents The {@link WebContents} in which to open the {@link InfoBar}.
 * @param icon Bitmap to use for the {@link 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,
        String secondaryButtonText) {
    sTitle = title;
    sText = text;
    sPrimaryButtonText = primaryButtonText;
    sSecondaryButtonText = secondaryButtonText;
    sIcon = icon;
    DataReductionPromoInfoBarDelegate.launch(webContents);
    DataReductionPromoUtils.saveInfoBarPromoDisplayed();
}
 
Example #4
Source File: DataReductionPromoSnackbarController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the Data Reduction Proxy promo snackbar if the current data savings are over
 * specific thresholds set by finch and the snackbar has not been shown for that
 *
 * @param dataSavingsInBytes The amount of data the Data Reduction Proxy has saved in bytes.
 */
public void maybeShowDataReductionPromoSnackbar(long dataSavingsInBytes) {
    // Prevents users who upgrade and have already saved mPromoDataSavingsInMB from seeing the
    // promo.
    if (!DataReductionPromoUtils.hasSnackbarPromoBeenInitWithStartingSavedBytes()) {
        DataReductionPromoUtils.saveSnackbarPromoDisplayed(dataSavingsInBytes);
        return;
    }

    for (int promoDataSavingsMB : mPromoDataSavingsMB) {
        long promoDataSavingsBytes = promoDataSavingsMB * BYTES_PER_MEGABYTE;
        if (promoDataSavingsMB > 0 && dataSavingsInBytes >= promoDataSavingsBytes
                && DataReductionPromoUtils
                        .getDisplayedSnackbarPromoSavedBytes() < promoDataSavingsBytes) {
            mSnackbarManager.showSnackbar(Snackbar
                    .make(getStringForBytes(promoDataSavingsBytes),
                            this,
                            Snackbar.TYPE_NOTIFICATION, Snackbar.UMA_DATA_REDUCTION_PROMO)
                    .setAction(
                            mContext.getString(R.string.data_reduction_promo_snackbar_button),
                            null));
            DataReductionProxyUma.dataReductionProxySnackbarPromo(promoDataSavingsMB);
            DataReductionPromoUtils.saveSnackbarPromoDisplayed(dataSavingsInBytes);
            break;
        }
    }
}
 
Example #5
Source File: DataReductionProxySettings.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Clears all data saving statistics.
 */
public void clearDataSavingStatistics() {
    // When the data saving statistics are cleared, reset the snackbar promo that tells the user
    // how much data they have saved using Data Saver so far.
    DataReductionPromoUtils.saveSnackbarPromoDisplayed(0);
    ContextUtils.getAppSharedPreferences()
            .edit()
            .putLong(DATA_REDUCTION_FIRST_ENABLED_TIME, System.currentTimeMillis())
            .apply();
    nativeClearDataSavingStatistics(mNativeDataReductionProxySettings);
}
 
Example #6
Source File: DataReductionPromoInfoBar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a data reduction proxy {@link InfoBar} with the specified title and link
 * text. Clicking the link will open the specified settings page.
 *
 * @param webContents The {@link WebContents} in which to open the {@link InfoBar}.
 * @param icon Bitmap to use for the {@link 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,
        String secondaryButtonText) {
    sTitle = title;
    sText = text;
    sPrimaryButtonText = primaryButtonText;
    sSecondaryButtonText = secondaryButtonText;
    sIcon = icon;
    DataReductionPromoInfoBarDelegate.launch(webContents);
    DataReductionPromoUtils.saveInfoBarPromoDisplayed();
}
 
Example #7
Source File: FirstRunActivity.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void completeFirstRunExperience() {
    if (!TextUtils.isEmpty(mResultSignInAccountName)) {
        boolean defaultAccountName =
                sGlue.isDefaultAccountName(getApplicationContext(), mResultSignInAccountName);
        int choice;
        if (mResultShowSignInSettings) {
            if (defaultAccountName) {
                choice = SIGNIN_SETTINGS_DEFAULT_ACCOUNT;
            } else {
                choice = SIGNIN_SETTINGS_ANOTHER_ACCOUNT;
            }
        } else {
            if (defaultAccountName) {
                choice = SIGNIN_ACCEPT_DEFAULT_ACCOUNT;
            } else {
                choice = SIGNIN_ACCEPT_ANOTHER_ACCOUNT;
            }
        }
        RecordHistogram.recordEnumeratedHistogram(
                UMA_SIGNIN_CHOICE, choice, SIGNIN_OPTION_COUNT);

        String entryType = mFreProperties.getBoolean(FirstRunActivity.COMING_FROM_CHROME_ICON)
                ? UMA_SIGNIN_CHOICE_ENTRY_MAIN_INTENT : UMA_SIGNIN_CHOICE_ENTRY_VIEW_INTENT;
        int numAccounts = sGlue.numberOfAccounts(getApplicationContext());
        String numAccountsString;
        if (numAccounts == 0) {
            numAccountsString = UMA_SIGNIN_CHOICE_ZERO_ACCOUNTS;
        } else if (numAccounts == 1) {
            numAccountsString = UMA_SIGNIN_CHOICE_ONE_ACCOUNT;
        } else {
            numAccountsString = UMA_SIGNIN_CHOICE_MANY_ACCOUNTS;
        }
        RecordHistogram.recordEnumeratedHistogram(
                UMA_SIGNIN_CHOICE + entryType + numAccountsString, choice, SIGNIN_OPTION_COUNT);
    }

    mFreProperties.putString(RESULT_SIGNIN_ACCOUNT_NAME, mResultSignInAccountName);
    mFreProperties.putBoolean(RESULT_SHOW_SIGNIN_SETTINGS, mResultShowSignInSettings);
    FirstRunFlowSequencer.markFlowAsCompleted(this, mFreProperties);

    if (DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) {
        if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) {
            DataReductionProxyUma
                    .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_FRE_ENABLED);
            DataReductionPromoUtils.saveFrePromoOptOut(false);
        } else {
            DataReductionProxyUma
                    .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_FRE_DISABLED);
            DataReductionPromoUtils.saveFrePromoOptOut(true);
        }
    }

    Intent resultData = new Intent();
    resultData.putExtras(mFreProperties);
    finishAllFREActivities(Activity.RESULT_OK, resultData);
}
 
Example #8
Source File: DataReductionProxyFirstRunFragment.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
}
 
Example #9
Source File: DataReductionPromoInfoBar.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Launch the data reduction infobar promo, if it needs to be displayed.
 *
 * @param context An Android context.
 * @param webContents The WebContents of the tab on which the infobar should show.
 * @param url The URL of the page on which the infobar should show.
 * @param isFragmentNavigation Whether the main frame navigation did not cause changes to the
 *            document (for example scrolling to a named anchor PopState).
 * @param statusCode The HTTP status code of the navigation.
 * @return boolean Whether the promo was launched.
 */
public static boolean maybeLaunchPromoInfoBar(Context context,
        WebContents webContents, String url, boolean isErrorPage, boolean isFragmentNavigation,
        int statusCode) {
    ThreadUtils.assertOnUiThread();
    if (webContents.isIncognito()) return false;
    if (isErrorPage) return false;
    if (isFragmentNavigation) return false;
    if (statusCode != HttpURLConnection.HTTP_OK) return false;
    if (!DataReductionPromoUtils.canShowPromos()) return false;

    // Don't show the infobar promo if neither the first run experience or second run promo has
    // been shown.
    if (!DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) return false;

    // Don't show the promo if the user opted out on the first run experience promo.
    if (DataReductionPromoUtils.getOptedOutOnFrePromo()) return false;

    // Don't show the promo if the user has seen this infobar promo before.
    if (DataReductionPromoUtils.getDisplayedInfoBarPromo()) return false;

    // Only show the promo on HTTP pages.
    if (!GURLUtils.getScheme(url).concat("://").equals(UrlConstants.HTTP_SCHEME)) return false;

    int currentMilestone = VersionNumberGetter.getMilestoneFromVersionNumber(
            PrefServiceBridge.getInstance().getAboutVersionStrings().getApplicationVersion());
    String freOrSecondRunVersion =
            DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion();

    Calendar releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE));
    long packageInstallTime = getPackageInstallTime(context);

    // The boolean pref that stores whether user opted out on the first run experience was
    // added in M51. If the last promo was shown before M51, then |freOrSecondRunVersion| will
    // be empty. If Chrome was installed after the FRE promo was added in M48 and before M51,
    // assume the user opted out from the FRE and don't show the infobar.
    if (freOrSecondRunVersion.isEmpty()
            && packageInstallTime > releaseDateOfM48Stable.getTimeInMillis()) {
        return false;
    }

    // Only show the promo if the current version is at least two milestones after the last
    // 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 < VersionNumberGetter
                    .getMilestoneFromVersionNumber(freOrSecondRunVersion) + 2) {
        return false;
    }

    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),
            context.getString(R.string.no_thanks));

    return true;
}
 
Example #10
Source File: DataReductionPromoSnackbarController.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an instance of a {@link DataReductionPromoSnackbarController}.
 *
 * @param context The {@link Context} in which snackbar is shown.
 * @param snackbarManager The manager that helps to show the snackbar.
 */
public DataReductionPromoSnackbarController(Context context, SnackbarManager snackbarManager) {
    mSnackbarManager = snackbarManager;
    mContext = context;

    String variationParamValue = VariationsAssociatedData
            .getVariationParamValue(PROMO_FIELD_TRIAL_NAME, PROMO_PARAM_NAME);

    if (variationParamValue.isEmpty()) {
        if (CommandLine.getInstance()
                .hasSwitch(ENABLE_DATA_REDUCTION_PROXY_SAVINGS_PROMO_SWITCH)) {
            mPromoDataSavingsMB = new int[1];
            mPromoDataSavingsMB[0] = 1;
        } else {
            mPromoDataSavingsMB = new int[0];
        }
    } else {
        variationParamValue = variationParamValue.replace(" ", "");
        String[] promoDataSavingStrings = variationParamValue.split(";");

        if (CommandLine.getInstance()
                .hasSwitch(ENABLE_DATA_REDUCTION_PROXY_SAVINGS_PROMO_SWITCH)) {
            mPromoDataSavingsMB = new int[promoDataSavingStrings.length + 1];
            mPromoDataSavingsMB[promoDataSavingStrings.length] = 1;
        } else {
            mPromoDataSavingsMB = new int[promoDataSavingStrings.length];
        }

        for (int i = 0; i < promoDataSavingStrings.length; i++) {
            try {
                mPromoDataSavingsMB[i] = Integer.parseInt(promoDataSavingStrings[i]);
            } catch (NumberFormatException e) {
                mPromoDataSavingsMB[i] = -1;
            }
        }
    }

    if (CommandLine.getInstance().hasSwitch(CLEAR_DATA_REDUCTION_PROXY_DATA_SAVINGS_SWITCH)) {
        DataReductionPromoUtils.saveSnackbarPromoDisplayed(0);
    }
}
 
Example #11
Source File: FirstRunActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void completeFirstRunExperience() {
    if (!TextUtils.isEmpty(mResultSignInAccountName)) {
        boolean defaultAccountName =
                sGlue.isDefaultAccountName(getApplicationContext(), mResultSignInAccountName);
        int choice;
        if (mResultShowSignInSettings) {
            if (defaultAccountName) {
                choice = SIGNIN_SETTINGS_DEFAULT_ACCOUNT;
            } else {
                choice = SIGNIN_SETTINGS_ANOTHER_ACCOUNT;
            }
        } else {
            if (defaultAccountName) {
                choice = SIGNIN_ACCEPT_DEFAULT_ACCOUNT;
            } else {
                choice = SIGNIN_ACCEPT_ANOTHER_ACCOUNT;
            }
        }
        sSigninChoiceHistogram.record(choice);
        recordFreProgressHistogram(FRE_PROGRESS_COMPLETED_SIGNED_IN);
    } else {
        recordFreProgressHistogram(FRE_PROGRESS_COMPLETED_NOT_SIGNED_IN);
    }

    mFreProperties.putString(RESULT_SIGNIN_ACCOUNT_NAME, mResultSignInAccountName);
    mFreProperties.putBoolean(RESULT_SHOW_SIGNIN_SETTINGS, mResultShowSignInSettings);
    FirstRunFlowSequencer.markFlowAsCompleted(this, mFreProperties);

    if (DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) {
        if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) {
            DataReductionProxyUma
                    .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_FRE_ENABLED);
            DataReductionPromoUtils.saveFrePromoOptOut(false);
        } else {
            DataReductionProxyUma
                    .dataReductionProxyUIAction(DataReductionProxyUma.ACTION_FRE_DISABLED);
            DataReductionPromoUtils.saveFrePromoOptOut(true);
        }
    }

    Intent resultData = new Intent();
    resultData.putExtras(mFreProperties);
    finishAllTheActivities(getLocalClassName(), Activity.RESULT_OK, resultData);

    sendPendingIntentIfNecessary(true);
}
 
Example #12
Source File: DataReductionProxyFirstRunFragment.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
}
 
Example #13
Source File: DataReductionPromoInfoBar.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Launch the data reduction infobar promo, if it needs to be displayed.
 *
 * @param context An Android context.
 * @param webContents The WebContents of the tab on which the infobar should show.
 * @param url The URL of the page on which the infobar should show.
 * @param isFragmentNavigation Whether the main frame navigation did not cause changes to the
 *            document (for example scrolling to a named anchor PopState).
 * @param statusCode The HTTP status code of the navigation.
 * @return boolean Whether the promo was launched.
 */
public static boolean maybeLaunchPromoInfoBar(Context context,
        WebContents webContents, String url, boolean isErrorPage, boolean isFragmentNavigation,
        int statusCode) {
    ThreadUtils.assertOnUiThread();
    if (webContents.isIncognito()) return false;
    if (isErrorPage) return false;
    if (isFragmentNavigation) return false;
    if (statusCode != HttpURLConnection.HTTP_OK) return false;
    if (!DataReductionPromoUtils.canShowPromos()) return false;

    // Don't show the infobar promo if neither the first run experience or second run promo has
    // been shown.
    if (!DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) return false;

    // Don't show the promo if the user opted out on the first run experience promo.
    if (DataReductionPromoUtils.getOptedOutOnFrePromo()) return false;

    // Don't show the promo if the user has seen this infobar promo before.
    if (DataReductionPromoUtils.getDisplayedInfoBarPromo()) return false;

    // Only show the promo on HTTP pages.
    if (!GURLUtils.getScheme(url).concat("://").equals(UrlConstants.HTTP_SCHEME)) return false;

    int currentMilestone = VersionNumberGetter.getMilestoneFromVersionNumber(
            PrefServiceBridge.getInstance().getAboutVersionStrings().getApplicationVersion());
    String freOrSecondRunVersion =
            DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion();

    // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577185
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        Calendar releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

        releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE));
        long packageInstallTime = getPackageInstallTime(context);

        // The boolean pref that stores whether user opted out on the first run experience was
        // added in M51. If the last promo was shown before M51, then |freOrSecondRunVersion|
        // will be empty. If Chrome was installed after the FRE promo was added in M48 and
        // beforeM51,assume the user opted out from the FRE and don't show the infobar.
        if (freOrSecondRunVersion.isEmpty()
                && packageInstallTime > releaseDateOfM48Stable.getTimeInMillis()) {
            return false;
        }

        // Only show the promo if the current version is at least two milestones after the last
        // 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 < VersionNumberGetter
                        .getMilestoneFromVersionNumber(freOrSecondRunVersion) + 2) {
            return false;
        }

        DataReductionPromoInfoBar.launch(webContents,
                BitmapFactory.decodeResource(context.getResources(),
                        R.drawable.infobar_chrome),
                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),
                context.getString(R.string.no_thanks));

        return true;
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
Example #14
Source File: DataReductionProxyFirstRunFragment.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    DataReductionPromoUtils.saveFreOrSecondRunPromoDisplayed();
}
 
Example #15
Source File: DataReductionPromoInfoBar.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Launch the data reduction infobar promo, if it needs to be displayed.
 *
 * @param context An Android context.
 * @param webContents The WebContents of the tab on which the infobar should show.
 * @param url The URL of the page on which the infobar should show.
 * @param isFragmentNavigation Whether the main frame navigation did not cause changes to the
 *            document (for example scrolling to a named anchor PopState).
 * @param statusCode The HTTP status code of the navigation.
 * @return boolean Whether the promo was launched.
 */
public static boolean maybeLaunchPromoInfoBar(Context context,
        WebContents webContents, String url, boolean isErrorPage, boolean isFragmentNavigation,
        int statusCode) {
    ThreadUtils.assertOnUiThread();
    if (webContents.isIncognito()) return false;
    if (isErrorPage) return false;
    if (isFragmentNavigation) return false;
    if (statusCode != HttpURLConnection.HTTP_OK) return false;
    if (!DataReductionPromoUtils.canShowPromos()) return false;

    // Don't show the infobar promo if neither the first run experience or second run promo has
    // been shown.
    if (!DataReductionPromoUtils.getDisplayedFreOrSecondRunPromo()) return false;

    // Don't show the promo if the user opted out on the first run experience promo.
    if (DataReductionPromoUtils.getOptedOutOnFrePromo()) return false;

    // Don't show the promo if the user has seen this infobar promo before.
    if (DataReductionPromoUtils.getDisplayedInfoBarPromo()) return false;

    // Only show the promo on HTTP pages.
    if (!GURLUtils.getScheme(url).equals(UrlConstants.HTTP_SCHEME)) return false;

    int currentMilestone = VersionNumberGetter.getMilestoneFromVersionNumber(
            PrefServiceBridge.getInstance().getAboutVersionStrings().getApplicationVersion());
    String freOrSecondRunVersion =
            DataReductionPromoUtils.getDisplayedFreOrSecondRunPromoVersion();

    // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577185
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        Calendar releaseDateOfM48Stable = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

        releaseDateOfM48Stable.setTime(Date.valueOf(M48_STABLE_RELEASE_DATE));
        long packageInstallTime = getPackageInstallTime(context);

        // The boolean pref that stores whether user opted out on the first run experience was
        // added in M51. If the last promo was shown before M51, then |freOrSecondRunVersion|
        // will be empty. If Chrome was installed after the FRE promo was added in M48 and
        // beforeM51,assume the user opted out from the FRE and don't show the infobar.
        if (freOrSecondRunVersion.isEmpty()
                && packageInstallTime > releaseDateOfM48Stable.getTimeInMillis()) {
            return false;
        }

        // Only show the promo if the current version is at least two milestones after the last
        // 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 < VersionNumberGetter
                        .getMilestoneFromVersionNumber(freOrSecondRunVersion) + 2) {
            return false;
        }

        DataReductionPromoInfoBar.launch(webContents,
                BitmapFactory.decodeResource(context.getResources(),
                        R.drawable.infobar_chrome),
                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),
                context.getString(R.string.no_thanks));

        return true;
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}