org.chromium.chrome.browser.preferences.ChromePreferenceManager Java Examples

The following examples show how to use org.chromium.chrome.browser.preferences.ChromePreferenceManager. 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: ChromeWebApkHost.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Once native is loaded we can consult the command-line (set via about:flags) and also finch
 * state to see if we should enable WebAPKs.
 */
public static void cacheEnabledStateForNextLaunch() {
    ChromePreferenceManager preferenceManager =
            ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext());

    boolean wasCommandLineEnabled = preferenceManager.getCachedWebApkCommandLineEnabled();
    boolean isCommandLineEnabled = isCommandLineFlagSet();
    if (isCommandLineEnabled != wasCommandLineEnabled) {
        // {@link launchWebApkRequirementsDialogIfNeeded()} is skipped the first time Chrome is
        // launched so do caching here instead.
        preferenceManager.setCachedWebApkCommandLineEnabled(isCommandLineEnabled);
    }

    boolean wasEnabled = isEnabledInPrefs();
    boolean isEnabled = computeEnabled();
    if (isEnabled != wasEnabled) {
        Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnabled);
        preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled);
    }
}
 
Example #2
Source File: MinidumpUploadService.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Stores the successes and failures from uploading crash to UMA,
 */
public static void storeBreakpadUploadStatsInUma(ChromePreferenceManager pref) {
    for (String type : TYPES) {
        for (int success = pref.getCrashSuccessUploadCount(type); success > 0; success--) {
            RecordHistogram.recordEnumeratedHistogram(
                    HISTOGRAM_NAME_PREFIX + type,
                    SUCCESS,
                    HISTOGRAM_MAX);
        }
        for (int fail = pref.getCrashFailureUploadCount(type); fail > 0; fail--) {
            RecordHistogram.recordEnumeratedHistogram(
                    HISTOGRAM_NAME_PREFIX + type,
                    FAILURE,
                    HISTOGRAM_MAX);
        }

        pref.setCrashSuccessUploadCount(type, 0);
        pref.setCrashFailureUploadCount(type, 0);
    }
}
 
