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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java

Issue 1379183003: [ContextualSearch] Adds long press promo for Contextual Search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing more comments Created 5 years, 2 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/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() {

Powered by Google App Engine
This is Rietveld 408576698