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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapWordNotLongEnoughSuppression.java

Issue 2906763002: [TTS] Add some initial signals for Tap in content. (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapWordNotLongEnoughSuppression.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapWordNotLongEnoughSuppression.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapWordNotLongEnoughSuppression.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec61c8f06aa1251f039d71a27c4ce67e1c6dfe9a
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/TapWordNotLongEnoughSuppression.java
@@ -0,0 +1,50 @@
+// 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 word that's not "long enough" should be suppressed.
+ * This signal would not be reasonable to use for suppression, so we do not aggregate-log it.
+ */
+class TapWordNotLongEnoughSuppression extends ContextualSearchHeuristic {
+ private static final int WORD_NOT_LONG_ENOUGH_LENGTH = 9;
+
+ 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.
+ */
+ TapWordNotLongEnoughSuppression(ContextualSearchContext contextualSearchContext) {
+ mIsSuppressionEnabled = ContextualSearchFieldTrial.isWordNotLongEnoughSuppressionEnabled();
+ mIsConditionSatisfied = isTapOnWordNotLongEnough(contextualSearchContext);
+ }
+
+ @Override
+ protected boolean isConditionSatisfiedAndEnabled() {
+ return mIsSuppressionEnabled && mIsConditionSatisfied;
+ }
+
+ @Override
+ protected void logResultsSeen(boolean wasSearchContentViewSeen, boolean wasActivatedByTap) {
+ if (wasActivatedByTap) {
+ ContextualSearchUma.logTapWordNotLongEnoughSeen(
+ wasSearchContentViewSeen, mIsConditionSatisfied);
+ }
+ }
+
+ /**
+ * @return Whether the tap is on a word that's not "long enough".
+ */
+ private boolean isTapOnWordNotLongEnough(ContextualSearchContext contextualSearchContext) {
+ // If setup failed, don't suppress.
+ String tappedWord = contextualSearchContext.getTappedWord();
+ return !TextUtils.isEmpty(tappedWord) && tappedWord.length() <= WORD_NOT_LONG_ENOUGH_LENGTH;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698