Commit 210d15f8 authored by donnd's avatar donnd Committed by Commit bot
Browse files

[TTS] Update Tap counters to compensate for Quick Answers.

When a Tap causes a Quick Answer that shows a caption with doesAnswer,
the user has no real need to open the panel.

This change counts Answers since the last open and uses them to compensate
for Taps without any panel open so we don't stop resolving and preloading
(which would cause subsequent Quick Answers to not appear automatically).

BUG=622160,609924

Review-Url: https://codereview.chromium.org/2099753003
Cr-Commit-Position: refs/heads/master@{#402351}
parent a66e015b
......@@ -751,6 +751,9 @@ public class ContextualSearchManager implements ContextualSearchManagementDelega
mQuickAnswersHeuristic.setConditionSatisfied(true);
mQuickAnswersHeuristic.setDoesAnswer(doesAnswer);
}
// Update Tap counters to account for a possible answer.
mPolicy.updateCountersForQuickAnswer(mWasActivatedByTap, doesAnswer);
}
/**
......
......@@ -259,6 +259,7 @@ class ContextualSearchPolicy {
// Always completely reset the tap counter, since it just counts taps
// since the last open.
mPreferenceManager.setContextualSearchTapCount(0);
mPreferenceManager.setContextualSearchTapQuickAnswerCount(0);
// Disable the "promo tap" counter, but only if we're using the Opt-out onboarding.
// For Opt-in, we never disable the promo tap counter.
......@@ -272,6 +273,20 @@ class ContextualSearchPolicy {
}
}
/**
* Updates Tap counters to account for a quick-answer caption shown on the panel.
* @param wasActivatedByTap Whether the triggering gesture was a Tap or not.
* @param doesAnswer Whether the caption is considered an answer rather than just
* informative.
*/
void updateCountersForQuickAnswer(boolean wasActivatedByTap, boolean doesAnswer) {
if (wasActivatedByTap && doesAnswer) {
int tapsWithAnswerSinceOpen =
mPreferenceManager.getContextualSearchTapQuickAnswerCount();
mPreferenceManager.setContextualSearchTapQuickAnswerCount(++tapsWithAnswerSinceOpen);
}
}
/**
* @return Whether a verbatim request should be made for the given base page, assuming there
* is no exiting request.
......@@ -527,7 +542,9 @@ class ContextualSearchPolicy {
* @return Whether the tap resolve/prefetch limit has been exceeded.
*/
private boolean isTapBeyondTheLimit() {
return getTapCount() > getTapLimit();
// Discount taps that caused a Quick Answer since the tap may not have been totally ignored.
return getTapCount() - mPreferenceManager.getContextualSearchTapQuickAnswerCount()
> getTapLimit();
}
/**
......
......@@ -36,6 +36,8 @@ public class ChromePreferenceManager {
"contextual_search_peek_promo_show_count";
private static final String CONTEXTUAL_SEARCH_LAST_ANIMATION_TIME =
"contextual_search_last_animation_time";
private static final String CONTEXTUAL_SEARCH_TAP_QUICK_ANSWER_COUNT =
"contextual_search_tap_quick_answer_count";
private static final String HERB_FLAVOR_KEY = "herb_flavor";
private static final String APP_LINK_KEY = "applink.app_link_enabled";
private static final String CHROME_DEFAULT_BROWSER = "applink.chrome_default_browser";
......@@ -268,20 +270,40 @@ public class ChromePreferenceManager {
}
/**
* @return Number of tap gestures that have been received when not waiting for the promo.
* @return Number of tap gestures that have been received since the last time the panel was
* opened.
*/
public int getContextualSearchTapCount() {
return mSharedPreferences.getInt(CONTEXTUAL_SEARCH_TAP_COUNT, 0);
}
/**
* Sets the number of tap gestures that have been received when not waiting for the promo.
* @param count Number of taps that have been received when not waiting for the promo.
* Sets the number of tap gestures that have been received since the last time the panel was
* opened.
* @param count Number of taps that have been received since the last time the panel was opened.
*/
public void setContextualSearchTapCount(int count) {
writeInt(CONTEXTUAL_SEARCH_TAP_COUNT, count);
}
/**
* @return Number of Tap triggered Quick Answers (that "do answer") that have been shown since
* the last time the panel was opened.
*/
public int getContextualSearchTapQuickAnswerCount() {
return mSharedPreferences.getInt(CONTEXTUAL_SEARCH_TAP_QUICK_ANSWER_COUNT, 0);
}
/**
* Sets the number of tap triggered Quick Answers (that "do answer") that have been shown since
* the last time the panel was opened.
* @param count Number of Tap triggered Quick Answers (that "do answer") that have been shown
* since the last time the panel was opened.
*/
public void setContextualSearchTapQuickAnswerCount(int count) {
writeInt(CONTEXTUAL_SEARCH_TAP_QUICK_ANSWER_COUNT, count);
}
/**
* @return Which UI prototype the user is testing. This is cached from native via
* {@link FeatureUtilities#cacheHerbFlavor}.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment