Index: chrome/android/java/src/org/chromium/chrome/browser/metrics/LaunchMetrics.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/metrics/LaunchMetrics.java b/chrome/android/java/src/org/chromium/chrome/browser/metrics/LaunchMetrics.java |
index ad58bb1a954194773eff9d105fe75756fca1eb21..f74cf9b8a97c9ea2463afbf74047f2db9ac37b78 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/metrics/LaunchMetrics.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/metrics/LaunchMetrics.java |
@@ -7,14 +7,11 @@ package org.chromium.chrome.browser.metrics; |
import android.util.Pair; |
import org.chromium.base.annotations.JNINamespace; |
-import org.chromium.base.library_loader.LibraryLoader; |
-import org.chromium.base.metrics.RecordHistogram; |
-import org.chromium.base.metrics.RecordUserAction; |
+import org.chromium.base.metrics.CachedMetrics; |
import org.chromium.content_public.browser.WebContents; |
import java.util.ArrayList; |
import java.util.List; |
-import java.util.concurrent.TimeUnit; |
/** |
* Used for recording metrics about Chrome launches that need to be recorded before the native |
@@ -23,150 +20,6 @@ import java.util.concurrent.TimeUnit; |
*/ |
@JNINamespace("metrics") |
public class LaunchMetrics { |
- |
- /** |
- * Creating an instance of a subclass of this class automatically adds it to a list of objects |
- * that are committed when the native library is available. |
- */ |
- private abstract static class CachedHistogram { |
- private static final List<CachedHistogram> sEvents = new ArrayList<CachedHistogram>(); |
- |
- protected final String mHistogramName; |
- |
- /** |
- * @param histogramName Name of the histogram to record. |
- */ |
- protected CachedHistogram(String histogramName) { |
- mHistogramName = histogramName; |
- sEvents.add(this); |
- } |
- |
- /** Commits the histogram. Expects the native library to be loaded. */ |
- protected abstract void commitAndClear(); |
- } |
- |
- /** |
- * Caches an action that will be recorded after native side is loaded. |
- */ |
- public static class ActionEvent extends CachedHistogram { |
- private int mCount; |
- |
- public ActionEvent(String actionName) { |
- super(actionName); |
- } |
- |
- public void record() { |
- if (LibraryLoader.isInitialized()) { |
- recordWithNative(); |
- } else { |
- mCount++; |
- } |
- } |
- |
- private void recordWithNative() { |
- RecordUserAction.record(mHistogramName); |
- } |
- |
- @Override |
- protected void commitAndClear() { |
- while (mCount > 0) { |
- recordWithNative(); |
- mCount--; |
- } |
- } |
- } |
- |
- /** Caches a set of integer histogram samples. */ |
- public static class SparseHistogramSample extends CachedHistogram { |
- private final List<Integer> mSamples = new ArrayList<Integer>(); |
- |
- public SparseHistogramSample(String histogramName) { |
- super(histogramName); |
- } |
- |
- public void record(int sample) { |
- if (LibraryLoader.isInitialized()) { |
- recordWithNative(sample); |
- } else { |
- mSamples.add(sample); |
- } |
- } |
- |
- private void recordWithNative(int sample) { |
- RecordHistogram.recordSparseSlowlyHistogram(mHistogramName, sample); |
- } |
- |
- @Override |
- protected void commitAndClear() { |
- for (Integer sample : mSamples) { |
- recordWithNative(sample); |
- } |
- mSamples.clear(); |
- } |
- } |
- |
- /** Caches a set of enumerated histogram samples. */ |
- public static class EnumeratedHistogramSample extends CachedHistogram { |
- private final List<Integer> mSamples = new ArrayList<Integer>(); |
- private final int mMaxValue; |
- |
- public EnumeratedHistogramSample(String histogramName, int maxValue) { |
- super(histogramName); |
- mMaxValue = maxValue; |
- } |
- |
- public void record(int sample) { |
- if (LibraryLoader.isInitialized()) { |
- recordWithNative(sample); |
- } else { |
- mSamples.add(sample); |
- } |
- } |
- |
- private void recordWithNative(int sample) { |
- RecordHistogram.recordEnumeratedHistogram(mHistogramName, sample, mMaxValue); |
- } |
- |
- @Override |
- protected void commitAndClear() { |
- for (Integer sample : mSamples) { |
- recordWithNative(sample); |
- } |
- mSamples.clear(); |
- } |
- } |
- |
- /** Caches a set of times histogram samples. */ |
- public static class TimesHistogramSample extends CachedHistogram { |
- private final List<Long> mSamples = new ArrayList<Long>(); |
- private final TimeUnit mTimeUnit; |
- |
- public TimesHistogramSample(String histogramName, TimeUnit timeUnit) { |
- super(histogramName); |
- mTimeUnit = timeUnit; |
- } |
- |
- public void record(long sample) { |
- if (LibraryLoader.isInitialized()) { |
- recordWithNative(sample); |
- } else { |
- mSamples.add(sample); |
- } |
- } |
- |
- private void recordWithNative(long sample) { |
- RecordHistogram.recordTimesHistogram(mHistogramName, sample, mTimeUnit); |
- } |
- |
- @Override |
- protected void commitAndClear() { |
- for (Long sample : mSamples) { |
- recordWithNative(sample); |
- } |
- mSamples.clear(); |
- } |
- } |
- |
// Each list item is a pair of the url and where it was added from e.g. from the add to |
// homescreen menu item, an app banner, or unknown. The mapping of int source values to |
// their string names is found in the C++ ShortcutInfo struct. |
@@ -222,7 +75,7 @@ public class LaunchMetrics { |
sTabUrls.clear(); |
// Record generic cached events. |
- for (CachedHistogram event : CachedHistogram.sEvents) event.commitAndClear(); |
+ CachedMetrics.commitCachedMetrics(); |
} |
/** |