Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchPolicy.java

Issue 1337703002: [Contextual Search] Add support for crushed sprites and animate the search provider icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from self-review Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 * TODO(donnd): Update this API to definitively determine if it's OK to send the URL, 263 * TODO(donnd): Update this API to definitively determine if it's OK to send the URL,
263 * by merging the checks in the native contextual_search_delegate here. 264 * by merging the checks in the native contextual_search_delegate here.
264 * @return {@code true} if the URL may be sent for policy reasons. 265 * @return {@code true} if the URL may be sent for policy reasons.
265 * Note that a return value of {@code true} may still require additi onal checks 266 * Note that a return value of {@code true} may still require additi onal checks
266 * to see if all privacy-related conditions are met to send the base page URL. 267 * to see if all privacy-related conditions are met to send the base page URL.
267 */ 268 */
268 boolean maySendBasePageUrl() { 269 boolean maySendBasePageUrl() {
269 return !isUserUndecided(); 270 return !isUserUndecided();
270 } 271 }
271 272
273 /**
274 * The search provider icon is animated every time on long press if the user has never opened
275 * the panel before and once a day on tap.
276 *
277 * @param selectionType The type of selection made by the user.
278 * @return Whether the search provider icon should be animated.
279 */
280 boolean shouldAnimateSearchProviderIcon(SelectionType selectionType) {
281 if (selectionType == SelectionType.TAP) {
282 long currentTimeMillis = System.currentTimeMillis();
283 long lastAnimatedTimeMillis =
284 mPreferenceManager.getContextualSearchLastAnimationTime();
285 if (Math.abs(currentTimeMillis - lastAnimatedTimeMillis) > ONE_DAY_I N_MILLIS) {
286 mPreferenceManager.setContextualSearchLastAnimationTime(currentT imeMillis);
287 return true;
288 } else {
289 return false;
290 }
291 } else if (selectionType == SelectionType.LONG_PRESS) {
292 return DisableablePromoTapCounter.getInstance(mPreferenceManager).is Enabled();
293 }
294
295 return false;
296 }
297
272 // ------------------------------------------------------------------------- ------------------- 298 // ------------------------------------------------------------------------- -------------------
273 // Testing support. 299 // Testing support.
274 // ------------------------------------------------------------------------- ------------------- 300 // ------------------------------------------------------------------------- -------------------
275 301
276 /** 302 /**
277 * Resets all policy counters. 303 * Resets all policy counters.
278 */ 304 */
279 @VisibleForTesting 305 @VisibleForTesting
280 void resetCounters() { 306 void resetCounters() {
281 updateCountersForOpen(); 307 updateCountersForOpen();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 410
385 /** 411 /**
386 * @return The limit of the number of taps to resolve using search term reso lution. 412 * @return The limit of the number of taps to resolve using search term reso lution.
387 */ 413 */
388 private int getTapResolveLimit() { 414 private int getTapResolveLimit() {
389 return isUserUndecided() 415 return isUserUndecided()
390 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided() 416 ? ContextualSearchFieldTrial.getTapResolveLimitForUndecided()
391 : ContextualSearchFieldTrial.getTapResolveLimitForDecided(); 417 : ContextualSearchFieldTrial.getTapResolveLimitForDecided();
392 } 418 }
393 } 419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698