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.content.Context; | 7 import android.content.Context; |
8 | 8 |
9 import org.chromium.base.VisibleForTesting; | 9 import org.chromium.base.VisibleForTesting; |
10 import org.chromium.chrome.browser.ChromeVersionInfo; | 10 import org.chromium.chrome.browser.ChromeVersionInfo; |
11 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon
troller.SelectionType; | 11 import org.chromium.chrome.browser.contextualsearch.ContextualSearchSelectionCon
troller.SelectionType; |
12 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 12 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
13 import org.chromium.chrome.browser.preferences.NetworkPredictionOptions; | 13 import org.chromium.chrome.browser.preferences.NetworkPredictionOptions; |
14 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 14 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
15 import org.chromium.content.browser.ContentViewCore; | 15 import org.chromium.content.browser.ContentViewCore; |
16 | 16 |
17 import java.net.URL; | 17 import java.net.URL; |
18 import java.util.regex.Pattern; | 18 import java.util.regex.Pattern; |
19 | 19 |
20 import javax.annotation.Nullable; | 20 import javax.annotation.Nullable; |
21 | 21 |
22 | 22 |
23 /** | 23 /** |
24 * Handles policy decisions for the {@code ContextualSearchManager}. | 24 * Handles policy decisions for the {@code ContextualSearchManager}. |
25 */ | 25 */ |
26 class ContextualSearchPolicy { | 26 class ContextualSearchPolicy { |
27 private static final Pattern CONTAINS_WHITESPACE_PATTERN = Pattern.compile("
\\s"); | 27 private static final Pattern CONTAINS_WHITESPACE_PATTERN = Pattern.compile("
\\s"); |
28 private static final int REMAINING_NOT_APPLICABLE = -1; | 28 private static final int REMAINING_NOT_APPLICABLE = -1; |
| 29 private static final int ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000; |
29 | 30 |
30 private static ContextualSearchPolicy sInstance; | 31 private static ContextualSearchPolicy sInstance; |
31 | 32 |
32 private final ChromePreferenceManager mPreferenceManager; | 33 private final ChromePreferenceManager mPreferenceManager; |
33 | 34 |
34 // Members used only for testing purposes. | 35 // Members used only for testing purposes. |
35 private boolean mDidOverrideDecidedStateForTesting; | 36 private boolean mDidOverrideDecidedStateForTesting; |
36 private boolean mDecidedStateForTesting; | 37 private boolean mDecidedStateForTesting; |
37 private boolean mDidResetCounters; | 38 private boolean mDidResetCounters; |
38 | 39 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 * TODO(donnd): Update this API to definitively determine if it's OK to send
the URL, | 298 * TODO(donnd): Update this API to definitively determine if it's OK to send
the URL, |
298 * by merging the checks in the native contextual_search_delegate here. | 299 * by merging the checks in the native contextual_search_delegate here. |
299 * @return {@code true} if the URL may be sent for policy reasons. | 300 * @return {@code true} if the URL may be sent for policy reasons. |
300 * Note that a return value of {@code true} may still require additi
onal checks | 301 * Note that a return value of {@code true} may still require additi
onal checks |
301 * to see if all privacy-related conditions are met to send the base
page URL. | 302 * to see if all privacy-related conditions are met to send the base
page URL. |
302 */ | 303 */ |
303 boolean maySendBasePageUrl() { | 304 boolean maySendBasePageUrl() { |
304 return !isUserUndecided(); | 305 return !isUserUndecided(); |
305 } | 306 } |
306 | 307 |
| 308 /** |
| 309 * The search provider icon is animated every time on long press if the user
has never opened |
| 310 * the panel before and once a day on tap. |
| 311 * |
| 312 * @param selectionType The type of selection made by the user. |
| 313 * @param isShowing Whether the panel is showing. |
| 314 * @return Whether the search provider icon should be animated. |
| 315 */ |
| 316 boolean shouldAnimateSearchProviderIcon(SelectionType selectionType, boolean
isShowing) { |
| 317 if (isShowing) { |
| 318 return false; |
| 319 } |
| 320 |
| 321 if (selectionType == SelectionType.TAP) { |
| 322 long currentTimeMillis = System.currentTimeMillis(); |
| 323 long lastAnimatedTimeMillis = |
| 324 mPreferenceManager.getContextualSearchLastAnimationTime(); |
| 325 if (Math.abs(currentTimeMillis - lastAnimatedTimeMillis) > ONE_DAY_I
N_MILLIS) { |
| 326 mPreferenceManager.setContextualSearchLastAnimationTime(currentT
imeMillis); |
| 327 return true; |
| 328 } else { |
| 329 return false; |
| 330 } |
| 331 } else if (selectionType == SelectionType.LONG_PRESS) { |
| 332 // If the panel has never been opened before, getPromoOpenCount() wi
ll be 0. |
| 333 // Once the panel has been opened, regardless of whether or not the
user has opted-in or |
| 334 // opted-out, the promo open count will be greater than zero. |
| 335 return getPromoOpenCount() == 0; |
| 336 } |
| 337 |
| 338 return false; |
| 339 } |
| 340 |
307 // -------------------------------------------------------------------------
------------------- | 341 // -------------------------------------------------------------------------
------------------- |
308 // Testing support. | 342 // Testing support. |
309 // -------------------------------------------------------------------------
------------------- | 343 // -------------------------------------------------------------------------
------------------- |
310 | 344 |
311 /** | 345 /** |
312 * Resets all policy counters. | 346 * Resets all policy counters. |
313 */ | 347 */ |
314 @VisibleForTesting | 348 @VisibleForTesting |
315 void resetCounters() { | 349 void resetCounters() { |
316 updateCountersForOpen(); | 350 updateCountersForOpen(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 453 |
420 /** | 454 /** |
421 * @return The limit of the number of taps to resolve using search term reso
lution. | 455 * @return The limit of the number of taps to resolve using search term reso
lution. |
422 */ | 456 */ |
423 private int getTapResolveLimit() { | 457 private int getTapResolveLimit() { |
424 return isUserUndecided() | 458 return isUserUndecided() |
425 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided() | 459 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided() |
426 : ContextualSearchFieldTrial.getTapResolveLimitForDecided(); | 460 : ContextualSearchFieldTrial.getTapResolveLimitForDecided(); |
427 } | 461 } |
428 } | 462 } |
OLD | NEW |