| Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapShortWordSuppression.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapShortWordSuppression.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapShortWordSuppression.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bbd1672d4a97489aa1963a6040f4cf5e0d20377e
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapShortWordSuppression.java
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.chrome.browser.contextualsearch;
|
| +
|
| +import android.text.TextUtils;
|
| +
|
| +/**
|
| + * Implements the policy that a Tap on a short word should be ignored.
|
| + * This signal could be used for suppression so we aggregate-log too.
|
| + */
|
| +class TapShortWordSuppression extends ContextualSearchHeuristic {
|
| + private static final int TOO_SHORT_WORD_LENGTH = 3;
|
| +
|
| + private final boolean mIsSuppressionEnabled;
|
| + private final boolean mIsConditionSatisfied;
|
| +
|
| + /**
|
| + * Constructs a heuristic to determine if the current Tap is close to the edge of the word.
|
| + * @param contextualSearchContext The current {@link ContextualSearchContext} so we can figure
|
| + * out what part of the word has been tapped.
|
| + */
|
| + TapShortWordSuppression(ContextualSearchContext contextualSearchContext) {
|
| + mIsSuppressionEnabled = ContextualSearchFieldTrial.isShortWordSuppressionEnabled();
|
| + mIsConditionSatisfied = isTapOnShortWord(contextualSearchContext);
|
| + }
|
| +
|
| + @Override
|
| + protected boolean isConditionSatisfiedAndEnabled() {
|
| + return mIsSuppressionEnabled && mIsConditionSatisfied;
|
| + }
|
| +
|
| + @Override
|
| + protected void logResultsSeen(boolean wasSearchContentViewSeen, boolean wasActivatedByTap) {
|
| + if (wasActivatedByTap) {
|
| + ContextualSearchUma.logTapShortWordSeen(
|
| + wasSearchContentViewSeen, mIsConditionSatisfied);
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + protected boolean shouldAggregateLogForTapSuppression() {
|
| + return true;
|
| + }
|
| +
|
| + @Override
|
| + protected boolean isConditionSatisfiedForAggregateLogging() {
|
| + return mIsConditionSatisfied;
|
| + }
|
| +
|
| + /**
|
| + * @return Whether the tap is on a "short" word.
|
| + */
|
| + private boolean isTapOnShortWord(ContextualSearchContext contextualSearchContext) {
|
| + // If setup failed, don't suppress.
|
| + String tappedWord = contextualSearchContext.getTappedWord();
|
| + return !TextUtils.isEmpty(tappedWord) && tappedWord.length() <= TOO_SHORT_WORD_LENGTH;
|
| + }
|
| +}
|
|
|