Commit 197818c8 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

[WebView Autofill] add metric for suggestion time and context

Bug: 839646
Change-Id: Ibfeee6aefedcc4c46b432d1f2df02089d521d214
Reviewed-on: https://chromium-review.googlesource.com/1065204Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561741}
parent df5f9465
......@@ -218,21 +218,26 @@ public class AwAutofillProvider extends AutofillProvider {
private long mNativeAutofillProvider;
private AwAutofillUMA mAutofillUMA;
private AwAutofillManager.InputUIObserver mInputUIObserver;
private long mAutofillTriggeredTimeMillis;
public AwAutofillProvider(Context context, ViewGroup containerView) {
this(containerView, new AwAutofillManager(context));
this(containerView, new AwAutofillManager(context), context);
}
@VisibleForTesting
public AwAutofillProvider(ViewGroup containerView, AwAutofillManager manager) {
public AwAutofillProvider(ViewGroup containerView, AwAutofillManager manager, Context context) {
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
mAutofillManager = manager;
mContainerView = containerView;
mAutofillUMA = new AwAutofillUMA();
mAutofillUMA = new AwAutofillUMA(context);
mInputUIObserver = new AwAutofillManager.InputUIObserver() {
@Override
public void onInputUIShown() {
mAutofillUMA.onSuggestionDisplayed();
// Not need to report suggestion window displayed if there is no live autofill
// session.
if (mRequest == null) return;
mAutofillUMA.onSuggestionDisplayed(
System.currentTimeMillis() - mAutofillTriggeredTimeMillis);
}
};
mAutofillManager.addInputUIObserver(mInputUIObserver);
......@@ -290,6 +295,7 @@ public class AwAutofillProvider extends AutofillProvider {
int virtualId = mRequest.getVirtualId((short) focus);
mAutofillManager.notifyVirtualViewEntered(mContainerView, virtualId, absBound);
mAutofillUMA.onSessionStarted(mAutofillManager.isDisabled());
mAutofillTriggeredTimeMillis = System.currentTimeMillis();
}
@Override
......@@ -303,7 +309,7 @@ public class AwAutofillProvider extends AutofillProvider {
onFocusChangedImpl(true, index, x, y, width, height, true /*causedByValueChange*/);
} else {
// Currently there is no api to notify both value and position
// change, before the API is availabe, we still need to call
// change, before the API is available, we still need to call
// notifyVirtualViewEntered() to tell current coordinates because
// the position could be changed.
int virtualId = mRequest.getVirtualId(sIndex);
......@@ -382,9 +388,13 @@ public class AwAutofillProvider extends AutofillProvider {
mAutofillManager.notifyVirtualViewEntered(
mContainerView, mRequest.getVirtualId((short) focusField), absBound);
// The focus field value might not sync with platform's
// AutofillManager, just notify it value changed.
if (!causedByValueChange) notifyVirtualValueChanged(focusField);
if (!causedByValueChange) {
// The focus field value might not sync with platform's
// AutofillManager, just notify it value changed.
notifyVirtualValueChanged(focusField);
mAutofillTriggeredTimeMillis = System.currentTimeMillis();
}
mRequest.setFocusField(new FocusField((short) focusField, absBound));
} else {
if (prev == null) return;
......
......@@ -4,9 +4,13 @@
package org.chromium.android_webview;
import android.content.Context;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.components.autofill.SubmissionSource;
import java.util.concurrent.TimeUnit;
/**
* The class for WebView autofill UMA.
*/
......@@ -14,6 +18,10 @@ public class AwAutofillUMA {
// Records whether the Autofill service is enabled or not.
public static final String UMA_AUTOFILL_WEBVIEW_ENABLED = "Autofill.WebView.Enabled";
// Records whether the Autofill provider is created by activity context or not.
public static final String UMA_AUTOFILL_WEBVIEW_CREATED_BY_ACTIVITY_CONTEXT =
"Autofill.WebView.CreatedByActivityContext";
// Records what happened in an autofill session.
public static final String UMA_AUTOFILL_WEBVIEW_AUTOFILL_SESSION =
"Autofill.WebView.AutofillSession";
......@@ -58,6 +66,16 @@ public class AwAutofillUMA {
public static final String UMA_AUTOFILL_WEBVIEW_SUGGESTION_TIME =
"Autofill.WebView.SuggestionTime";
// The expected time range of time is from 10ms to 2 seconds, and 50 buckets is sufficient.
private static final long MIN_TIME_MILLIS = 10;
private static final long MAX_TIME_MILLIS = TimeUnit.SECONDS.toMillis(2);
private static final int NUM_OF_BUCKETS = 50;
private static void recordTimesHistogram(String name, long durationMillis) {
RecordHistogram.recordCustomTimesHistogram(name, durationMillis, MIN_TIME_MILLIS,
MAX_TIME_MILLIS, TimeUnit.MILLISECONDS, NUM_OF_BUCKETS);
}
private static class SessionRecorder {
public static final int EVENT_VIRTUAL_STRUCTURE_PROVIDED = 0x1 << 0;
public static final int EVENT_SUGGESTION_DISPLAYED = 0x1 << 1;
......@@ -66,6 +84,8 @@ public class AwAutofillUMA {
public static final int EVENT_FORM_SUBMITTED = 0x1 << 4;
public static final int EVENT_USER_CHANGED_AUTOFILLED_FIELD = 0x1 << 5;
private Long mSuggestionTimeMillis;
public void record(int event) {
// Not record any event until we get EVENT_VIRTUAL_STRUCTURE_PROVIDED which makes the
// following events meaningful.
......@@ -82,6 +102,13 @@ public class AwAutofillUMA {
mState |= event;
}
public void setSuggestionTimeMillis(long suggestionTimeMillis) {
// Only record first suggestion.
if (mSuggestionTimeMillis == null) {
mSuggestionTimeMillis = Long.valueOf(suggestionTimeMillis);
}
}
public void recordHistogram() {
RecordHistogram.recordEnumeratedHistogram(UMA_AUTOFILL_WEBVIEW_AUTOFILL_SESSION,
toUMAAutofillSessionValue(), AUTOFILL_SESSION_HISTOGRAM_COUNT);
......@@ -90,6 +117,9 @@ public class AwAutofillUMA {
RecordHistogram.recordBooleanHistogram(
UMA_AUTOFILL_USER_CHANGED_AUTOFILLED_FIELD, mUserChangedAutofilledField);
}
if (mSuggestionTimeMillis != null) {
recordTimesHistogram(UMA_AUTOFILL_WEBVIEW_SUGGESTION_TIME, mSuggestionTimeMillis);
}
}
private int toUMAAutofillSessionValue() {
......@@ -147,6 +177,11 @@ public class AwAutofillUMA {
private SessionRecorder mRecorder;
private Boolean mAutofillDisabled;
public AwAutofillUMA(Context context) {
RecordHistogram.recordBooleanHistogram(UMA_AUTOFILL_WEBVIEW_CREATED_BY_ACTIVITY_CONTEXT,
AwContents.activityFromContext(context) != null);
}
public void onFormSubmitted(int submissionSource) {
if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_FORM_SUBMITTED);
recordSession();
......@@ -170,8 +205,11 @@ public class AwAutofillUMA {
if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_VIRTUAL_STRUCTURE_PROVIDED);
}
public void onSuggestionDisplayed() {
if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_SUGGESTION_DISPLAYED);
public void onSuggestionDisplayed(long suggestionTimeMillis) {
if (mRecorder != null) {
mRecorder.record(SessionRecorder.EVENT_SUGGESTION_DISPLAYED);
mRecorder.setSuggestionTimeMillis(suggestionTimeMillis);
}
}
public void onAutofill() {
......
......@@ -6823,6 +6823,12 @@ uploading your change for review.
<summary>Records the state of an autofill session.</summary>
</histogram>
<histogram name="Autofill.WebView.CreatedByActivityContext"
enum="BooleanEnabled">
<owner>michaelbai@chromium.org</owner>
<summary>Whether the autofill is created by activity context.</summary>
</histogram>
<histogram name="Autofill.WebView.Enabled" enum="BooleanEnabled">
<owner>michaelbai@chromium.org</owner>
<summary>
......@@ -6836,6 +6842,11 @@ uploading your change for review.
<summary>Records the source of form submission.</summary>
</histogram>
<histogram name="Autofill.WebView.SuggestionTime" units="ms">
<owner>michaelbai@chromium.org</owner>
<summary>The time taken to display suggestion.</summary>
</histogram>
<histogram name="Autofill.WebView.UserChangedAutofilledField"
enum="BooleanEnabled">
<owner>michaelbai@chromium.org</owner>
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