Example #3
Source File: SigninPromoUtil.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(activity);
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get(activity).isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startAccountSigninActivity(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example #4
Source File: FeatureUtilities.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * @return Which flavor of Herb is being tested.  See {@link ChromeSwitches#HERB_FLAVOR_ANISE}
 *         and its related switches.
 */
public static String getHerbFlavor() {
    Context context = ContextUtils.getApplicationContext();
    if (isHerbDisallowed(context)) return ChromeSwitches.HERB_FLAVOR_DISABLED;

    if (!sIsHerbFlavorCached) {
        sCachedHerbFlavor = null;

        // Allowing disk access for preferences while prototyping.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        try {
            sCachedHerbFlavor =
                    ChromePreferenceManager.getInstance(context).getCachedHerbFlavor();
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }

        sIsHerbFlavorCached = true;
        Log.d(TAG, "Retrieved cached Herb flavor: " + sCachedHerbFlavor);
    }

    return sCachedHerbFlavor;
}
 
Example #5
Source File: FeatureUtilities.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return Which flavor of Herb is being tested.
 *         See {@link ChromeSwitches#HERB_FLAVOR_ELDERBERRY} and its related switches.
 */
public static String getHerbFlavor() {
    Context context = ContextUtils.getApplicationContext();
    if (isHerbDisallowed(context)) return ChromeSwitches.HERB_FLAVOR_DISABLED;

    if (!sIsHerbFlavorCached) {
        sCachedHerbFlavor = null;

        // Allowing disk access for preferences while prototyping.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        try {
            sCachedHerbFlavor = ChromePreferenceManager.getInstance().getCachedHerbFlavor();
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }

        sIsHerbFlavorCached = true;
        Log.d(TAG, "Retrieved cached Herb flavor: " + sCachedHerbFlavor);
    }

    return sCachedHerbFlavor;
}
 
Example #6
Source File: MinidumpUploadService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Stores the successes and failures from uploading crash to UMA,
 */
public static void storeBreakpadUploadStatsInUma(ChromePreferenceManager pref) {
    for (String type : TYPES) {
        for (int success = pref.getCrashSuccessUploadCount(type); success > 0; success--) {
            RecordHistogram.recordEnumeratedHistogram(
                    HISTOGRAM_NAME_PREFIX + type, SUCCESS, HISTOGRAM_MAX);
        }
        for (int fail = pref.getCrashFailureUploadCount(type); fail > 0; fail--) {
            RecordHistogram.recordEnumeratedHistogram(
                    HISTOGRAM_NAME_PREFIX + type, FAILURE, HISTOGRAM_MAX);
        }

        pref.setCrashSuccessUploadCount(type, 0);
        pref.setCrashFailureUploadCount(type, 0);
    }
}
 
Example #7
Source File: InstantAppsHandler.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Cache whether the Instant Apps feature is enabled.
 * This should only be called with the native library loaded.
 */
public void cacheInstantAppsEnabled() {
    Context context = ContextUtils.getApplicationContext();
    boolean isEnabled = false;
    boolean wasEnabled = isEnabled(context);
    CommandLine instance = CommandLine.getInstance();
    if (instance.hasSwitch(ChromeSwitches.DISABLE_APP_LINK)) {
        isEnabled = false;
    } else if (instance.hasSwitch(ChromeSwitches.ENABLE_APP_LINK)) {
        isEnabled = true;
    } else {
        String experiment = FieldTrialList.findFullName(INSTANT_APPS_EXPERIMENT_NAME);
        if (INSTANT_APPS_DISABLED_ARM.equals(experiment)) {
            isEnabled = false;
        } else if (INSTANT_APPS_ENABLED_ARM.equals(experiment)) {
            isEnabled = true;
        }
    }

    if (isEnabled != wasEnabled) {
        ChromePreferenceManager.getInstance(context).setCachedInstantAppsEnabled(isEnabled);
    }
}
 
Example #8
Source File: SigninPromoUtil.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance();
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get().isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startIfAllowed(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example #9
Source File: SigninPromoUtil.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Launches the signin promo if it needs to be displayed.
 * @param activity The parent activity.
 * @return Whether the signin promo is shown.
 */
public static boolean launchSigninPromoIfNeeded(final Activity activity) {
    // The promo is displayed if Chrome is launched directly (i.e., not with the intent to
    // navigate to and view a URL on startup), the instance is part of the field trial,
    // and the promo has been marked to display.
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance(activity);
    if (MultiWindowUtils.getInstance().isLegacyMultiWindow(activity)) return false;
    if (!preferenceManager.getShowSigninPromo()) return false;
    preferenceManager.setShowSigninPromo(false);

    String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccountName();
    if (ChromeSigninController.get(activity).isSignedIn() || !TextUtils.isEmpty(lastSyncName)) {
        return false;
    }

    AccountSigninActivity.startIfAllowed(activity, SigninAccessPoint.SIGNIN_PROMO);
    preferenceManager.setSigninPromoShown();
    return true;
}
 
Example #10
Source File: MinidumpUploadService.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Stores the successes and failures from uploading crash to UMA,
 */
public static void storeBreakpadUploadStatsInUma(ChromePreferenceManager pref) {
    for (String type : TYPES) {
        for (int success = pref.getCrashSuccessUploadCount(type); success > 0; success--) {
            RecordHistogram.recordEnumeratedHistogram(
                    HISTOGRAM_NAME_PREFIX + type,
                    SUCCESS,
                    HISTOGRAM_MAX);
        }
        for (int fail = pref.getCrashFailureUploadCount(type); fail > 0; fail--) {
            RecordHistogram.recordEnumeratedHistogram(
                    HISTOGRAM_NAME_PREFIX + type,
                    FAILURE,
                    HISTOGRAM_MAX);
        }

        pref.setCrashSuccessUploadCount(type, 0);
        pref.setCrashFailureUploadCount(type, 0);
    }
}
 
Example #11
Source File: NewTabPageRecyclerView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * To be triggered when a snippet is bound to a ViewHolder.
 */
public void onSnippetBound(View cardView) {
    // We only run if the feature is enabled and once per NTP.
    if (!SnippetsConfig.isIncreasedCardVisibilityEnabled() || mFirstCardAnimationRun) return;
    mFirstCardAnimationRun = true;

    // We only want an animation to run if we are not scrolled.
    if (computeVerticalScrollOffset() != 0) return;

    // We only show the animation a certain number of times to a user.
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(getContext());
    int animCount = manager.getNewTabPageFirstCardAnimationRunCount();
    if (animCount > CardsVariationParameters.getFirstCardAnimationMaxRuns()) return;
    manager.setNewTabPageFirstCardAnimationRunCount(animCount + 1);

    // We do not show the animation if the user has previously seen it then scrolled.
    if (manager.getCardsImpressionAfterAnimation()) return;

    // The peeking card bounces up twice from its position.
    ObjectAnimator animator = ObjectAnimator.ofFloat(cardView, View.TRANSLATION_Y,
            0f, -mPeekingCardBounceDistance, 0f, -mPeekingCardBounceDistance, 0f);
    animator.setStartDelay(PEEKING_CARD_ANIMATION_START_DELAY_MS);
    animator.setDuration(PEEKING_CARD_ANIMATION_TIME_MS);
    animator.setInterpolator(PEEKING_CARD_INTERPOLATOR);
    animator.start();
}
 
Example #12
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    Context context = ContextUtils.getApplicationContext();

    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet(context)) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance(context);
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example #13
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * @return Which flavor of Herb is being tested.
 *         See {@link ChromeSwitches#HERB_FLAVOR_ELDERBERRY} and its related switches.
 */
public static String getHerbFlavor() {
    Context context = ContextUtils.getApplicationContext();
    if (isHerbDisallowed(context)) return ChromeSwitches.HERB_FLAVOR_DISABLED;

    if (!sIsHerbFlavorCached) {
        sCachedHerbFlavor = null;

        // Allowing disk access for preferences while prototyping.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        try {
            sCachedHerbFlavor =
                    ChromePreferenceManager.getInstance(context).getCachedHerbFlavor();
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }

        sIsHerbFlavorCached = true;
        Log.d(TAG, "Retrieved cached Herb flavor: " + sCachedHerbFlavor);
    }

    return sCachedHerbFlavor;
}
 
Example #14
Source File: CtrSuppression.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an object that tracks impressions and clicks per user to produce CTR and
 * impression metrics.
 */
CtrSuppression() {
    mPreferenceManager = ChromePreferenceManager.getInstance();

    // This needs to be done last in this constructor because the native code may call
    // into this object.
    mNativePointer = nativeInit();
}
 
Example #15
Source File: ContextualSearchSelectionController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Handles Tap suppression by making a callback to either the handler's #handleSuppressedTap()
 * or #handleNonSuppressedTap() after a possible delay.
 * This should be called when the context is fully built (by gathering surrounding text
 * if needed, etc) but before showing any UX.
 */
void handleShouldSuppressTap() {
    int x = (int) mX;
    int y = (int) mY;

    // TODO(donnd): add a policy method to get adjusted tap count.
    ChromePreferenceManager prefs = ChromePreferenceManager.getInstance();
    int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount()
            - prefs.getContextualSearchTapQuickAnswerCount();
    TapSuppressionHeuristics tapHeuristics =
            new TapSuppressionHeuristics(this, mLastTapState, x, y, adjustedTapsSinceOpen);
    // TODO(donnd): Move to be called when the panel closes to work with states that change.
    tapHeuristics.logConditionState();
    // Tell the manager what it needs in order to log metrics on whether the tap would have
    // been suppressed if each of the heuristics were satisfied.
    mHandler.handleMetricsForWouldSuppressTap(tapHeuristics);

    boolean shouldSuppressTap = tapHeuristics.shouldSuppressTap();
    if (mTapTimeNanoseconds != 0) {
        // Remember the tap state for subsequent tap evaluation.
        mLastTapState =
                new ContextualSearchTapState(x, y, mTapTimeNanoseconds, shouldSuppressTap);
    } else {
        mLastTapState = null;
    }

    if (shouldSuppressTap) {
        mHandler.handleSuppressedTap();
    } else {
        mHandler.handleNonSuppressedTap();
    }
}
 
Example #16
Source File: DefaultBrowserInfo.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize an AsyncTask for getting menu title of opening a link in default browser.
 */
public static void initBrowserFetcher() {
    synchronized (sDirCreationLock) {
        if (sDefaultBrowserFetcher == null) {
            sDefaultBrowserFetcher = new AsyncTask<Void, Void, ArrayList<String>>() {
                @Override
                protected ArrayList<String> doInBackground(Void... params) {
                    Context context = ContextUtils.getApplicationContext();
                    ArrayList<String> menuTitles = new ArrayList<String>(2);
                    // Store the package label of current application.
                    menuTitles.add(
                            getTitleFromPackageLabel(context, BuildInfo.getPackageLabel()));

                    PackageManager pm = context.getPackageManager();
                    ResolveInfo info = getResolveInfoForViewIntent(pm);

                    // Caches whether Chrome is set as a default browser on the device.
                    boolean isDefault = (info != null && info.match != 0
                            && context.getPackageName().equals(info.activityInfo.packageName));
                    ChromePreferenceManager.getInstance().setCachedChromeDefaultBrowser(
                            isDefault);

                    // Check if there is a default handler for the Intent.  If so, store its
                    // label.
                    String packageLabel = null;
                    if (info != null && info.match != 0 && info.loadLabel(pm) != null) {
                        packageLabel = info.loadLabel(pm).toString();
                    }
                    menuTitles.add(getTitleFromPackageLabel(context, packageLabel));
                    return menuTitles;
                }
            };
            sDefaultBrowserFetcher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }
}
 
Example #17
Source File: NewTabPageRecyclerView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onCardBound(CardViewHolder cardViewHolder) {
    if (cardViewHolder.getAdapterPosition() == getNewTabPageAdapter().getFirstCardPosition()) {
        updatePeekingCard(cardViewHolder);
    } else {
        cardViewHolder.setNotPeeking();
    }

    // Animate the peeking card.
    // We only run if the feature is enabled and once per NTP.
    if (!shouldAnimateFirstCard()) return;
    mFirstCardAnimationRun = true;

    // We only want an animation to run if we are not scrolled.
    if (computeVerticalScrollOffset() != 0) return;

    // We only show the animation a certain number of times to a user.
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance();
    int animCount = manager.getNewTabPageFirstCardAnimationRunCount();
    if (animCount > CardsVariationParameters.getFirstCardAnimationMaxRuns()) return;
    manager.setNewTabPageFirstCardAnimationRunCount(animCount + 1);

    // We do not show the animation if the user has previously seen it then scrolled.
    if (manager.getCardsImpressionAfterAnimation()) return;

    // The peeking card bounces up twice from its position.
    ObjectAnimator animator =
            ObjectAnimator.ofFloat(cardViewHolder.itemView, View.TRANSLATION_Y, 0f,
                    -mPeekingCardBounceDistance, 0f, -mPeekingCardBounceDistance, 0f);
    animator.setStartDelay(PEEKING_CARD_ANIMATION_START_DELAY_MS);
    animator.setDuration(PEEKING_CARD_ANIMATION_TIME_MS);
    animator.setInterpolator(PEEKING_CARD_INTERPOLATOR);
    animator.start();
}
 
Example #18
Source File: NewTabPageRecyclerView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onSnippetImpression() {
    // If the user has seen the first card animation and causes a snippet impression, remember
    // for future runs.
    if (!mFirstCardAnimationRun && !mCardImpressionAfterAnimationTracked) return;

    ChromePreferenceManager.getInstance().setCardsImpressionAfterAnimation(true);
    mCardImpressionAfterAnimationTracked = true;
}
 
Example #19
Source File: ChromeWebApkHost.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Check the cached value to figure out if the feature is enabled. We have to use the cached
 * value because native library may not yet been loaded.
 * @return Whether the feature is enabled.
 */
private static boolean isEnabledInPrefs() {
    // Will go away once the feature is enabled for everyone by default.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ChromePreferenceManager.getInstance().getCachedWebApkRuntimeEnabled();
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
Example #20
Source File: ChromeWebApkHost.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Once native is loaded we can consult the command-line (set via about:flags) and also finch
 * state to see if we should enable WebAPKs.
 */
public static void cacheEnabledStateForNextLaunch() {
    ChromePreferenceManager preferenceManager = ChromePreferenceManager.getInstance();

    boolean wasEnabled = isEnabledInPrefs();
    boolean isEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.IMPROVED_A2HS);
    if (isEnabled != wasEnabled) {
        Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnabled);
        preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled);
    }
}
 
