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

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 Aurimas's 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..ce77d3f0629e85e662cbef8251d5c8084010556f 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
@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.content.browser.ContentViewCore;
import java.net.URL;
+import java.util.Date;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
@@ -36,7 +37,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 +151,48 @@ class ContextualSearchPolicy {
}
/**
+ * @return Whether the Peek promo is available to be shown above the Search Bar.
+ */
+ public boolean isPeekPromoAvailable(ContextualSearchSelectionController controller) {
+ // 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;
+
+ // 5) The promo has not expired according to the expiration date defined by Finch..
aurimas (slooooooooow) 2015/10/03 00:54:02 Remove the extra period at the end of this comment
pedro (no code reviews) 2015/10/05 02:13:21 Code has been removed.
+ final Date expirationDate = ContextualSearchFieldTrial.getPeekPromoExpirationDate();
+ if (expirationDate != null) {
+ final Date currentDate = new Date();
+ if (currentDate.after(expirationDate)) 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