Add UMA metric to track the time elapsed since a WebAPK was last launched
This CL also:
Adds a new SharedPreferences property "has_been_launched" to track whether the
WebAPK/Webapp has been launched from the home screen.
BUG=730201
Test=WebApkIntegrationTest.*, WebappModeTest.*
Review-Url: https://codereview.chromium.org/2930553002
Cr-Commit-Position: refs/heads/master@{#483485}
diff --git a/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
index eaf57b7..b3667c55 100644
--- a/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
+++ b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
@@ -270,6 +270,15 @@
}
/**
+ * Returns the number of samples recorded for the given histogram.
+ * @param name name of the histogram to look up.
+ */
+ @VisibleForTesting
+ public static int getHistogramTotalCountForTesting(String name) {
+ return nativeGetHistogramTotalCountForTesting(name);
+ }
+
+ /**
* Initializes the metrics system.
*/
public static void initialize() {
@@ -290,5 +299,6 @@
private static native long nativeRecordSparseHistogram(String name, long key, int sample);
private static native int nativeGetHistogramValueCountForTesting(String name, int sample);
+ private static native int nativeGetHistogramTotalCountForTesting(String name);
private static native void nativeInitialize();
}
diff --git a/base/android/record_histogram.cc b/base/android/record_histogram.cc
index 1a207a18..0561986 100644
--- a/base/android/record_histogram.cc
+++ b/base/android/record_histogram.cc
@@ -315,6 +315,20 @@
return samples->GetCount(static_cast<int>(sample));
}
+jint GetHistogramTotalCountForTesting(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jstring>& histogram_name) {
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(
+ android::ConvertJavaStringToUTF8(env, histogram_name));
+ if (histogram == nullptr) {
+ // No samples have been recorded for this histogram.
+ return 0;
+ }
+
+ return histogram->SnapshotSamples()->TotalCount();
+}
+
bool RegisterRecordHistogram(JNIEnv* env) {
return RegisterNativesImpl(env);
}