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

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

Issue 2894913003: [TTS] Move Ranker logging to inference time. (Closed)
Patch Set: Rebase only. Created 3 years, 6 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.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.os.Handler; 8 import android.os.Handler;
9 import android.text.TextUtils; 9 import android.text.TextUtils;
10 import android.view.View; 10 import android.view.View;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 // How long to wait for a tap near a previous tap before hiding the UI or sh owing a re-Tap. 88 // How long to wait for a tap near a previous tap before hiding the UI or sh owing a re-Tap.
89 // This setting is not critical: in practice it determines how long to wait after an invalid 89 // This setting is not critical: in practice it determines how long to wait after an invalid
90 // tap for the page to respond before hiding the UI. Specifically this setti ng just needs to be 90 // tap for the page to respond before hiding the UI. Specifically this setti ng just needs to be
91 // long enough for Blink's decisions before calling handleShowUnhandledTapUI IfNeeded (which 91 // long enough for Blink's decisions before calling handleShowUnhandledTapUI IfNeeded (which
92 // probably are page-dependent), and short enough that the Bar goes away fai rly quickly after a 92 // probably are page-dependent), and short enough that the Bar goes away fai rly quickly after a
93 // tap on non-text or whitespace: We currently do not get notification in th ese cases (hence the 93 // tap on non-text or whitespace: We currently do not get notification in th ese cases (hence the
94 // timer). 94 // timer).
95 private static final int TAP_NEAR_PREVIOUS_DETECTION_DELAY_MS = 100; 95 private static final int TAP_NEAR_PREVIOUS_DETECTION_DELAY_MS = 100;
96 96
97 private static final int NANOSECONDS_IN_A_MILLISECOND = 1000000;
98
97 private final ObserverList<ContextualSearchObserver> mObservers = 99 private final ObserverList<ContextualSearchObserver> mObservers =
98 new ObserverList<ContextualSearchObserver>(); 100 new ObserverList<ContextualSearchObserver>();
99 101
100 private final ChromeActivity mActivity; 102 private final ChromeActivity mActivity;
101 private final ContextualSearchTabPromotionDelegate mTabPromotionDelegate; 103 private final ContextualSearchTabPromotionDelegate mTabPromotionDelegate;
102 private final ViewTreeObserver.OnGlobalFocusChangeListener mOnFocusChangeLis tener; 104 private final ViewTreeObserver.OnGlobalFocusChangeListener mOnFocusChangeLis tener;
103 private final TabModelObserver mTabModelObserver; 105 private final TabModelObserver mTabModelObserver;
104 106
107 // The Ranker logger to use to write Tap Suppression Ranker logs to UMA.
108 private final ContextualSearchRankerLogger mTapSuppressionRankerLogger;
109
105 private ContextualSearchSelectionController mSelectionController; 110 private ContextualSearchSelectionController mSelectionController;
106 private ContextualSearchNetworkCommunicator mNetworkCommunicator; 111 private ContextualSearchNetworkCommunicator mNetworkCommunicator;
107 private ContextualSearchPolicy mPolicy; 112 private ContextualSearchPolicy mPolicy;
108 private ContextualSearchInternalStateController mInternalStateController; 113 private ContextualSearchInternalStateController mInternalStateController;
109 114
110 @VisibleForTesting 115 @VisibleForTesting
111 protected ContextualSearchTranslateController mTranslateController; 116 protected ContextualSearchTranslateController mTranslateController;
112 117
113 // The Overlay panel. 118 // The Overlay panel.
114 private ContextualSearchPanel mSearchPanel; 119 private ContextualSearchPanel mSearchPanel;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 @Override 222 @Override
218 public void didAddTab(Tab tab, TabLaunchType type) { 223 public void didAddTab(Tab tab, TabLaunchType type) {
219 // If we're in the process of promoting this tab, just return an d don't mess with 224 // If we're in the process of promoting this tab, just return an d don't mess with
220 // this state. 225 // this state.
221 if (tab.getContentViewCore() == mSearchPanel.getContentViewCore( )) return; 226 if (tab.getContentViewCore() == mSearchPanel.getContentViewCore( )) return;
222 hideContextualSearch(StateChangeReason.UNKNOWN); 227 hideContextualSearch(StateChangeReason.UNKNOWN);
223 } 228 }
224 }; 229 };
225 230
226 mSelectionController = new ContextualSearchSelectionController(activity, this); 231 mSelectionController = new ContextualSearchSelectionController(activity, this);
227
228 mNetworkCommunicator = this; 232 mNetworkCommunicator = this;
229
230 mPolicy = new ContextualSearchPolicy(mSelectionController, mNetworkCommu nicator); 233 mPolicy = new ContextualSearchPolicy(mSelectionController, mNetworkCommu nicator);
231
232 mTranslateController = new ContextualSearchTranslateController(activity, mPolicy, this); 234 mTranslateController = new ContextualSearchTranslateController(activity, mPolicy, this);
233
234 mInternalStateController = new ContextualSearchInternalStateController( 235 mInternalStateController = new ContextualSearchInternalStateController(
235 mPolicy, getContextualSearchInternalStateHandler()); 236 mPolicy, getContextualSearchInternalStateHandler());
237 mTapSuppressionRankerLogger = new ContextualSearchRankerLoggerImpl();
236 } 238 }
237 239
238 /** 240 /**
239 * Initializes this manager. 241 * Initializes this manager.
240 * @param parentView The parent view to attach Contextual Search UX to. 242 * @param parentView The parent view to attach Contextual Search UX to.
241 */ 243 */
242 public void initialize(ViewGroup parentView) { 244 public void initialize(ViewGroup parentView) {
243 mNativeContextualSearchManagerPtr = nativeInit(); 245 mNativeContextualSearchManagerPtr = nativeInit();
244 246
245 mParentView = parentView; 247 mParentView = parentView;
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 * @param doesAnswer Whether the caption should be regarded as an answer suc h 778 * @param doesAnswer Whether the caption should be regarded as an answer suc h
777 * that the user may not need to open the panel, or whether the capti on 779 * that the user may not need to open the panel, or whether the capti on
778 * is simply informative or descriptive of the answer in the full res ults. 780 * is simply informative or descriptive of the answer in the full res ults.
779 */ 781 */
780 @CalledByNative 782 @CalledByNative
781 private void onSetCaption(String caption, boolean doesAnswer) { 783 private void onSetCaption(String caption, boolean doesAnswer) {
782 if (TextUtils.isEmpty(caption)) return; 784 if (TextUtils.isEmpty(caption)) return;
783 785
784 // Notify the UI of the caption. 786 // Notify the UI of the caption.
785 mSearchPanel.setCaption(caption); 787 mSearchPanel.setCaption(caption);
788 System.out.println("ctxs checking mQuickAnswersHeuristic " + mQuickAnswe rsHeuristic);
786 if (mQuickAnswersHeuristic != null) { 789 if (mQuickAnswersHeuristic != null) {
787 mQuickAnswersHeuristic.setConditionSatisfied(true); 790 mQuickAnswersHeuristic.setConditionSatisfied(true);
788 mQuickAnswersHeuristic.setDoesAnswer(doesAnswer); 791 mQuickAnswersHeuristic.setDoesAnswer(doesAnswer);
789 } 792 }
790 793
791 // Update Tap counters to account for a possible answer. 794 // Update Tap counters to account for a possible answer.
792 mPolicy.updateCountersForQuickAnswer(mWasActivatedByTap, doesAnswer); 795 mPolicy.updateCountersForQuickAnswer(mWasActivatedByTap, doesAnswer);
793 } 796 }
794 797
795 /** 798 /**
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 } 1287 }
1285 1288
1286 @Override 1289 @Override
1287 public void handleSuppressedTap() { 1290 public void handleSuppressedTap() {
1288 if (mIsAccessibilityModeEnabled) return; 1291 if (mIsAccessibilityModeEnabled) return;
1289 1292
1290 hideContextualSearch(StateChangeReason.BASE_PAGE_TAP); 1293 hideContextualSearch(StateChangeReason.BASE_PAGE_TAP);
1291 } 1294 }
1292 1295
1293 @Override 1296 @Override
1294 public void handleNonSuppressedTap() { 1297 public void handleNonSuppressedTap(long tapTimeNanoseconds) {
1295 if (mIsAccessibilityModeEnabled) return; 1298 if (mIsAccessibilityModeEnabled) return;
1296 1299
1297 mInternalStateController.notifyFinishedWorkOn(InternalState.DECIDING_SUP PRESSION); 1300 // If there's a wait-after-tap experiment then we may want to delay a bi t longer for
1301 // the user to take an action like scrolling that will reset our interna l state.
1302 long delayBeforeFinishingWorkMs = 0;
1303 if (ContextualSearchFieldTrial.getWaitAfterTapDelayMs() > 0 && tapTimeNa noseconds > 0) {
1304 delayBeforeFinishingWorkMs = ContextualSearchFieldTrial.getWaitAfter TapDelayMs()
1305 - (System.nanoTime() - tapTimeNanoseconds) / NANOSECONDS_IN_ A_MILLISECOND;
1306 }
1307
1308 // Finish work on the current state, either immediately or with a delay.
1309 if (delayBeforeFinishingWorkMs <= 0) {
1310 finishSuppressionDecision();
1311 } else {
1312 new Handler().postDelayed(new Runnable() {
1313 @Override
1314 public void run() {
1315 finishSuppressionDecision();
1316 }
1317 }, delayBeforeFinishingWorkMs);
1318 }
1319 }
1320
1321 /**
1322 * Finishes work on the suppression decision if that work is still in progre ss.
1323 * If no longer working on the suppression decision then resets the Ranker-l ogger.
1324 */
1325 private void finishSuppressionDecision() {
1326 if (mInternalStateController.isStillWorkingOn(InternalState.DECIDING_SUP PRESSION)) {
1327 mInternalStateController.notifyFinishedWorkOn(InternalState.DECIDING _SUPPRESSION);
1328 } else {
1329 mTapSuppressionRankerLogger.reset();
1330 }
1298 } 1331 }
1299 1332
1300 @Override 1333 @Override
1301 public void handleMetricsForWouldSuppressTap(ContextualSearchHeuristics tapH euristics) { 1334 public void handleMetricsForWouldSuppressTap(ContextualSearchHeuristics tapH euristics) {
1302 mHeuristics = tapHeuristics; 1335 mHeuristics = tapHeuristics;
1303 1336
1304 // TODO(donnd): QuickAnswersHeuristic is getting added to TapSuppression Heuristics and 1337 // TODO(donnd): QuickAnswersHeuristic is getting added to TapSuppression Heuristics and
1305 // and getting considered in TapSuppressionHeuristics#shouldSuppressTap( ). It should 1338 // and getting considered in TapSuppressionHeuristics#shouldSuppressTap( ). It should
1306 // be a part of ContextualSearchHeuristics for logging purposes but not for suppression. 1339 // be a part of ContextualSearchHeuristics for logging purposes but not for suppression.
1307 mQuickAnswersHeuristic = new QuickAnswersHeuristic(); 1340 mQuickAnswersHeuristic = new QuickAnswersHeuristic();
1308 mHeuristics.add(mQuickAnswersHeuristic); 1341 mHeuristics.add(mQuickAnswersHeuristic);
1309 1342
1310 mSearchPanel.getPanelMetrics().setResultsSeenExperiments(mHeuristics); 1343 mSearchPanel.getPanelMetrics().setResultsSeenExperiments(mHeuristics);
1311 mSearchPanel.getPanelMetrics().setRankerLogExperiments(mHeuristics, getB asePageUrl()); 1344 mSearchPanel.getPanelMetrics().setRankerLogger(mTapSuppressionRankerLogg er);
1312 } 1345 }
1313 1346
1314 @Override 1347 @Override
1315 public void handleValidTap() { 1348 public void handleValidTap() {
1316 if (mIsAccessibilityModeEnabled) return; 1349 if (mIsAccessibilityModeEnabled) return;
1317 1350
1318 mInternalStateController.enter(InternalState.TAP_RECOGNIZED); 1351 mInternalStateController.enter(InternalState.TAP_RECOGNIZED);
1319 } 1352 }
1320 1353
1321 /** 1354 /**
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 mNativeContextualSearchManagerPtr, mContext, webCont ents); 1468 mNativeContextualSearchManagerPtr, mContext, webCont ents);
1436 } else { 1469 } else {
1437 mInternalStateController.reset(StateChangeReason.UNKNOWN); 1470 mInternalStateController.reset(StateChangeReason.UNKNOWN);
1438 } 1471 }
1439 } 1472 }
1440 1473
1441 /** Starts the process of deciding if we'll suppress the current Tap gesture or not. */ 1474 /** Starts the process of deciding if we'll suppress the current Tap gesture or not. */
1442 @Override 1475 @Override
1443 public void decideSuppression() { 1476 public void decideSuppression() {
1444 mInternalStateController.notifyStartingWorkOn(InternalState.DECI DING_SUPPRESSION); 1477 mInternalStateController.notifyStartingWorkOn(InternalState.DECI DING_SUPPRESSION);
1445 mSelectionController.handleShouldSuppressTap(); 1478 // Ranker will handle the suppression, but our legacy implementa tion uses
1479 // TapSuppressionHeuristics (run from the ContextualSearchSelect ionConroller).
1480 // Usage includes tap-far-from-previous suppression.
1481 mTapSuppressionRankerLogger.setupLoggingForPage(getBasePageUrl() );
1482
1483 // TODO(donnd): Move handleShouldSuppressTap out of the Selectio n Controller.
1484 mSelectionController.handleShouldSuppressTap(mTapSuppressionRank erLogger);
1446 } 1485 }
1447 1486
1448 /** Starts showing the Tap UI by selecting a word around the current caret. */ 1487 /** Starts showing the Tap UI by selecting a word around the current caret. */
1449 @Override 1488 @Override
1450 public void startShowingTapUi() { 1489 public void startShowingTapUi() {
1451 WebContents baseWebContents = getBaseWebContents(); 1490 WebContents baseWebContents = getBaseWebContents();
1452 // TODO(donnd): Call isTapSupported earlier so we don't waste ti me gathering 1491 // TODO(donnd): Call isTapSupported earlier so we don't waste ti me gathering
1453 // surrounding text and deciding suppression when unsupported, o r remove the whole 1492 // surrounding text and deciding suppression when unsupported, o r remove the whole
1454 // idea of unsupported taps in favor of deciding suppression bet ter. 1493 // idea of unsupported taps in favor of deciding suppression bet ter.
1455 // Details in crbug.com/715297. 1494 // Details in crbug.com/715297.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager, 1635 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager,
1597 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); 1636 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents);
1598 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager, 1637 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager,
1599 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); 1638 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents);
1600 private native void nativeEnableContextualSearchJsApiForOverlay( 1639 private native void nativeEnableContextualSearchJsApiForOverlay(
1601 long nativeContextualSearchManager, WebContents overlayWebContents); 1640 long nativeContextualSearchManager, WebContents overlayWebContents);
1602 // Don't call these directly, instead call the private methods that cache th e results. 1641 // Don't call these directly, instead call the private methods that cache th e results.
1603 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager); 1642 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager);
1604 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager); 1643 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager);
1605 } 1644 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698