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

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: 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..b3353f6b75c6acfb884f9dfc6b76d32616ef3410 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,37 @@ class ContextualSearchPolicy {
}
/**
+ * @return Whether the Peek promo is available to be shown in any panel.
+ */
+ public boolean isPeekPromoAvailable(ContextualSearchSelectionController controller) {
+ if (!ContextualSearchFieldTrial.isPeekPromoEnabled()) return false;
+
+ if (!isUserUndecided()) return false;
+
+ if (controller.getSelectionType() != SelectionType.LONG_PRESS) return false;
+
+ // Check display limit.
+ final int maxShowCount = ContextualSearchFieldTrial.getPeekPromoMaxShowCount();
+ final int peekPromoShowCount = mPreferenceManager.getContextualSearchPeekPromoShowCount();
+ if (peekPromoShowCount >= maxShowCount) return false;
+
+ // Check expiration date.
+ final Date expirationDate = ContextualSearchFieldTrial.getPeekPromoExpirationDate();
+ if (expirationDate != null) {
+ final Date currentDate = new Date();
+ if (expirationDate != null && currentDate.after(expirationDate)) return false;
+ }
+
+ return true;
+ }
+
+ public void registerPeekPromoSeen() {
David Trainor- moved to gerrit 2015/10/02 20:49:20 javadoc
pedro (no code reviews) 2015/10/02 22:15:57 Done.
+ 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