Commit 751d79d7 authored by Peter E Conn's avatar Peter E Conn Committed by Commit Bot

🔁 Add last bits of UMA for TWAs.

Bug: 813104
Change-Id: I0139374f0f05c2a685d413e8c9d4bfcd5204cd67
Reviewed-on: https://chromium-review.googlesource.com/1088702
Commit-Queue: Peter Conn <peconn@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565366}
parent f9a9e76e
...@@ -7,9 +7,11 @@ package org.chromium.chrome.browser.browserservices; ...@@ -7,9 +7,11 @@ package org.chromium.chrome.browser.browserservices;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.TimeUnit;
/** /**
* Class to contain metrics recording constants and behaviour for Browser Services. * Class to contain metrics recording constants and behaviour for Browser Services.
...@@ -32,11 +34,28 @@ public class BrowserServicesMetrics { ...@@ -32,11 +34,28 @@ public class BrowserServicesMetrics {
public static final int VERIFICATION_RESULT_CACHED_SUCCESS = 6; public static final int VERIFICATION_RESULT_CACHED_SUCCESS = 6;
public static final int VERIFICATION_RESULT_COUNT = 7; public static final int VERIFICATION_RESULT_COUNT = 7;
/**
* Records the verification result for Trusted Web Activity verification.
*/
public static void recordVerificationResult(@VerificationResultEnum int result) { public static void recordVerificationResult(@VerificationResultEnum int result) {
RecordHistogram.recordEnumeratedHistogram("BrowserServices.VerificationResult", result, RecordHistogram.recordEnumeratedHistogram("BrowserServices.VerificationResult", result,
VERIFICATION_RESULT_COUNT); VERIFICATION_RESULT_COUNT);
} }
/**
* Records that a Trusted Web Activity has been opened.
*/
public static void recordTwaOpened() {
RecordUserAction.record("BrowserServices.TwaOpened");
}
/**
* Records the time that a Trusted Web Activity has been open for.
*/
public static void recordTwaOpenTime(long duration, TimeUnit unit) {
RecordHistogram.recordTimesHistogram("BrowserServices.TwaOpenTime", duration, unit);
}
// Don't let anyone instantiate. // Don't let anyone instantiate.
private BrowserServicesMetrics() {} private BrowserServicesMetrics() {}
} }
...@@ -41,6 +41,7 @@ import org.chromium.chrome.browser.IntentHandler; ...@@ -41,6 +41,7 @@ import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.SingleTabActivity; import org.chromium.chrome.browser.SingleTabActivity;
import org.chromium.chrome.browser.TabState; import org.chromium.chrome.browser.TabState;
import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate;
import org.chromium.chrome.browser.browserservices.BrowserServicesMetrics;
import org.chromium.chrome.browser.browserservices.BrowserSessionContentHandler; import org.chromium.chrome.browser.browserservices.BrowserSessionContentHandler;
import org.chromium.chrome.browser.browserservices.BrowserSessionContentUtils; import org.chromium.chrome.browser.browserservices.BrowserSessionContentUtils;
import org.chromium.chrome.browser.browserservices.BrowserSessionDataProvider; import org.chromium.chrome.browser.browserservices.BrowserSessionDataProvider;
...@@ -114,6 +115,7 @@ public class WebappActivity extends SingleTabActivity { ...@@ -114,6 +115,7 @@ public class WebappActivity extends SingleTabActivity {
private WebappSplashScreenController mSplashController; private WebappSplashScreenController mSplashController;
private boolean mIsInitialized; private boolean mIsInitialized;
private long mOnResumeTimestampMs;
private Integer mBrandColor; private Integer mBrandColor;
private Bitmap mLargestFavicon; private Bitmap mLargestFavicon;
...@@ -192,6 +194,7 @@ public class WebappActivity extends SingleTabActivity { ...@@ -192,6 +194,7 @@ public class WebappActivity extends SingleTabActivity {
return; return;
} }
BrowserServicesMetrics.recordTwaOpened();
// Occasionally verification occurs in the background while there is no active Tab. // Occasionally verification occurs in the background while there is no active Tab.
if (areTabModelsInitialized() && getActivityTab() != null) { if (areTabModelsInitialized() && getActivityTab() != null) {
mUkmRecorder.recordTwaOpened(getActivityTab().getWebContents()); mUkmRecorder.recordTwaOpened(getActivityTab().getWebContents());
...@@ -487,6 +490,8 @@ public class WebappActivity extends SingleTabActivity { ...@@ -487,6 +490,8 @@ public class WebappActivity extends SingleTabActivity {
updateTaskDescription(); updateTaskDescription();
} }
super.onResume(); super.onResume();
mOnResumeTimestampMs = SystemClock.elapsedRealtime();
} }
@Override @Override
...@@ -499,6 +504,11 @@ public class WebappActivity extends SingleTabActivity { ...@@ -499,6 +504,11 @@ public class WebappActivity extends SingleTabActivity {
public void onPauseWithNative() { public void onPauseWithNative() {
mNotificationManager.cancelNotification(); mNotificationManager.cancelNotification();
super.onPauseWithNative(); super.onPauseWithNative();
if (getBrowserSession() != null && !didVerificationFail()) {
BrowserServicesMetrics.recordTwaOpenTime(
SystemClock.elapsedRealtime() - mOnResumeTimestampMs, TimeUnit.MILLISECONDS);
}
} }
@Override @Override
......
...@@ -3500,6 +3500,11 @@ should be able to be added at any place in this file. ...@@ -3500,6 +3500,11 @@ should be able to be added at any place in this file.
<description>Please enter the description of this user action.</description> <description>Please enter the description of this user action.</description>
</action> </action>
<action name="BrowserServices.TwaOpened">
<owner>peconn@chromium.org</owner>
<description>Recorded when a user opens a TWA.</description>
</action>
<action name="Cancel"> <action name="Cancel">
<owner>Please list the metric's owners. Add more owner tags as needed.</owner> <owner>Please list the metric's owners. Add more owner tags as needed.</owner>
<description>Please enter the description of this user action.</description> <description>Please enter the description of this user action.</description>
......
...@@ -9759,6 +9759,14 @@ uploading your change for review. ...@@ -9759,6 +9759,14 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="BrowserServices.TwaOpenTime" units="ms">
<owner>peconn@chromium.org</owner>
<summary>
Triggered when a TrustedWebActivity is paused, recording the time since it
had been resumed.
</summary>
</histogram>
<histogram name="BrowserServices.VerificationResult" <histogram name="BrowserServices.VerificationResult"
enum="BrowserServicesVerificationResult"> enum="BrowserServicesVerificationResult">
<owner>peconn@chromium.org</owner> <owner>peconn@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