Commit b5128bb5 authored by bttk's avatar bttk Committed by Commit Bot

metrics: Refactor CachedMetrics in omnibox

Bug: 1046181
Change-Id: Ia7c2b1f98569c95d8ded7ec030d7936eddbd8f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2024413
Auto-Submit: bttk <bttk@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarEnder <ender@google.com>
Commit-Queue: bttk <bttk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742418}
parent 8dd06452
...@@ -30,7 +30,7 @@ import androidx.annotation.VisibleForTesting; ...@@ -30,7 +30,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider; import org.chromium.chrome.browser.ActivityTabProvider;
...@@ -82,9 +82,6 @@ import java.util.List; ...@@ -82,9 +82,6 @@ import java.util.List;
public class LocationBarLayout extends FrameLayout public class LocationBarLayout extends FrameLayout
implements OnClickListener, LocationBar, AutocompleteDelegate, FakeboxDelegate, implements OnClickListener, LocationBar, AutocompleteDelegate, FakeboxDelegate,
VoiceRecognitionHandler.Delegate, AssistantVoiceSearchService.Observer { VoiceRecognitionHandler.Delegate, AssistantVoiceSearchService.Observer {
private static final EnumeratedHistogramSample ENUMERATED_FOCUS_REASON =
new EnumeratedHistogramSample(
"Android.OmniboxFocusReason", OmniboxFocusReason.NUM_ENTRIES);
protected ImageButton mDeleteButton; protected ImageButton mDeleteButton;
protected ImageButton mMicButton; protected ImageButton mMicButton;
...@@ -1165,7 +1162,8 @@ public class LocationBarLayout extends FrameLayout ...@@ -1165,7 +1162,8 @@ public class LocationBarLayout extends FrameLayout
} }
private void recordOmniboxFocusReason(@OmniboxFocusReason int reason) { private void recordOmniboxFocusReason(@OmniboxFocusReason int reason) {
ENUMERATED_FOCUS_REASON.record(reason); RecordHistogram.recordEnumeratedHistogram(
"Android.OmniboxFocusReason", reason, OmniboxFocusReason.NUM_ENTRIES);
} }
@Override @Override
......
...@@ -40,7 +40,7 @@ import org.chromium.base.ApiCompatibilityUtils; ...@@ -40,7 +40,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.SysUtils; import org.chromium.base.SysUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.CachedMetrics; import org.chromium.base.metrics.CachedMetrics.ActionEvent;
import org.chromium.chrome.browser.WindowDelegate; import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.ui.KeyboardVisibilityDelegate; import org.chromium.ui.KeyboardVisibilityDelegate;
...@@ -55,12 +55,12 @@ public abstract class UrlBar extends AutocompleteEditText { ...@@ -55,12 +55,12 @@ public abstract class UrlBar extends AutocompleteEditText {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private static final CachedMetrics.ActionEvent ACTION_LONG_PRESS_COPY = private static final ActionEvent ACTION_LONG_PRESS_COPY =
new CachedMetrics.ActionEvent("Omnibox.LongPress.Copy"); new ActionEvent("Omnibox.LongPress.Copy");
private static final CachedMetrics.ActionEvent ACTION_LONG_PRESS_CUT = private static final ActionEvent ACTION_LONG_PRESS_CUT =
new CachedMetrics.ActionEvent("Omnibox.LongPress.Cut"); new ActionEvent("Omnibox.LongPress.Cut");
private static final CachedMetrics.ActionEvent ACTION_LONG_PRESS_SHARE = private static final ActionEvent ACTION_LONG_PRESS_SHARE =
new CachedMetrics.ActionEvent("Omnibox.LongPress.Share"); new ActionEvent("Omnibox.LongPress.Share");
// TextView becomes very slow on long strings, so we limit maximum length // TextView becomes very slow on long strings, so we limit maximum length
// of what is displayed to the user, see limitDisplayableLength(). // of what is displayed to the user, see limitDisplayableLength().
......
...@@ -14,8 +14,8 @@ import android.view.ViewGroup; ...@@ -14,8 +14,8 @@ import android.view.ViewGroup;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import org.chromium.base.metrics.CachedMetrics; import org.chromium.base.metrics.CachedMetrics.ActionEvent;
import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider; import org.chromium.chrome.browser.ActivityTabProvider;
...@@ -74,18 +74,14 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr ...@@ -74,18 +74,14 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
int NUM_ENTRIES = 4; int NUM_ENTRIES = 4;
} }
/** Cached metrics in the event this code is triggered prior to native being initialized. */ private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_TAP =
private static final EnumeratedHistogramSample ENUMERATED_SUGGESTION_ACTION = new ActionEvent("Omnibox.EditUrlSuggestion.Tap");
new EnumeratedHistogramSample( private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_COPY =
"Omnibox.EditUrlSuggestionAction", SuggestionAction.NUM_ENTRIES); new ActionEvent("Omnibox.EditUrlSuggestion.Copy");
private static final CachedMetrics.ActionEvent ACTION_EDIT_URL_SUGGESTION_TAP = private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_EDIT =
new CachedMetrics.ActionEvent("Omnibox.EditUrlSuggestion.Tap"); new ActionEvent("Omnibox.EditUrlSuggestion.Edit");
private static final CachedMetrics.ActionEvent ACTION_EDIT_URL_SUGGESTION_COPY = private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_SHARE =
new CachedMetrics.ActionEvent("Omnibox.EditUrlSuggestion.Copy"); new ActionEvent("Omnibox.EditUrlSuggestion.Share");
private static final CachedMetrics.ActionEvent ACTION_EDIT_URL_SUGGESTION_EDIT =
new CachedMetrics.ActionEvent("Omnibox.EditUrlSuggestion.Edit");
private static final CachedMetrics.ActionEvent ACTION_EDIT_URL_SUGGESTION_SHARE =
new CachedMetrics.ActionEvent("Omnibox.EditUrlSuggestion.Share");
/** The delegate for accessing the location bar for observation and modification. */ /** The delegate for accessing the location bar for observation and modification. */
private final LocationBarDelegate mLocationBarDelegate; private final LocationBarDelegate mLocationBarDelegate;
...@@ -238,11 +234,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr ...@@ -238,11 +234,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
assert activityTab != null : "A tab is required to make changes to the location bar."; assert activityTab != null : "A tab is required to make changes to the location bar.";
if (R.id.url_copy_icon == view.getId()) { if (R.id.url_copy_icon == view.getId()) {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.COPY); recordSuggestionAction(SuggestionAction.COPY);
ACTION_EDIT_URL_SUGGESTION_COPY.record(); ACTION_EDIT_URL_SUGGESTION_COPY.record();
Clipboard.getInstance().copyUrlToClipboard(mLastProcessedSuggestion.getUrl()); Clipboard.getInstance().copyUrlToClipboard(mLastProcessedSuggestion.getUrl());
} else if (R.id.url_share_icon == view.getId()) { } else if (R.id.url_share_icon == view.getId()) {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.SHARE); recordSuggestionAction(SuggestionAction.SHARE);
ACTION_EDIT_URL_SUGGESTION_SHARE.record(); ACTION_EDIT_URL_SUGGESTION_SHARE.record();
mLocationBarDelegate.clearOmniboxFocus(); mLocationBarDelegate.clearOmniboxFocus();
// TODO(mdjones): This should only share the displayed URL instead of the background // TODO(mdjones): This should only share the displayed URL instead of the background
...@@ -253,11 +249,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr ...@@ -253,11 +249,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
.get() .get()
.share(activityTab, false); .share(activityTab, false);
} else if (R.id.url_edit_icon == view.getId()) { } else if (R.id.url_edit_icon == view.getId()) {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.EDIT); recordSuggestionAction(SuggestionAction.EDIT);
ACTION_EDIT_URL_SUGGESTION_EDIT.record(); ACTION_EDIT_URL_SUGGESTION_EDIT.record();
mLocationBarDelegate.setOmniboxEditingText(mLastProcessedSuggestion.getUrl()); mLocationBarDelegate.setOmniboxEditingText(mLastProcessedSuggestion.getUrl());
} else { } else {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.TAP); recordSuggestionAction(SuggestionAction.TAP);
ACTION_EDIT_URL_SUGGESTION_TAP.record(); ACTION_EDIT_URL_SUGGESTION_TAP.record();
// If the event wasn't on any of the buttons, treat is as a tap on the general // If the event wasn't on any of the buttons, treat is as a tap on the general
// suggestion. // suggestion.
...@@ -267,6 +263,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr ...@@ -267,6 +263,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
} }
} }
private void recordSuggestionAction(@SuggestionAction int action) {
RecordHistogram.recordEnumeratedHistogram(
"Omnibox.EditUrlSuggestionAction", action, SuggestionAction.NUM_ENTRIES);
}
/** /**
* @return true if the suggestion is effectively the same as the current page, either because: * @return true if the suggestion is effectively the same as the current page, either because:
* 1. It's a search suggestion for the same search terms as the current SERP. * 1. It's a search suggestion for the same search terms as the current SERP.
......
...@@ -16,7 +16,7 @@ import androidx.annotation.IntDef; ...@@ -16,7 +16,7 @@ import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.CachedMetrics; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.omnibox.suggestions.AutocompleteCoordinator; import org.chromium.chrome.browser.omnibox.suggestions.AutocompleteCoordinator;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory; import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
...@@ -42,31 +42,6 @@ public class VoiceRecognitionHandler { ...@@ -42,31 +42,6 @@ public class VoiceRecognitionHandler {
@VisibleForTesting @VisibleForTesting
public static final float VOICE_SEARCH_CONFIDENCE_NAVIGATE_THRESHOLD = 0.9f; public static final float VOICE_SEARCH_CONFIDENCE_NAVIGATE_THRESHOLD = 0.9f;
private static final CachedMetrics
.EnumeratedHistogramSample VOICE_INTERACTION_START_SOURCE_METRIC =
new CachedMetrics.EnumeratedHistogramSample(
"VoiceInteraction.StartEventSource", VoiceInteractionSource.HISTOGRAM_BOUNDARY);
private static final CachedMetrics
.EnumeratedHistogramSample VOICE_INTERACTION_FINISH_SOURCE_METRIC =
new CachedMetrics.EnumeratedHistogramSample("VoiceInteraction.FinishEventSource",
VoiceInteractionSource.HISTOGRAM_BOUNDARY);
private static final CachedMetrics
.EnumeratedHistogramSample VOICE_INTERACTION_DISMISSED_SOURCE_METRIC =
new CachedMetrics.EnumeratedHistogramSample("VoiceInteraction.DismissedEventSource",
VoiceInteractionSource.HISTOGRAM_BOUNDARY);
private static final CachedMetrics
.EnumeratedHistogramSample VOICE_INTERACTION_FAILURE_SOURCE_METRIC =
new CachedMetrics.EnumeratedHistogramSample("VoiceInteraction.FailureEventSource",
VoiceInteractionSource.HISTOGRAM_BOUNDARY);
private static final CachedMetrics.BooleanHistogramSample VOICE_SEARCH_RESULT_METRIC =
new CachedMetrics.BooleanHistogramSample("VoiceInteraction.VoiceSearchResult");
// There's no percentage histogram sample in CachedMetrics, so we mimic what that does
// internally.
private static final CachedMetrics
.EnumeratedHistogramSample VOICE_SEARCH_CONFIDENCE_VALUE_METRIC =
new CachedMetrics.EnumeratedHistogramSample(
"VoiceInteraction.VoiceResultConfidenceValue", 101);
private final Delegate mDelegate; private final Delegate mDelegate;
private WebContentsObserver mVoiceSearchWebContentsObserver; private WebContentsObserver mVoiceSearchWebContentsObserver;
private AssistantVoiceSearchService mAssistantVoiceSearchService; private AssistantVoiceSearchService mAssistantVoiceSearchService;
...@@ -444,7 +419,8 @@ public class VoiceRecognitionHandler { ...@@ -444,7 +419,8 @@ public class VoiceRecognitionHandler {
*/ */
@VisibleForTesting @VisibleForTesting
protected void recordVoiceSearchStartEventSource(@VoiceInteractionSource int source) { protected void recordVoiceSearchStartEventSource(@VoiceInteractionSource int source) {
VOICE_INTERACTION_START_SOURCE_METRIC.record(source); RecordHistogram.recordEnumeratedHistogram("VoiceInteraction.StartEventSource", source,
VoiceInteractionSource.HISTOGRAM_BOUNDARY);
} }
/** /**
...@@ -454,7 +430,8 @@ public class VoiceRecognitionHandler { ...@@ -454,7 +430,8 @@ public class VoiceRecognitionHandler {
*/ */
@VisibleForTesting @VisibleForTesting
protected void recordVoiceSearchFinishEventSource(@VoiceInteractionSource int source) { protected void recordVoiceSearchFinishEventSource(@VoiceInteractionSource int source) {
VOICE_INTERACTION_FINISH_SOURCE_METRIC.record(source); RecordHistogram.recordEnumeratedHistogram("VoiceInteraction.FinishEventSource", source,
VoiceInteractionSource.HISTOGRAM_BOUNDARY);
} }
/** /**
...@@ -464,7 +441,8 @@ public class VoiceRecognitionHandler { ...@@ -464,7 +441,8 @@ public class VoiceRecognitionHandler {
*/ */
@VisibleForTesting @VisibleForTesting
protected void recordVoiceSearchDismissedEventSource(@VoiceInteractionSource int source) { protected void recordVoiceSearchDismissedEventSource(@VoiceInteractionSource int source) {
VOICE_INTERACTION_DISMISSED_SOURCE_METRIC.record(source); RecordHistogram.recordEnumeratedHistogram("VoiceInteraction.DismissedEventSource", source,
VoiceInteractionSource.HISTOGRAM_BOUNDARY);
} }
/** /**
...@@ -474,7 +452,8 @@ public class VoiceRecognitionHandler { ...@@ -474,7 +452,8 @@ public class VoiceRecognitionHandler {
*/ */
@VisibleForTesting @VisibleForTesting
protected void recordVoiceSearchFailureEventSource(@VoiceInteractionSource int source) { protected void recordVoiceSearchFailureEventSource(@VoiceInteractionSource int source) {
VOICE_INTERACTION_FAILURE_SOURCE_METRIC.record(source); RecordHistogram.recordEnumeratedHistogram("VoiceInteraction.FailureEventSource", source,
VoiceInteractionSource.HISTOGRAM_BOUNDARY);
} }
/** /**
...@@ -483,7 +462,7 @@ public class VoiceRecognitionHandler { ...@@ -483,7 +462,7 @@ public class VoiceRecognitionHandler {
*/ */
@VisibleForTesting @VisibleForTesting
protected void recordVoiceSearchResult(boolean result) { protected void recordVoiceSearchResult(boolean result) {
VOICE_SEARCH_RESULT_METRIC.record(result); RecordHistogram.recordBooleanHistogram("VoiceInteraction.VoiceSearchResult", result);
} }
/** /**
...@@ -494,7 +473,8 @@ public class VoiceRecognitionHandler { ...@@ -494,7 +473,8 @@ public class VoiceRecognitionHandler {
@VisibleForTesting @VisibleForTesting
protected void recordVoiceSearchConfidenceValue(float value) { protected void recordVoiceSearchConfidenceValue(float value) {
int percentage = Math.round(value * 100f); int percentage = Math.round(value * 100f);
VOICE_SEARCH_CONFIDENCE_VALUE_METRIC.record(percentage); RecordHistogram.recordPercentageHistogram(
"VoiceInteraction.VoiceResultConfidenceValue", percentage);
} }
/** /**
......
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