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;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CommandLine;
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.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider;
......@@ -82,9 +82,6 @@ import java.util.List;
public class LocationBarLayout extends FrameLayout
implements OnClickListener, LocationBar, AutocompleteDelegate, FakeboxDelegate,
VoiceRecognitionHandler.Delegate, AssistantVoiceSearchService.Observer {
private static final EnumeratedHistogramSample ENUMERATED_FOCUS_REASON =
new EnumeratedHistogramSample(
"Android.OmniboxFocusReason", OmniboxFocusReason.NUM_ENTRIES);
protected ImageButton mDeleteButton;
protected ImageButton mMicButton;
......@@ -1165,7 +1162,8 @@ public class LocationBarLayout extends FrameLayout
}
private void recordOmniboxFocusReason(@OmniboxFocusReason int reason) {
ENUMERATED_FOCUS_REASON.record(reason);
RecordHistogram.recordEnumeratedHistogram(
"Android.OmniboxFocusReason", reason, OmniboxFocusReason.NUM_ENTRIES);
}
@Override
......
......@@ -40,7 +40,7 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Log;
import org.chromium.base.SysUtils;
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.ui.KeyboardVisibilityDelegate;
......@@ -55,12 +55,12 @@ public abstract class UrlBar extends AutocompleteEditText {
private static final boolean DEBUG = false;
private static final CachedMetrics.ActionEvent ACTION_LONG_PRESS_COPY =
new CachedMetrics.ActionEvent("Omnibox.LongPress.Copy");
private static final CachedMetrics.ActionEvent ACTION_LONG_PRESS_CUT =
new CachedMetrics.ActionEvent("Omnibox.LongPress.Cut");
private static final CachedMetrics.ActionEvent ACTION_LONG_PRESS_SHARE =
new CachedMetrics.ActionEvent("Omnibox.LongPress.Share");
private static final ActionEvent ACTION_LONG_PRESS_COPY =
new ActionEvent("Omnibox.LongPress.Copy");
private static final ActionEvent ACTION_LONG_PRESS_CUT =
new ActionEvent("Omnibox.LongPress.Cut");
private static final ActionEvent ACTION_LONG_PRESS_SHARE =
new ActionEvent("Omnibox.LongPress.Share");
// TextView becomes very slow on long strings, so we limit maximum length
// of what is displayed to the user, see limitDisplayableLength().
......
......@@ -14,8 +14,8 @@ import android.view.ViewGroup;
import androidx.annotation.IntDef;
import org.chromium.base.metrics.CachedMetrics;
import org.chromium.base.metrics.CachedMetrics.EnumeratedHistogramSample;
import org.chromium.base.metrics.CachedMetrics.ActionEvent;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider;
......@@ -74,18 +74,14 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
int NUM_ENTRIES = 4;
}
/** Cached metrics in the event this code is triggered prior to native being initialized. */
private static final EnumeratedHistogramSample ENUMERATED_SUGGESTION_ACTION =
new EnumeratedHistogramSample(
"Omnibox.EditUrlSuggestionAction", SuggestionAction.NUM_ENTRIES);
private static final CachedMetrics.ActionEvent ACTION_EDIT_URL_SUGGESTION_TAP =
new CachedMetrics.ActionEvent("Omnibox.EditUrlSuggestion.Tap");
private static final CachedMetrics.ActionEvent ACTION_EDIT_URL_SUGGESTION_COPY =
new CachedMetrics.ActionEvent("Omnibox.EditUrlSuggestion.Copy");
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");
private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_TAP =
new ActionEvent("Omnibox.EditUrlSuggestion.Tap");
private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_COPY =
new ActionEvent("Omnibox.EditUrlSuggestion.Copy");
private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_EDIT =
new ActionEvent("Omnibox.EditUrlSuggestion.Edit");
private static final ActionEvent ACTION_EDIT_URL_SUGGESTION_SHARE =
new ActionEvent("Omnibox.EditUrlSuggestion.Share");
/** The delegate for accessing the location bar for observation and modification. */
private final LocationBarDelegate mLocationBarDelegate;
......@@ -238,11 +234,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
assert activityTab != null : "A tab is required to make changes to the location bar.";
if (R.id.url_copy_icon == view.getId()) {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.COPY);
recordSuggestionAction(SuggestionAction.COPY);
ACTION_EDIT_URL_SUGGESTION_COPY.record();
Clipboard.getInstance().copyUrlToClipboard(mLastProcessedSuggestion.getUrl());
} else if (R.id.url_share_icon == view.getId()) {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.SHARE);
recordSuggestionAction(SuggestionAction.SHARE);
ACTION_EDIT_URL_SUGGESTION_SHARE.record();
mLocationBarDelegate.clearOmniboxFocus();
// TODO(mdjones): This should only share the displayed URL instead of the background
......@@ -253,11 +249,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
.get()
.share(activityTab, false);
} else if (R.id.url_edit_icon == view.getId()) {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.EDIT);
recordSuggestionAction(SuggestionAction.EDIT);
ACTION_EDIT_URL_SUGGESTION_EDIT.record();
mLocationBarDelegate.setOmniboxEditingText(mLastProcessedSuggestion.getUrl());
} else {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.TAP);
recordSuggestionAction(SuggestionAction.TAP);
ACTION_EDIT_URL_SUGGESTION_TAP.record();
// If the event wasn't on any of the buttons, treat is as a tap on the general
// suggestion.
......@@ -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:
* 1. It's a search suggestion for the same search terms as the current SERP.
......
......@@ -16,7 +16,7 @@ import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting;
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.browser.omnibox.suggestions.AutocompleteCoordinator;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
......@@ -42,31 +42,6 @@ public class VoiceRecognitionHandler {
@VisibleForTesting
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 WebContentsObserver mVoiceSearchWebContentsObserver;
private AssistantVoiceSearchService mAssistantVoiceSearchService;
......@@ -444,7 +419,8 @@ public class VoiceRecognitionHandler {
*/
@VisibleForTesting
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 {
*/
@VisibleForTesting
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 {
*/
@VisibleForTesting
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 {
*/
@VisibleForTesting
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 {
*/
@VisibleForTesting
protected void recordVoiceSearchResult(boolean result) {
VOICE_SEARCH_RESULT_METRIC.record(result);
RecordHistogram.recordBooleanHistogram("VoiceInteraction.VoiceSearchResult", result);
}
/**
......@@ -494,7 +473,8 @@ public class VoiceRecognitionHandler {
@VisibleForTesting
protected void recordVoiceSearchConfidenceValue(float value) {
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