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

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

Issue 2894913003: [TTS] Move Ranker logging to inference time. (Closed)
Patch Set: Fix some asserts and minor cleanup. 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/ContextualSearchManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java
index fc22a8e0145a99d572dbba9323e996e8bc7d9554..e62d2a056021621948f3ed524c944017fb3bef58 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java
@@ -94,6 +94,8 @@ public class ContextualSearchManager implements ContextualSearchManagementDelega
// timer).
private static final int TAP_NEAR_PREVIOUS_DETECTION_DELAY_MS = 100;
+ private static final int NANOSECONDS_IN_A_MILLISECOND = 1000000;
+
private final ObserverList<ContextualSearchObserver> mObservers =
new ObserverList<ContextualSearchObserver>();
@@ -102,6 +104,9 @@ public class ContextualSearchManager implements ContextualSearchManagementDelega
private final ViewTreeObserver.OnGlobalFocusChangeListener mOnFocusChangeListener;
private final TabModelObserver mTabModelObserver;
+ // The Ranker logger to use to write Tap Suppression Ranker logs to UMA.
+ private final ContextualSearchRankerLogger mTapSuppressionRankerLogger;
+
private ContextualSearchSelectionController mSelectionController;
private ContextualSearchNetworkCommunicator mNetworkCommunicator;
private ContextualSearchPolicy mPolicy;
@@ -224,15 +229,12 @@ public class ContextualSearchManager implements ContextualSearchManagementDelega
};
mSelectionController = new ContextualSearchSelectionController(activity, this);
-
mNetworkCommunicator = this;
-
mPolicy = new ContextualSearchPolicy(mSelectionController, mNetworkCommunicator);
-
mTranslateController = new ContextualSearchTranslateController(activity, mPolicy, this);
-
mInternalStateController = new ContextualSearchInternalStateController(
mPolicy, getContextualSearchInternalStateHandler());
+ mTapSuppressionRankerLogger = new ContextualSearchRankerLoggerImpl();
}
/**
@@ -1291,10 +1293,40 @@ public class ContextualSearchManager implements ContextualSearchManagementDelega
}
@Override
- public void handleNonSuppressedTap() {
+ public void handleNonSuppressedTap(long tapTimeNanoseconds) {
if (mIsAccessibilityModeEnabled) return;
- mInternalStateController.notifyFinishedWorkOn(InternalState.DECIDING_SUPPRESSION);
+ // If there's a wait-after-tap experiment then we may want to delay a bit longer for
+ // the user to take an action like scrolling that will reset our internal state.
+ long delayBeforeFinishingWorkMs = 0;
+ if (ContextualSearchFieldTrial.getWaitAfterTapDelayMs() > 0 && tapTimeNanoseconds > 0) {
+ delayBeforeFinishingWorkMs = ContextualSearchFieldTrial.getWaitAfterTapDelayMs()
+ - (System.nanoTime() - tapTimeNanoseconds) / NANOSECONDS_IN_A_MILLISECOND;
+ }
+
+ // Finish work on the current state, either immediately or with a delay.
+ if (delayBeforeFinishingWorkMs <= 0) {
+ finishSuppressionDecision();
+ } else {
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ finishSuppressionDecision();
+ }
+ }, delayBeforeFinishingWorkMs);
+ }
+ }
+
+ /**
+ * Finishes work on the suppression decision if that work is still in progress.
+ * If no longer working on the suppression decision then resets the Ranker-logger.
+ */
+ private void finishSuppressionDecision() {
+ if (mInternalStateController.isStillWorkingOn(InternalState.DECIDING_SUPPRESSION)) {
+ mInternalStateController.notifyFinishedWorkOn(InternalState.DECIDING_SUPPRESSION);
+ } else {
+ mTapSuppressionRankerLogger.reset();
+ }
}
@Override
@@ -1308,7 +1340,7 @@ public class ContextualSearchManager implements ContextualSearchManagementDelega
mHeuristics.add(mQuickAnswersHeuristic);
mSearchPanel.getPanelMetrics().setResultsSeenExperiments(mHeuristics);
- mSearchPanel.getPanelMetrics().setRankerLogExperiments(mHeuristics, getBasePageUrl());
+ mSearchPanel.getPanelMetrics().setRankerLogger(mTapSuppressionRankerLogger);
}
@Override
@@ -1442,7 +1474,12 @@ public class ContextualSearchManager implements ContextualSearchManagementDelega
@Override
public void decideSuppression() {
mInternalStateController.notifyStartingWorkOn(InternalState.DECIDING_SUPPRESSION);
- mSelectionController.handleShouldSuppressTap();
+ // Ranker will handle the suppression, but our legacy implementation uses
+ // TapSuppressionHeuristics (run from the ContextualSearchSelectionConroller).
+ mTapSuppressionRankerLogger.setupLoggingForPage(getBasePageUrl());
+
+ // TODO(donnd): Move handleShouldSuppressTap out of the Selection Controller.
+ mSelectionController.handleShouldSuppressTap(mTapSuppressionRankerLogger);
}
/** Starts showing the Tap UI by selecting a word around the current caret. */

Powered by Google App Engine
This is Rietveld 408576698