Commit b6d6ad8b authored by Troy Hildebrandt's avatar Troy Hildebrandt Committed by Commit Bot

Adds metrics recording for the source of voice interactions.

Right now we only record a metric on when a voice search is triggered
in the omnibox, and nowhere else. This patch records where the start of
a voice interaction comes from, and if completed successfully resulting
in either suggestions or a navigation to a SRP, the source of the finish
event as well. This currently includes omnibox, NTP, and the search
widget.

This also includes a minor refactoring, pulling voice search logic out
LocationBarLayout and into its own class,
LocationBarVoiceRecognitionHandler.

Bug: 817228
Change-Id: Ie0a97ecbbec92c9189e4454e67c94b18ca4c7ffe
Reviewed-on: https://chromium-review.googlesource.com/943598
Commit-Queue: Troy Hildebrandt <thildebr@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Reviewed-by: default avatarMaria Khomenko <mariakhomenko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547560}
parent e65dd61a
...@@ -30,6 +30,7 @@ import org.chromium.chrome.browser.download.DownloadManagerService; ...@@ -30,6 +30,7 @@ import org.chromium.chrome.browser.download.DownloadManagerService;
import org.chromium.chrome.browser.metrics.StartupMetrics; import org.chromium.chrome.browser.metrics.StartupMetrics;
import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
import org.chromium.chrome.browser.omnibox.LocationBarVoiceRecognitionHandler;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlService; import org.chromium.chrome.browser.search_engines.TemplateUrlService;
import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrlServiceObserver; import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
...@@ -85,6 +86,7 @@ public class NewTabPage ...@@ -85,6 +86,7 @@ public class NewTabPage
private boolean mSearchProviderHasLogo; private boolean mSearchProviderHasLogo;
private FakeboxDelegate mFakeboxDelegate; private FakeboxDelegate mFakeboxDelegate;
private LocationBarVoiceRecognitionHandler mVoiceRecognitionHandler;
// The timestamp at which the constructor was called. // The timestamp at which the constructor was called.
private final long mConstructedTimeNs; private final long mConstructedTimeNs;
...@@ -117,16 +119,6 @@ public class NewTabPage ...@@ -117,16 +119,6 @@ public class NewTabPage
* Handles user interaction with the fakebox (the URL bar in the NTP). * Handles user interaction with the fakebox (the URL bar in the NTP).
*/ */
public interface FakeboxDelegate { public interface FakeboxDelegate {
/**
* Shows the voice recognition dialog. Called when the user taps the microphone icon.
*/
void startVoiceRecognition();
/**
* @return Whether voice search is currently enabled.
*/
boolean isVoiceSearchEnabled();
/** /**
* @return Whether the URL bar is currently focused. * @return Whether the URL bar is currently focused.
*/ */
...@@ -192,19 +184,19 @@ public class NewTabPage ...@@ -192,19 +184,19 @@ public class NewTabPage
@Override @Override
public boolean isVoiceSearchEnabled() { public boolean isVoiceSearchEnabled() {
return mFakeboxDelegate != null && mFakeboxDelegate.isVoiceSearchEnabled(); return mVoiceRecognitionHandler != null
&& mVoiceRecognitionHandler.isVoiceSearchEnabled();
} }
@Override @Override
public void focusSearchBox(boolean beginVoiceSearch, String pastedText) { public void focusSearchBox(boolean beginVoiceSearch, String pastedText) {
if (mIsDestroyed) return; if (mIsDestroyed) return;
if (VrShellDelegate.isInVr()) return; if (VrShellDelegate.isInVr()) return;
if (mFakeboxDelegate != null) { if (mVoiceRecognitionHandler != null && beginVoiceSearch) {
if (beginVoiceSearch) { mVoiceRecognitionHandler.startVoiceRecognition(
mFakeboxDelegate.startVoiceRecognition(); LocationBarVoiceRecognitionHandler.VoiceInteractionSource.NTP);
} else { } else if (mFakeboxDelegate != null) {
mFakeboxDelegate.requestUrlFocusFromFakebox(pastedText); mFakeboxDelegate.requestUrlFocusFromFakebox(pastedText);
}
} }
} }
...@@ -445,8 +437,6 @@ public class NewTabPage ...@@ -445,8 +437,6 @@ public class NewTabPage
mFakeboxDelegate = fakeboxDelegate; mFakeboxDelegate = fakeboxDelegate;
mNewTabPageView.setFakeboxDelegate(fakeboxDelegate); mNewTabPageView.setFakeboxDelegate(fakeboxDelegate);
if (mFakeboxDelegate != null) { if (mFakeboxDelegate != null) {
mNewTabPageView.updateVoiceSearchButtonVisibility();
// The toolbar can't get the reference to the native page until its initialization is // The toolbar can't get the reference to the native page until its initialization is
// finished, so we can't cache it here and transfer it to the view later. We pull that // finished, so we can't cache it here and transfer it to the view later. We pull that
// state from the location bar when we get a reference to it as a workaround. // state from the location bar when we get a reference to it as a workaround.
...@@ -455,6 +445,17 @@ public class NewTabPage ...@@ -455,6 +445,17 @@ public class NewTabPage
} }
} }
/**
* Sets the {@link LocationBarVoiceRecognitionHandler} this page interacts with.
*/
public void setVoiceRecognitionHandler(
LocationBarVoiceRecognitionHandler voiceRecognitionHandler) {
mVoiceRecognitionHandler = voiceRecognitionHandler;
if (mVoiceRecognitionHandler != null) {
mNewTabPageView.updateVoiceSearchButtonVisibility();
}
}
/** /**
* Records UMA for the NTP being shown. This includes a fresh page load or being brought to the * Records UMA for the NTP being shown. This includes a fresh page load or being brought to the
* foreground. * foreground.
......
...@@ -585,8 +585,8 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -585,8 +585,8 @@ public class LocationBarTablet extends LocationBarLayout {
private boolean shouldShowMicButton() { private boolean shouldShowMicButton() {
// If the download UI is enabled, the mic button should be only be shown when the url bar // If the download UI is enabled, the mic button should be only be shown when the url bar
// is focused. // is focused.
return isVoiceSearchEnabled() && mNativeInitialized return mVoiceRecognitionHandler != null && mVoiceRecognitionHandler.isVoiceSearchEnabled()
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress); && mNativeInitialized && (mUrlBar.hasFocus() || mUrlFocusChangeInProgress);
} }
@Override @Override
......
...@@ -14,6 +14,7 @@ import org.chromium.chrome.R; ...@@ -14,6 +14,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.WindowDelegate; import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.locale.LocaleManager; import org.chromium.chrome.browser.locale.LocaleManager;
import org.chromium.chrome.browser.omnibox.LocationBarLayout; import org.chromium.chrome.browser.omnibox.LocationBarLayout;
import org.chromium.chrome.browser.omnibox.LocationBarVoiceRecognitionHandler;
import org.chromium.chrome.browser.omnibox.OmniboxSuggestion; import org.chromium.chrome.browser.omnibox.OmniboxSuggestion;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.ui.UiUtils; import org.chromium.ui.UiUtils;
...@@ -91,7 +92,10 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout { ...@@ -91,7 +92,10 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
/** Called when the SearchActivity has finished initialization. */ /** Called when the SearchActivity has finished initialization. */
void onDeferredStartup(boolean isVoiceSearchIntent) { void onDeferredStartup(boolean isVoiceSearchIntent) {
SearchWidgetProvider.updateCachedVoiceSearchAvailability(isVoiceSearchEnabled()); if (mVoiceRecognitionHandler != null) {
SearchWidgetProvider.updateCachedVoiceSearchAvailability(
mVoiceRecognitionHandler.isVoiceSearchEnabled());
}
if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true); if (isVoiceSearchIntent && mUrlBar.isFocused()) onUrlFocusChange(true);
if (!TextUtils.isEmpty(mUrlBar.getText())) onTextChangedForAutocomplete(); if (!TextUtils.isEmpty(mUrlBar.getText())) onTextChangedForAutocomplete();
...@@ -131,8 +135,10 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout { ...@@ -131,8 +135,10 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
private void beginQueryInternal(boolean isVoiceSearchIntent) { private void beginQueryInternal(boolean isVoiceSearchIntent) {
assert !mPendingSearchPromoDecision; assert !mPendingSearchPromoDecision;
if (isVoiceSearchEnabled() && isVoiceSearchIntent) { if (mVoiceRecognitionHandler != null && mVoiceRecognitionHandler.isVoiceSearchEnabled()
startVoiceRecognition(); && isVoiceSearchIntent) {
mVoiceRecognitionHandler.startVoiceRecognition(
LocationBarVoiceRecognitionHandler.VoiceInteractionSource.SEARCH_WIDGET);
} else { } else {
focusTextBox(); focusTextBox();
} }
......
...@@ -822,6 +822,7 @@ chrome_java_sources = [ ...@@ -822,6 +822,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java", "java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java", "java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarTablet.java", "java/src/org/chromium/chrome/browser/omnibox/LocationBarTablet.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarVoiceRecognitionHandler.java",
"java/src/org/chromium/chrome/browser/omnibox/OmniboxPrerender.java", "java/src/org/chromium/chrome/browser/omnibox/OmniboxPrerender.java",
"java/src/org/chromium/chrome/browser/omnibox/OmniboxResultsAdapter.java", "java/src/org/chromium/chrome/browser/omnibox/OmniboxResultsAdapter.java",
"java/src/org/chromium/chrome/browser/omnibox/OmniboxSuggestion.java", "java/src/org/chromium/chrome/browser/omnibox/OmniboxSuggestion.java",
...@@ -1702,6 +1703,7 @@ chrome_test_java_sources = [ ...@@ -1702,6 +1703,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/omaha/StringSanitizerTest.java", "javatests/src/org/chromium/chrome/browser/omaha/StringSanitizerTest.java",
"javatests/src/org/chromium/chrome/browser/omaha/UpdateMenuItemHelperTest.java", "javatests/src/org/chromium/chrome/browser/omaha/UpdateMenuItemHelperTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/LocationBarLayoutTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/LocationBarLayoutTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/LocationBarVoiceRecognitionHandlerTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/OmniboxTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/OmniboxTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/OmniboxUrlEmphasizerTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/OmniboxUrlEmphasizerTest.java",
"javatests/src/org/chromium/chrome/browser/omnibox/SuggestionAnswerTest.java", "javatests/src/org/chromium/chrome/browser/omnibox/SuggestionAnswerTest.java",
......
...@@ -45745,6 +45745,12 @@ Full version information for the fingerprint enum values: ...@@ -45745,6 +45745,12 @@ Full version information for the fingerprint enum values:
<int value="1" label="Chrome Tab"/> <int value="1" label="Chrome Tab"/>
</enum> </enum>
<enum name="VoiceInteractionEventSource">
<int value="0" label="Omnibox"/>
<int value="1" label="NTP"/>
<int value="2" label="Search widget"/>
</enum>
<enum name="VPNDriver"> <enum name="VPNDriver">
<int value="0" label="OpenVPN"/> <int value="0" label="OpenVPN"/>
<int value="1" label="L2TP/IPSec"/> <int value="1" label="L2TP/IPSec"/>
...@@ -99122,6 +99122,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -99122,6 +99122,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="VoiceInteraction.FinishEventSource"
enum="VoiceInteractionEventSource">
<owner>thildebr@chromium.org</owner>
<summary>
Android: The source of a successful voice search, such as omnibox or NTP.
</summary>
</histogram>
<histogram name="VoiceInteraction.IllegalContextRequest" enum="BooleanHit"> <histogram name="VoiceInteraction.IllegalContextRequest" enum="BooleanHit">
<owner>muyuanli@chromium.org</owner> <owner>muyuanli@chromium.org</owner>
<summary> <summary>
...@@ -99137,6 +99145,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -99137,6 +99145,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="VoiceInteraction.StartEventSource"
enum="VoiceInteractionEventSource">
<owner>thildebr@chromium.org</owner>
<summary>
Android: The source of a voice search start event, such as omnibox or NTP.
</summary>
</histogram>
<histogram name="VoiceInteraction.UserInteractionToRequestArrival" units="ms"> <histogram name="VoiceInteraction.UserInteractionToRequestArrival" units="ms">
<owner>muyuanli@chromium.org</owner> <owner>muyuanli@chromium.org</owner>
<summary> <summary>
...@@ -99144,6 +99160,19 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -99144,6 +99160,19 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="VoiceInteraction.VoiceResultConfidenceValue" units="%">
<owner>thildebr@chromium.org</owner>
<summary>
Android: Records the confidence value of a successful voice search as a
percentage.
</summary>
</histogram>
<histogram name="VoiceInteraction.VoiceSearchResult" enum="BooleanSuccess">
<owner>thildebr@chromium.org</owner>
<summary>Android: Records whether the voice search produced results.</summary>
</histogram>
<histogram name="VR.Component.Assets.DurationUntilReady.OnChromeStart" <histogram name="VR.Component.Assets.DurationUntilReady.OnChromeStart"
units="ms"> units="ms">
<obsolete> <obsolete>
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