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 return DisableablePromoTapCounter.getInstance(mPreferenceManager).is Enabled(); | |
pedro (no code reviews)
2015/10/27 20:32:00
As we've discussed offline, this counter is for ta
Theresa
2015/10/28 02:01:53
Done.
| |
333 } | |
334 | |
335 return false; | |
336 } | |
337 | |
307 // ------------------------------------------------------------------------- ------------------- | 338 // ------------------------------------------------------------------------- ------------------- |
308 // Testing support. | 339 // Testing support. |
309 // ------------------------------------------------------------------------- ------------------- | 340 // ------------------------------------------------------------------------- ------------------- |
310 | 341 |
311 /** | 342 /** |
312 * Resets all policy counters. | 343 * Resets all policy counters. |
313 */ | 344 */ |
314 @VisibleForTesting | 345 @VisibleForTesting |
315 void resetCounters() { | 346 void resetCounters() { |
316 updateCountersForOpen(); | 347 updateCountersForOpen(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 | 450 |
420 /** | 451 /** |
421 * @return The limit of the number of taps to resolve using search term reso lution. | 452 * @return The limit of the number of taps to resolve using search term reso lution. |
422 */ | 453 */ |
423 private int getTapResolveLimit() { | 454 private int getTapResolveLimit() { |
424 return isUserUndecided() | 455 return isUserUndecided() |
425 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided() | 456 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided() |
426 : ContextualSearchFieldTrial.getTapResolveLimitForDecided(); | 457 : ContextualSearchFieldTrial.getTapResolveLimitForDecided(); |
427 } | 458 } |
428 } | 459 } |
OLD | NEW |