OLD | NEW |
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.text.TextUtils; | 7 import android.text.TextUtils; |
8 | 8 |
9 import org.chromium.base.VisibleForTesting; | 9 import org.chromium.base.VisibleForTesting; |
10 import org.chromium.chrome.browser.ChromeActivity; | 10 import org.chromium.chrome.browser.ChromeActivity; |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 mLastTapState = null; | 344 mLastTapState = null; |
345 mHandler.handleInvalidTap(); | 345 mHandler.handleInvalidTap(); |
346 } | 346 } |
347 } | 347 } |
348 | 348 |
349 /** | 349 /** |
350 * Handles Tap suppression by making a callback to either the handler's #han
dleSuppressedTap() | 350 * Handles Tap suppression by making a callback to either the handler's #han
dleSuppressedTap() |
351 * or #handleNonSuppressedTap() after a possible delay. | 351 * or #handleNonSuppressedTap() after a possible delay. |
352 * This should be called when the context is fully built (by gathering surro
unding text | 352 * This should be called when the context is fully built (by gathering surro
unding text |
353 * if needed, etc) but before showing any UX. | 353 * if needed, etc) but before showing any UX. |
| 354 * @param rankerLogger The {@link ContextualSearchRankerLogger} currently be
ing used to measure |
| 355 * or suppress the UI by Ranker. |
354 */ | 356 */ |
355 void handleShouldSuppressTap() { | 357 void handleShouldSuppressTap(ContextualSearchRankerLogger rankerLogger) { |
356 int x = (int) mX; | 358 int x = (int) mX; |
357 int y = (int) mY; | 359 int y = (int) mY; |
358 | 360 |
359 // TODO(donnd): add a policy method to get adjusted tap count. | 361 // TODO(donnd): add a policy method to get adjusted tap count. |
360 ChromePreferenceManager prefs = ChromePreferenceManager.getInstance(); | 362 ChromePreferenceManager prefs = ChromePreferenceManager.getInstance(); |
361 int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount() | 363 int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount() |
362 - prefs.getContextualSearchTapQuickAnswerCount(); | 364 - prefs.getContextualSearchTapQuickAnswerCount(); |
363 TapSuppressionHeuristics tapHeuristics = | 365 TapSuppressionHeuristics tapHeuristics = |
364 new TapSuppressionHeuristics(this, mLastTapState, x, y, adjusted
TapsSinceOpen); | 366 new TapSuppressionHeuristics(this, mLastTapState, x, y, adjusted
TapsSinceOpen); |
| 367 |
365 // TODO(donnd): Move to be called when the panel closes to work with sta
tes that change. | 368 // TODO(donnd): Move to be called when the panel closes to work with sta
tes that change. |
366 tapHeuristics.logConditionState(); | 369 tapHeuristics.logConditionState(); |
| 370 |
| 371 tapHeuristics.logRankerTapSuppression(rankerLogger); |
367 // Tell the manager what it needs in order to log metrics on whether the
tap would have | 372 // Tell the manager what it needs in order to log metrics on whether the
tap would have |
368 // been suppressed if each of the heuristics were satisfied. | 373 // been suppressed if each of the heuristics were satisfied. |
369 mHandler.handleMetricsForWouldSuppressTap(tapHeuristics); | 374 mHandler.handleMetricsForWouldSuppressTap(tapHeuristics); |
370 | 375 |
371 boolean shouldSuppressTap = tapHeuristics.shouldSuppressTap(); | 376 boolean shouldSuppressTapBasedOnHeuristics = tapHeuristics.shouldSuppres
sTap(); |
372 if (mTapTimeNanoseconds != 0) { | 377 if (mTapTimeNanoseconds != 0) { |
373 // Remember the tap state for subsequent tap evaluation. | 378 // Remember the tap state for subsequent tap evaluation. |
374 mLastTapState = | 379 mLastTapState = new ContextualSearchTapState( |
375 new ContextualSearchTapState(x, y, mTapTimeNanoseconds, shou
ldSuppressTap); | 380 x, y, mTapTimeNanoseconds, shouldSuppressTapBasedOnHeuristic
s); |
376 } else { | 381 } else { |
377 mLastTapState = null; | 382 mLastTapState = null; |
378 } | 383 } |
379 | 384 |
380 if (shouldSuppressTap) { | 385 boolean shouldSuppressTapBasedOnRanker = rankerLogger.inferUiSuppression
(); |
| 386 if (shouldSuppressTapBasedOnHeuristics || shouldSuppressTapBasedOnRanker
) { |
381 mHandler.handleSuppressedTap(); | 387 mHandler.handleSuppressedTap(); |
382 } else { | 388 } else { |
383 mHandler.handleNonSuppressedTap(); | 389 mHandler.handleNonSuppressedTap(mTapTimeNanoseconds); |
384 } | 390 } |
385 } | 391 } |
386 | 392 |
387 /** | 393 /** |
388 * Gets the base page ContentViewCore. | 394 * Gets the base page ContentViewCore. |
389 * Deprecated, use getBaseWebContents instead. | 395 * Deprecated, use getBaseWebContents instead. |
390 * @return The Base Page's {@link ContentViewCore}, or {@code null} if there
is no current tab. | 396 * @return The Base Page's {@link ContentViewCore}, or {@code null} if there
is no current tab. |
391 */ | 397 */ |
392 @Deprecated | 398 @Deprecated |
393 ContentViewCore getBaseContentView() { | 399 ContentViewCore getBaseContentView() { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 // Starts are inclusive and ends are non-inclusive for both GSAContext &
matcher. | 558 // Starts are inclusive and ends are non-inclusive for both GSAContext &
matcher. |
553 while (matcher.find()) { | 559 while (matcher.find()) { |
554 if (startOffset >= matcher.start() && endOffset <= matcher.end()) { | 560 if (startOffset >= matcher.start() && endOffset <= matcher.end()) { |
555 return true; | 561 return true; |
556 } | 562 } |
557 } | 563 } |
558 | 564 |
559 return false; | 565 return false; |
560 } | 566 } |
561 } | 567 } |
OLD | NEW |