Example #21
Source File: ContextualSearchPolicy.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * ContextualSearchPolicy constructor.
 */
public ContextualSearchPolicy(ContextualSearchSelectionController selectionController,
        ContextualSearchNetworkCommunicator networkCommunicator) {
    mPreferenceManager = ChromePreferenceManager.getInstance();

    mSelectionController = selectionController;
    mNetworkCommunicator = networkCommunicator;
}
 
Example #22
Source File: SignInPromo.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Hides the sign in promo and sets a preference to make sure it is not shown again. */
@Override
public void dismiss(Callback<String> itemRemovedCallback) {
    mDismissed = true;
    setVisible(false);

    ChromePreferenceManager.getInstance().setNewTabPageSigninPromoDismissed(true);
    mObserver.unregister();
    itemRemovedCallback.onResult(ContextUtils.getApplicationContext().getString(getHeader()));
}
 
Example #23
Source File: InstantAppsHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** @return Whether Chrome is the default browser on the device. */
private boolean isChromeDefaultHandler(Context context) {
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ChromePreferenceManager.getInstance().getCachedChromeDefaultBrowser();
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
Example #24
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not chrome should attach the toolbar to the bottom of the screen.
 */
public static boolean isChromeHomeEnabled() {
    if (sChromeHomeEnabled == null) {
        ChromePreferenceManager manager =
                ChromePreferenceManager.getInstance(ContextUtils.getApplicationContext());
        sChromeHomeEnabled = manager.isChromeHomeEnabled();
    }

    return sChromeHomeEnabled;
}
 
Example #25
Source File: FeatureUtilities.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Caches which flavor of Herb the user prefers from native.
 */
private static void cacheHerbFlavor() {
    Context context = ContextUtils.getApplicationContext();
    if (isHerbDisallowed(context)) return;

    String oldFlavor = getHerbFlavor();

    // Check the experiment value before the command line to put the user in the correct group.
    // The first clause does the null checks so so we can freely use the startsWith() function.
    String newFlavor = FieldTrialList.findFullName(HERB_EXPERIMENT_NAME);
    Log.d(TAG, "Experiment flavor: " + newFlavor);
    if (!TextUtils.isEmpty(newFlavor)
            && newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_ELDERBERRY)) {
        newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY;
    } else {
        newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED;
    }

    CommandLine instance = CommandLine.getInstance();
    if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH)) {
        newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED;
    } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_ELDERBERRY_SWITCH)) {
        newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY;
    }

    Log.d(TAG, "Caching flavor: " + newFlavor);
    sCachedHerbFlavor = newFlavor;

    if (!TextUtils.equals(oldFlavor, newFlavor)) {
        ChromePreferenceManager.getInstance().setCachedHerbFlavor(newFlavor);
    }
}
 
