OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.contextualsearch; | 5 package org.chromium.chrome.browser.contextualsearch; |
6 | 6 |
7 import android.text.TextUtils; | 7 import android.text.TextUtils; |
8 | 8 |
9 import org.chromium.base.CommandLine; | 9 import org.chromium.base.CommandLine; |
10 import org.chromium.base.SysUtils; | 10 import org.chromium.base.SysUtils; |
11 import org.chromium.chrome.browser.ChromeSwitches; | 11 import org.chromium.chrome.browser.ChromeSwitches; |
12 import org.chromium.chrome.browser.ChromeVersionInfo; | 12 import org.chromium.chrome.browser.ChromeVersionInfo; |
13 import org.chromium.components.variations.VariationsAssociatedData; | 13 import org.chromium.components.variations.VariationsAssociatedData; |
14 | 14 |
| 15 import java.text.ParseException; |
| 16 import java.text.SimpleDateFormat; |
15 import java.util.Arrays; | 17 import java.util.Arrays; |
| 18 import java.util.Date; |
16 import java.util.Locale; | 19 import java.util.Locale; |
17 | 20 |
18 /** | 21 /** |
19 * Provides Field Trial support for the Contextual Search application within Chr
ome for Android. | 22 * Provides Field Trial support for the Contextual Search application within Chr
ome for Android. |
20 */ | 23 */ |
21 public class ContextualSearchFieldTrial { | 24 public class ContextualSearchFieldTrial { |
22 private static final String FIELD_TRIAL_NAME = "ContextualSearch"; | 25 private static final String FIELD_TRIAL_NAME = "ContextualSearch"; |
23 private static final String ENABLED_PARAM = "enabled"; | 26 private static final String ENABLED_PARAM = "enabled"; |
24 private static final String ENABLED_VALUE = "true"; | 27 private static final String ENABLED_VALUE = "true"; |
25 | 28 |
26 private static final String DISABLE_FOR_CJK = "disable_for_cjk"; | 29 private static final String DISABLE_FOR_CJK = "disable_for_cjk"; |
27 private static final String DISABLE_FOR_CHINESE = "disable_for_chinese"; | 30 private static final String DISABLE_FOR_CHINESE = "disable_for_chinese"; |
28 private static final String DISABLE_FOR_JAPANESE = "disable_for_japanese"; | 31 private static final String DISABLE_FOR_JAPANESE = "disable_for_japanese"; |
29 private static final String DISABLE_FOR_KOREAN = "disable_for_korean"; | 32 private static final String DISABLE_FOR_KOREAN = "disable_for_korean"; |
30 | 33 |
31 // TODO(pedrosimonetti): Confirm if we can delete promo_on_longpress_only no
w. | 34 // TODO(pedrosimonetti): Confirm if we can delete promo_on_longpress_only no
w. |
32 private static final String PROMO_ON_LONGPRESS_ONLY = "promo_on_longpress_on
ly"; | 35 private static final String PROMO_ON_LONGPRESS_ONLY = "promo_on_longpress_on
ly"; |
33 static final String PROMO_ON_LIMITED_TAPS = "promo_on_limited_taps"; | 36 static final String PROMO_ON_LIMITED_TAPS = "promo_on_limited_taps"; |
34 static final String TAP_TRIGGERED_PROMO_LIMIT = "tap_triggered_promo_limit"; | 37 static final String TAP_TRIGGERED_PROMO_LIMIT = "tap_triggered_promo_limit"; |
35 static final String TAP_RESOLVE_LIMIT_FOR_DECIDED = "tap_resolve_limit_for_d
ecided"; | 38 static final String TAP_RESOLVE_LIMIT_FOR_DECIDED = "tap_resolve_limit_for_d
ecided"; |
36 static final String TAP_PREFETCH_LIMIT_FOR_DECIDED = "tap_prefetch_limit_for
_decided"; | 39 static final String TAP_PREFETCH_LIMIT_FOR_DECIDED = "tap_prefetch_limit_for
_decided"; |
37 static final String TAP_RESOLVE_LIMIT_FOR_UNDECIDED = "tap_resolve_limit_for
_undecided"; | 40 static final String TAP_RESOLVE_LIMIT_FOR_UNDECIDED = "tap_resolve_limit_for
_undecided"; |
38 static final String TAP_PREFETCH_LIMIT_FOR_UNDECIDED = "tap_prefetch_limit_f
or_undecided"; | 41 static final String TAP_PREFETCH_LIMIT_FOR_UNDECIDED = "tap_prefetch_limit_f
or_undecided"; |
39 | 42 |
| 43 static final String PEEK_PROMO_ENABLED = "peek_promo_enabled"; |
| 44 static final String PEEK_PROMO_MAX_SHOW_COUNT = "peek_promo_max_show_count"; |
| 45 static final String PEEK_PROMO_EXPIRATION_DATE = "peek_promo_expiration_date
"; |
| 46 private static final String PEEK_PROMO_EXPIRATION_DATE_FORMAT = "yyyy-MM-dd
HH:mm:ss"; |
| 47 static final int PEEK_PROMO_DEFAULT_MAX_SHOW_COUNT = 10; |
| 48 |
40 private static final String CHINESE_LANGUAGE_CODE = "zh"; | 49 private static final String CHINESE_LANGUAGE_CODE = "zh"; |
41 private static final String JAPANESE_LANGUAGE_CODE = "ja"; | 50 private static final String JAPANESE_LANGUAGE_CODE = "ja"; |
42 private static final String KOREAN_LANGUAGE_CODE = "ko"; | 51 private static final String KOREAN_LANGUAGE_CODE = "ko"; |
43 private static final String[] CJK_LANGUAGE_CODES = {CHINESE_LANGUAGE_CODE, | 52 private static final String[] CJK_LANGUAGE_CODES = {CHINESE_LANGUAGE_CODE, |
44 JAPANESE_LANGUAGE_CODE, KOREAN_LANGUAGE_CODE}; | 53 JAPANESE_LANGUAGE_CODE, KOREAN_LANGUAGE_CODE}; |
45 | 54 |
46 // The default navigation-detection-delay in milliseconds. | 55 // The default navigation-detection-delay in milliseconds. |
47 private static final int DEFAULT_TAP_NAVIGATION_DETECTION_DELAY = 16; | 56 private static final int DEFAULT_TAP_NAVIGATION_DETECTION_DELAY = 16; |
48 private static final String NAVIGATION_DETECTION_DELAY = "tap_navigation_det
ection_delay"; | 57 private static final String NAVIGATION_DETECTION_DELAY = "tap_navigation_det
ection_delay"; |
49 | 58 |
50 private static final int UNLIMITED_TAPS = -1; | 59 private static final int UNLIMITED_TAPS = -1; |
51 private static final int DEFAULT_TAP_RESOLVE_LIMIT_FOR_DECIDED = UNLIMITED_T
APS; | 60 private static final int DEFAULT_TAP_RESOLVE_LIMIT_FOR_DECIDED = UNLIMITED_T
APS; |
52 private static final int DEFAULT_TAP_PREFETCH_LIMIT_FOR_DECIDED = UNLIMITED_
TAPS; | 61 private static final int DEFAULT_TAP_PREFETCH_LIMIT_FOR_DECIDED = UNLIMITED_
TAPS; |
53 private static final int DEFAULT_TAP_RESOLVE_LIMIT_FOR_UNDECIDED = 100; | 62 private static final int DEFAULT_TAP_RESOLVE_LIMIT_FOR_UNDECIDED = 100; |
54 private static final int DEFAULT_TAP_PREFETCH_LIMIT_FOR_UNDECIDED = 10; | 63 private static final int DEFAULT_TAP_PREFETCH_LIMIT_FOR_UNDECIDED = 10; |
55 | 64 |
56 // Cached value to avoid repeated and redundant JNI operations. | 65 // Cached value to avoid repeated and redundant JNI operations. |
57 private static Boolean sEnabled; | 66 private static Boolean sEnabled; |
58 | 67 |
| 68 private static Boolean sIsPeekPromoEnabled; |
| 69 private static int sPeekPromoMaxCount; |
| 70 private static Date sPeekPromoExpirationDate; |
| 71 private static boolean sPeekPromoExpirationDateCached; |
| 72 |
59 /** | 73 /** |
60 * Don't instantiate. | 74 * Don't instantiate. |
61 */ | 75 */ |
62 private ContextualSearchFieldTrial() {} | 76 private ContextualSearchFieldTrial() {} |
63 | 77 |
64 /** | 78 /** |
65 * Checks the current Variations parameters associated with the active group
as well as the | 79 * Checks the current Variations parameters associated with the active group
as well as the |
66 * Chrome preference to determine if the service is enabled. | 80 * Chrome preference to determine if the service is enabled. |
67 * @return Whether Contextual Search is enabled or not. | 81 * @return Whether Contextual Search is enabled or not. |
68 */ | 82 */ |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 234 |
221 /** | 235 /** |
222 * @return The limit on the number of prefetches to issue for undecided user
s, or the default | 236 * @return The limit on the number of prefetches to issue for undecided user
s, or the default |
223 * if no value is present. | 237 * if no value is present. |
224 */ | 238 */ |
225 static int getTapPrefetchLimitForUndecided() { | 239 static int getTapPrefetchLimitForUndecided() { |
226 return getIntParamValueOrDefault(TAP_PREFETCH_LIMIT_FOR_UNDECIDED, | 240 return getIntParamValueOrDefault(TAP_PREFETCH_LIMIT_FOR_UNDECIDED, |
227 DEFAULT_TAP_PREFETCH_LIMIT_FOR_UNDECIDED); | 241 DEFAULT_TAP_PREFETCH_LIMIT_FOR_UNDECIDED); |
228 } | 242 } |
229 | 243 |
| 244 /** |
| 245 * @return Whether the Peek Promo is enabled. |
| 246 */ |
| 247 static boolean isPeekPromoEnabled() { |
| 248 if (sIsPeekPromoEnabled != null) return sIsPeekPromoEnabled; |
| 249 |
| 250 sIsPeekPromoEnabled = getBooleanParam(PEEK_PROMO_ENABLED); |
| 251 return sIsPeekPromoEnabled; |
| 252 } |
| 253 |
| 254 /** |
| 255 * @return The maximum number of times the Peek Promo should be displayed. |
| 256 */ |
| 257 static int getPeekPromoMaxShowCount() { |
| 258 if (sPeekPromoMaxCount > 0) return sPeekPromoMaxCount; |
| 259 |
| 260 sPeekPromoMaxCount = getIntParamValueOrDefault( |
| 261 PEEK_PROMO_MAX_SHOW_COUNT, |
| 262 PEEK_PROMO_DEFAULT_MAX_SHOW_COUNT); |
| 263 |
| 264 return sPeekPromoMaxCount; |
| 265 } |
| 266 |
| 267 /** |
| 268 * @return The expiration date of the Peek Promo, using the format |
| 269 */ |
| 270 static Date getPeekPromoExpirationDate() { |
| 271 if (sPeekPromoExpirationDateCached) return sPeekPromoExpirationDate; |
| 272 |
| 273 Date expirationDate = null; |
| 274 |
| 275 String expirationDateString = getStringParam(PEEK_PROMO_EXPIRATION_DATE)
; |
| 276 if (expirationDateString != null) { |
| 277 SimpleDateFormat format = |
| 278 new SimpleDateFormat(PEEK_PROMO_EXPIRATION_DATE_FORMAT, Loca
le.US); |
| 279 try { |
| 280 expirationDate = format.parse(expirationDateString); |
| 281 } catch (ParseException e) { |
| 282 e.printStackTrace(); |
| 283 } |
| 284 } |
| 285 |
| 286 sPeekPromoExpirationDateCached = true; |
| 287 sPeekPromoExpirationDate = expirationDate; |
| 288 return sPeekPromoExpirationDate; |
| 289 } |
| 290 |
230 // -------------------------------------------------------------------------
------------------- | 291 // -------------------------------------------------------------------------
------------------- |
231 // Helpers. | 292 // Helpers. |
232 // -------------------------------------------------------------------------
------------------- | 293 // -------------------------------------------------------------------------
------------------- |
233 | 294 |
234 /** | 295 /** |
235 * Gets a boolean Finch parameter, assuming the <paramName>="true" format.
Also checks for a | 296 * Gets a boolean Finch parameter, assuming the <paramName>="true" format.
Also checks for a |
236 * command-line switch with the same name, for easy local testing. | 297 * command-line switch with the same name, for easy local testing. |
237 * @param paramName The name of the Finch parameter (or command-line switch)
to get a value for. | 298 * @param paramName The name of the Finch parameter (or command-line switch)
to get a value for. |
238 * @return Whether the Finch param is defined with a value "true", if there'
s a command-line | 299 * @return Whether the Finch param is defined with a value "true", if there'
s a command-line |
239 * flag present with any value. | 300 * flag present with any value. |
(...skipping 21 matching lines...) Expand all Loading... |
261 if (!TextUtils.isEmpty(value)) { | 322 if (!TextUtils.isEmpty(value)) { |
262 try { | 323 try { |
263 return Integer.parseInt(value); | 324 return Integer.parseInt(value); |
264 } catch (NumberFormatException e) { | 325 } catch (NumberFormatException e) { |
265 return defaultValue; | 326 return defaultValue; |
266 } | 327 } |
267 } | 328 } |
268 | 329 |
269 return defaultValue; | 330 return defaultValue; |
270 } | 331 } |
| 332 |
| 333 /** |
| 334 * Returns a string value for a Finch parameter. Also checks for a command-l
ine switch. |
| 335 * @param paramName The name of the Finch parameter (or command-line switch)
to get a value for. |
| 336 * @return The command-line value, if present, or the finch parameter value. |
| 337 */ |
| 338 private static String getStringParam(String paramName) { |
| 339 if (CommandLine.getInstance().hasSwitch(paramName)) { |
| 340 return CommandLine.getInstance().getSwitchValue(paramName); |
| 341 } |
| 342 return VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME,
paramName); |
| 343 } |
271 } | 344 } |
OLD | NEW |