Chromium Code Reviews| 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..66bcb4fb99887413f2c719e11190ee4f29b75527 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,46 @@ class ContextualSearchPolicy { |
| } |
| /** |
| + * @return Whether the Peek promo is available to be shown in any panel. |
|
aurimas (slooooooooow)
2015/10/02 22:58:37
Any panel? It should probably say "to be shown in
pedro (no code reviews)
2015/10/03 00:11:27
Reworked the phrase.
|
| + */ |
| + 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.. |
| + final Date expirationDate = ContextualSearchFieldTrial.getPeekPromoExpirationDate(); |
|
aurimas (slooooooooow)
2015/10/02 22:58:37
Why do we need this? Can't we just update finch co
pedro (no code reviews)
2015/10/03 00:11:27
We don't know when the user will get a new Finch c
aurimas (slooooooooow)
2015/10/03 00:54:02
I still don't understand why we need this capabili
|
| + if (expirationDate != null) { |
| + final Date currentDate = new Date(); |
| + if (expirationDate != null && currentDate.after(expirationDate)) return false; |
| + } |
| + |
| + // 6) Only then, show the promo. |
| + return true; |
| + } |
| + |
| + public void registerPeekPromoSeen() { |
|
aurimas (slooooooooow)
2015/10/02 22:58:37
Add javadoc.
pedro (no code reviews)
2015/10/03 00:11:27
Done.
|
| + final int peekPromoShowCount = mPreferenceManager.getContextualSearchPeekPromoShowCount(); |
| + mPreferenceManager.setContextualSearchPeekPromoShowCount(peekPromoShowCount + 1); |
| + |
|
aurimas (slooooooooow)
2015/10/02 22:58:37
Remove empty line.
pedro (no code reviews)
2015/10/03 00:11:27
Done.
|
| + } |
| + |
| + /** |
| * Registers that a tap has taken place by incrementing tap-tracking counters. |
| */ |
| void registerTap() { |