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 { ...@@ -218,21 +218,26 @@ public class AwAutofillProvider extends AutofillProvider {
private long mNativeAutofillProvider; private long mNativeAutofillProvider;
private AwAutofillUMA mAutofillUMA; private AwAutofillUMA mAutofillUMA;
private AwAutofillManager.InputUIObserver mInputUIObserver; private AwAutofillManager.InputUIObserver mInputUIObserver;
private long mAutofillTriggeredTimeMillis;
public AwAutofillProvider(Context context, ViewGroup containerView) { public AwAutofillProvider(Context context, ViewGroup containerView) {
this(containerView, new AwAutofillManager(context)); this(containerView, new AwAutofillManager(context), context);
} }
@VisibleForTesting @VisibleForTesting
public AwAutofillProvider(ViewGroup containerView, AwAutofillManager manager) { public AwAutofillProvider(ViewGroup containerView, AwAutofillManager manager, Context context) {
assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; assert Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
mAutofillManager = manager; mAutofillManager = manager;
mContainerView = containerView; mContainerView = containerView;
mAutofillUMA = new AwAutofillUMA(); mAutofillUMA = new AwAutofillUMA(context);
mInputUIObserver = new AwAutofillManager.InputUIObserver() { mInputUIObserver = new AwAutofillManager.InputUIObserver() {
@Override @Override
public void onInputUIShown() { 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); mAutofillManager.addInputUIObserver(mInputUIObserver);
...@@ -290,6 +295,7 @@ public class AwAutofillProvider extends AutofillProvider { ...@@ -290,6 +295,7 @@ public class AwAutofillProvider extends AutofillProvider {
int virtualId = mRequest.getVirtualId((short) focus); int virtualId = mRequest.getVirtualId((short) focus);
mAutofillManager.notifyVirtualViewEntered(mContainerView, virtualId, absBound); mAutofillManager.notifyVirtualViewEntered(mContainerView, virtualId, absBound);
mAutofillUMA.onSessionStarted(mAutofillManager.isDisabled()); mAutofillUMA.onSessionStarted(mAutofillManager.isDisabled());
mAutofillTriggeredTimeMillis = System.currentTimeMillis();
} }
@Override @Override
...@@ -303,7 +309,7 @@ public class AwAutofillProvider extends AutofillProvider { ...@@ -303,7 +309,7 @@ public class AwAutofillProvider extends AutofillProvider {
onFocusChangedImpl(true, index, x, y, width, height, true /*causedByValueChange*/); onFocusChangedImpl(true, index, x, y, width, height, true /*causedByValueChange*/);
} else { } else {
// Currently there is no api to notify both value and position // 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 // notifyVirtualViewEntered() to tell current coordinates because
// the position could be changed. // the position could be changed.
int virtualId = mRequest.getVirtualId(sIndex); int virtualId = mRequest.getVirtualId(sIndex);
...@@ -382,9 +388,13 @@ public class AwAutofillProvider extends AutofillProvider { ...@@ -382,9 +388,13 @@ public class AwAutofillProvider extends AutofillProvider {
mAutofillManager.notifyVirtualViewEntered( mAutofillManager.notifyVirtualViewEntered(
mContainerView, mRequest.getVirtualId((short) focusField), absBound); mContainerView, mRequest.getVirtualId((short) focusField), absBound);
// The focus field value might not sync with platform's
// AutofillManager, just notify it value changed. if (!causedByValueChange) {
if (!causedByValueChange) notifyVirtualValueChanged(focusField); // 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)); mRequest.setFocusField(new FocusField((short) focusField, absBound));
} else { } else {
if (prev == null) return; if (prev == null) return;
......
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
package org.chromium.android_webview; package org.chromium.android_webview;
import android.content.Context;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.components.autofill.SubmissionSource; import org.chromium.components.autofill.SubmissionSource;
import java.util.concurrent.TimeUnit;
/** /**
* The class for WebView autofill UMA. * The class for WebView autofill UMA.
*/ */
...@@ -14,6 +18,10 @@ public class AwAutofillUMA { ...@@ -14,6 +18,10 @@ public class AwAutofillUMA {
// Records whether the Autofill service is enabled or not. // Records whether the Autofill service is enabled or not.
public static final String UMA_AUTOFILL_WEBVIEW_ENABLED = "Autofill.WebView.Enabled"; 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. // Records what happened in an autofill session.
public static final String UMA_AUTOFILL_WEBVIEW_AUTOFILL_SESSION = public static final String UMA_AUTOFILL_WEBVIEW_AUTOFILL_SESSION =
"Autofill.WebView.AutofillSession"; "Autofill.WebView.AutofillSession";
...@@ -58,6 +66,16 @@ public class AwAutofillUMA { ...@@ -58,6 +66,16 @@ public class AwAutofillUMA {
public static final String UMA_AUTOFILL_WEBVIEW_SUGGESTION_TIME = public static final String UMA_AUTOFILL_WEBVIEW_SUGGESTION_TIME =
"Autofill.WebView.SuggestionTime"; "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 { private static class SessionRecorder {
public static final int EVENT_VIRTUAL_STRUCTURE_PROVIDED = 0x1 << 0; public static final int EVENT_VIRTUAL_STRUCTURE_PROVIDED = 0x1 << 0;
public static final int EVENT_SUGGESTION_DISPLAYED = 0x1 << 1; public static final int EVENT_SUGGESTION_DISPLAYED = 0x1 << 1;
...@@ -66,6 +84,8 @@ public class AwAutofillUMA { ...@@ -66,6 +84,8 @@ public class AwAutofillUMA {
public static final int EVENT_FORM_SUBMITTED = 0x1 << 4; public static final int EVENT_FORM_SUBMITTED = 0x1 << 4;
public static final int EVENT_USER_CHANGED_AUTOFILLED_FIELD = 0x1 << 5; public static final int EVENT_USER_CHANGED_AUTOFILLED_FIELD = 0x1 << 5;
private Long mSuggestionTimeMillis;
public void record(int event) { public void record(int event) {
// Not record any event until we get EVENT_VIRTUAL_STRUCTURE_PROVIDED which makes the // Not record any event until we get EVENT_VIRTUAL_STRUCTURE_PROVIDED which makes the
// following events meaningful. // following events meaningful.
...@@ -82,6 +102,13 @@ public class AwAutofillUMA { ...@@ -82,6 +102,13 @@ public class AwAutofillUMA {
mState |= event; mState |= event;
} }
public void setSuggestionTimeMillis(long suggestionTimeMillis) {
// Only record first suggestion.
if (mSuggestionTimeMillis == null) {
mSuggestionTimeMillis = Long.valueOf(suggestionTimeMillis);
}
}
public void recordHistogram() { public void recordHistogram() {
RecordHistogram.recordEnumeratedHistogram(UMA_AUTOFILL_WEBVIEW_AUTOFILL_SESSION, RecordHistogram.recordEnumeratedHistogram(UMA_AUTOFILL_WEBVIEW_AUTOFILL_SESSION,
toUMAAutofillSessionValue(), AUTOFILL_SESSION_HISTOGRAM_COUNT); toUMAAutofillSessionValue(), AUTOFILL_SESSION_HISTOGRAM_COUNT);
...@@ -90,6 +117,9 @@ public class AwAutofillUMA { ...@@ -90,6 +117,9 @@ public class AwAutofillUMA {
RecordHistogram.recordBooleanHistogram( RecordHistogram.recordBooleanHistogram(
UMA_AUTOFILL_USER_CHANGED_AUTOFILLED_FIELD, mUserChangedAutofilledField); UMA_AUTOFILL_USER_CHANGED_AUTOFILLED_FIELD, mUserChangedAutofilledField);
} }
if (mSuggestionTimeMillis != null) {
recordTimesHistogram(UMA_AUTOFILL_WEBVIEW_SUGGESTION_TIME, mSuggestionTimeMillis);
}
} }
private int toUMAAutofillSessionValue() { private int toUMAAutofillSessionValue() {
...@@ -147,6 +177,11 @@ public class AwAutofillUMA { ...@@ -147,6 +177,11 @@ public class AwAutofillUMA {
private SessionRecorder mRecorder; private SessionRecorder mRecorder;
private Boolean mAutofillDisabled; 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) { public void onFormSubmitted(int submissionSource) {
if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_FORM_SUBMITTED); if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_FORM_SUBMITTED);
recordSession(); recordSession();
...@@ -170,8 +205,11 @@ public class AwAutofillUMA { ...@@ -170,8 +205,11 @@ public class AwAutofillUMA {
if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_VIRTUAL_STRUCTURE_PROVIDED); if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_VIRTUAL_STRUCTURE_PROVIDED);
} }
public void onSuggestionDisplayed() { public void onSuggestionDisplayed(long suggestionTimeMillis) {
if (mRecorder != null) mRecorder.record(SessionRecorder.EVENT_SUGGESTION_DISPLAYED); if (mRecorder != null) {
mRecorder.record(SessionRecorder.EVENT_SUGGESTION_DISPLAYED);
mRecorder.setSuggestionTimeMillis(suggestionTimeMillis);
}
} }
public void onAutofill() { public void onAutofill() {
......
...@@ -6823,6 +6823,12 @@ uploading your change for review. ...@@ -6823,6 +6823,12 @@ uploading your change for review.
<summary>Records the state of an autofill session.</summary> <summary>Records the state of an autofill session.</summary>
</histogram> </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"> <histogram name="Autofill.WebView.Enabled" enum="BooleanEnabled">
<owner>michaelbai@chromium.org</owner> <owner>michaelbai@chromium.org</owner>
<summary> <summary>
...@@ -6836,6 +6842,11 @@ uploading your change for review. ...@@ -6836,6 +6842,11 @@ uploading your change for review.
<summary>Records the source of form submission.</summary> <summary>Records the source of form submission.</summary>
</histogram> </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" <histogram name="Autofill.WebView.UserChangedAutofilledField"
enum="BooleanEnabled"> enum="BooleanEnabled">
<owner>michaelbai@chromium.org</owner> <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