Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchFieldTrial.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchFieldTrial.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchFieldTrial.java |
index 0a3c3e46739179557628df28e1fdd0fcbad850b5..0ebd02b6f6cc81bc17cf31c60fd5e518585e5d06 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchFieldTrial.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchFieldTrial.java |
@@ -12,7 +12,10 @@ import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.ChromeVersionInfo; |
import org.chromium.components.variations.VariationsAssociatedData; |
+import java.text.ParseException; |
+import java.text.SimpleDateFormat; |
import java.util.Arrays; |
+import java.util.Date; |
import java.util.Locale; |
/** |
@@ -37,6 +40,12 @@ public class ContextualSearchFieldTrial { |
static final String TAP_RESOLVE_LIMIT_FOR_UNDECIDED = "tap_resolve_limit_for_undecided"; |
static final String TAP_PREFETCH_LIMIT_FOR_UNDECIDED = "tap_prefetch_limit_for_undecided"; |
+ static final String PEEK_PROMO_ENABLED = "peek_promo_enabled"; |
+ static final String PEEK_PROMO_MAX_SHOW_COUNT = "peek_promo_max_show_count"; |
+ static final String PEEK_PROMO_EXPIRATION_DATE = "peek_promo_expiration_date"; |
+ private static final String PEEK_PROMO_EXPIRATION_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; |
+ static final int PEEK_PROMO_DEFAULT_MAX_SHOW_COUNT = 10; |
+ |
private static final String CHINESE_LANGUAGE_CODE = "zh"; |
private static final String JAPANESE_LANGUAGE_CODE = "ja"; |
private static final String KOREAN_LANGUAGE_CODE = "ko"; |
@@ -56,6 +65,11 @@ public class ContextualSearchFieldTrial { |
// Cached value to avoid repeated and redundant JNI operations. |
private static Boolean sEnabled; |
+ private static Boolean sIsPeekPromoEnabled; |
+ private static int sPeekPromoMaxCount; |
+ private static Date sPeekPromoExpirationDate; |
+ private static boolean sPeekPromoExpirationDateCached; |
+ |
/** |
* Don't instantiate. |
*/ |
@@ -227,6 +241,53 @@ public class ContextualSearchFieldTrial { |
DEFAULT_TAP_PREFETCH_LIMIT_FOR_UNDECIDED); |
} |
+ /** |
+ * @return Whether the Peek Promo is enabled. |
+ */ |
+ static boolean isPeekPromoEnabled() { |
+ if (sIsPeekPromoEnabled != null) return sIsPeekPromoEnabled; |
+ |
+ sIsPeekPromoEnabled = getBooleanParam(PEEK_PROMO_ENABLED); |
+ return sIsPeekPromoEnabled; |
+ } |
+ |
+ /** |
+ * @return The maximum number of times the Peek Promo should be displayed. |
+ */ |
+ static int getPeekPromoMaxShowCount() { |
+ if (sPeekPromoMaxCount > 0) return sPeekPromoMaxCount; |
+ |
+ sPeekPromoMaxCount = getIntParamValueOrDefault( |
+ PEEK_PROMO_MAX_SHOW_COUNT, |
+ PEEK_PROMO_DEFAULT_MAX_SHOW_COUNT); |
+ |
+ return sPeekPromoMaxCount; |
+ } |
+ |
+ /** |
+ * @return The expiration date of the Peek Promo, using the format |
+ */ |
+ static Date getPeekPromoExpirationDate() { |
+ if (sPeekPromoExpirationDateCached) return sPeekPromoExpirationDate; |
+ |
+ Date expirationDate = null; |
+ |
+ String expirationDateString = getStringParam(PEEK_PROMO_EXPIRATION_DATE); |
+ if (expirationDateString != null) { |
+ SimpleDateFormat format = |
+ new SimpleDateFormat(PEEK_PROMO_EXPIRATION_DATE_FORMAT, Locale.US); |
+ try { |
+ expirationDate = format.parse(expirationDateString); |
+ } catch (ParseException e) { |
+ e.printStackTrace(); |
+ } |
+ } |
+ |
+ sPeekPromoExpirationDateCached = true; |
+ sPeekPromoExpirationDate = expirationDate; |
+ return sPeekPromoExpirationDate; |
+ } |
+ |
// -------------------------------------------------------------------------------------------- |
// Helpers. |
// -------------------------------------------------------------------------------------------- |
@@ -268,4 +329,16 @@ public class ContextualSearchFieldTrial { |
return defaultValue; |
} |
+ |
+ /** |
+ * Returns a string value for a Finch parameter. Also checks for a command-line switch. |
+ * @param paramName The name of the Finch parameter (or command-line switch) to get a value for. |
+ * @return The command-line value, if present, or the finch parameter value. |
+ */ |
+ private static String getStringParam(String paramName) { |
+ if (CommandLine.getInstance().hasSwitch(paramName)) { |
+ return CommandLine.getInstance().getSwitchValue(paramName); |
+ } |
+ return VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName); |
+ } |
} |