| Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java
|
| index b7c134d46e2a60ac6ac9210c0d1b47f271e78aef..b7da20b266ae7e53bf201457264cf565b3ef22d4 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java
|
| @@ -36,7 +36,7 @@ class ContextualSearchPolicy {
|
| private boolean mDecidedStateForTesting;
|
| private boolean mDidResetCounters;
|
|
|
| - static ContextualSearchPolicy getInstance(Context context) {
|
| + public static ContextualSearchPolicy getInstance(Context context) {
|
| if (sInstance == null) {
|
| sInstance = new ContextualSearchPolicy(context);
|
| }
|
| @@ -150,6 +150,44 @@ class ContextualSearchPolicy {
|
| }
|
|
|
| /**
|
| + * @return Whether the Peek promo is available to be shown above the Search Bar.
|
| + */
|
| + public boolean isPeekPromoAvailable(ContextualSearchSelectionController controller) {
|
| + // Allow Promo to be forcefully enabled for testing.
|
| + if (ContextualSearchFieldTrial.isPeekPromoForced()) return true;
|
| +
|
| + // Check for several conditions to determine whether the Peek Promo is available.
|
| +
|
| + // 1) Enabled by Finch.
|
| + if (!ContextualSearchFieldTrial.isPeekPromoEnabled()) return false;
|
| +
|
| + // 2) If the Panel was never opened.
|
| + if (getPromoOpenCount() > 0) return false;
|
| +
|
| + // 3) User has not opted in.
|
| + if (!isUserUndecided()) return false;
|
| +
|
| + // 4) Selection was caused by a long press.
|
| + if (controller.getSelectionType() != SelectionType.LONG_PRESS) return false;
|
| +
|
| + // 5) Promo was not shown more than the maximum number of times defined by Finch.
|
| + final int maxShowCount = ContextualSearchFieldTrial.getPeekPromoMaxShowCount();
|
| + final int peekPromoShowCount = mPreferenceManager.getContextualSearchPeekPromoShowCount();
|
| + if (peekPromoShowCount >= maxShowCount) return false;
|
| +
|
| + // 6) Only then, show the promo.
|
| + return true;
|
| + }
|
| +
|
| + /**
|
| + * Register that the Peek Promo was seen.
|
| + */
|
| + public void registerPeekPromoSeen() {
|
| + final int peekPromoShowCount = mPreferenceManager.getContextualSearchPeekPromoShowCount();
|
| + mPreferenceManager.setContextualSearchPeekPromoShowCount(peekPromoShowCount + 1);
|
| + }
|
| +
|
| + /**
|
| * Registers that a tap has taken place by incrementing tap-tracking counters.
|
| */
|
| void registerTap() {
|
|
|