Example #26
Source File: FeatureUtilities.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Cache whether or not Chrome Home is enabled.
 */
public static void cacheChromeHomeEnabled() {
    // Chrome Home doesn't work with tablets.
    if (DeviceFormFactor.isTablet()) return;

    boolean isChromeHomeEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_HOME);
    ChromePreferenceManager manager = ChromePreferenceManager.getInstance();
    boolean valueChanged = isChromeHomeEnabled != manager.isChromeHomeEnabled();
    manager.setChromeHomeEnabled(isChromeHomeEnabled);
    sChromeHomeEnabled = isChromeHomeEnabled;

    // If the cached value changed, restart chrome.
    if (valueChanged) ApplicationLifetime.terminate(true);
}
 
Example #27
Source File: FeatureUtilities.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Caches which flavor of Herb the user prefers from native.
 */
private static void cacheHerbFlavor() {
    Context context = ContextUtils.getApplicationContext();
    if (isHerbDisallowed(context)) return;

    String oldFlavor = getHerbFlavor();

    // Check the experiment value before the command line to put the user in the correct group.
    // The first clause does the null checks so so we can freely use the startsWith() function.
    String newFlavor = FieldTrialList.findFullName(HERB_EXPERIMENT_NAME);
    Log.d(TAG, "Experiment flavor: " + newFlavor);
    if (!TextUtils.isEmpty(newFlavor)
            && newFlavor.startsWith(ChromeSwitches.HERB_FLAVOR_ELDERBERRY)) {
        newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY;
    } else {
        newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED;
    }

    CommandLine instance = CommandLine.getInstance();
    if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_DISABLED_SWITCH)) {
        newFlavor = ChromeSwitches.HERB_FLAVOR_DISABLED;
    } else if (instance.hasSwitch(ChromeSwitches.HERB_FLAVOR_ELDERBERRY_SWITCH)) {
        newFlavor = ChromeSwitches.HERB_FLAVOR_ELDERBERRY;
    }

    Log.d(TAG, "Caching flavor: " + newFlavor);
    sCachedHerbFlavor = newFlavor;

    if (!TextUtils.equals(oldFlavor, newFlavor)) {
        ChromePreferenceManager.getInstance(context).setCachedHerbFlavor(newFlavor);
    }
}
 
Example #28
Source File: FeatureUtilities.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not chrome should attach the toolbar to the bottom of the screen.
 */
public static boolean isChromeHomeEnabled() {
    if (sChromeHomeEnabled == null) {
        sChromeHomeEnabled = ChromePreferenceManager.getInstance().isChromeHomeEnabled();
    }

    return sChromeHomeEnabled;
}
 
Example #29
Source File: SuggestionsMetrics.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public static void recordSurfaceVisible() {
    if (!ChromePreferenceManager.getInstance().getSuggestionsSurfaceShown()) {
        RecordUserAction.record("Suggestions.FirstTimeSurfaceVisible");
        ChromePreferenceManager.getInstance().setSuggestionsSurfaceShown();
    }

    RecordUserAction.record("Suggestions.SurfaceVisible");
}
 
Example #30
Source File: DisableablePromoTapCounter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the singleton instance used to access the persistent counter.
 * @param prefsManager The ChromePreferenceManager to get prefs from.
 * @return the counter.
 */
static DisableablePromoTapCounter getInstance(
        ChromePreferenceManager prefsManager) {
    if (sInstance == null) {
        sInstance = new DisableablePromoTapCounter(prefsManager);
    }
    return sInstance;
}