Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Unified Diff: base/android/java/src/org/chromium/base/metrics/RecordHistogram.java

Issue 1597273005: Move ChromiumMultiDex to BuildConfig. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
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 c1b04892e87362dfc459bcbacdb75d817f4fb975..447dd87741aa2f414a99aa2758e3c77a62b0ce84 100644
--- a/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
+++ b/base/android/java/src/org/chromium/base/metrics/RecordHistogram.java
@@ -4,8 +4,10 @@
package org.chromium.base.metrics;
+import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.JNINamespace;
+import org.chromium.chrome.browser.ChromeVersionInfo;
Yaron 2016/01/18 17:51:10 Unfortunately this dep won't work because you're i
Peter Wen 2016/01/18 22:18:08 Acknowledged.
import java.util.concurrent.TimeUnit;
@@ -18,6 +20,21 @@ import java.util.concurrent.TimeUnit;
*/
@JNINamespace("base::android")
public class RecordHistogram {
+ private static final String TAG = "RecordHistogram";
+
+ private static boolean sNativeInitialized = false;
+
+ private static boolean isNativeInitialized() {
+ if (!sNativeInitialized) {
+ if (ChromeVersionInfo.isLocalBuild()) {
+ throw new RuntimeException("Calling RecordHistogram before native is loaded.");
+ } else {
+ Log.w(TAG, "Calling RecordHistogram before native is loaded.");
Yaron 2016/01/18 17:51:10 Can you make the histogram name a parameter to thi
Peter Wen 2016/01/18 22:18:08 Done.
+ }
+ }
+ return sNativeInitialized;
+ }
+
/**
* Records a sample in a boolean UMA histogram of the given name. Boolean histogram has two
* buckets, corresponding to success (true) and failure (false). This is the Java equivalent of
@@ -26,7 +43,9 @@ public class RecordHistogram {
* @param sample sample to be recorded, either true or false
*/
public static void recordBooleanHistogram(String name, boolean sample) {
- nativeRecordBooleanHistogram(name, System.identityHashCode(name), sample);
+ if (isNativeInitialized()) {
+ nativeRecordBooleanHistogram(name, System.identityHashCode(name), sample);
+ }
}
/**
@@ -39,7 +58,9 @@ public class RecordHistogram {
* lower than |boundary|
*/
public static void recordEnumeratedHistogram(String name, int sample, int boundary) {
- nativeRecordEnumeratedHistogram(name, System.identityHashCode(name), sample, boundary);
+ if (isNativeInitialized()) {
+ nativeRecordEnumeratedHistogram(name, System.identityHashCode(name), sample, boundary);
+ }
}
/**
@@ -83,8 +104,10 @@ public class RecordHistogram {
*/
public static void recordCustomCountHistogram(
String name, int sample, int min, int max, int numBuckets) {
- nativeRecordCustomCountHistogram(
- name, System.identityHashCode(name), sample, min, max, numBuckets);
+ if (isNativeInitialized()) {
+ nativeRecordCustomCountHistogram(
+ name, System.identityHashCode(name), sample, min, max, numBuckets);
+ }
}
/**
@@ -98,8 +121,10 @@ public class RecordHistogram {
*/
public static void recordLinearCountHistogram(
String name, int sample, int min, int max, int numBuckets) {
- nativeRecordLinearCountHistogram(
- name, System.identityHashCode(name), sample, min, max, numBuckets);
+ if (isNativeInitialized()) {
+ nativeRecordLinearCountHistogram(
+ name, System.identityHashCode(name), sample, min, max, numBuckets);
+ }
}
/**
@@ -109,7 +134,9 @@ public class RecordHistogram {
* @param sample sample to be recorded, at least 0 and at most 100.
*/
public static void recordPercentageHistogram(String name, int sample) {
- nativeRecordEnumeratedHistogram(name, System.identityHashCode(name), sample, 101);
+ if (isNativeInitialized()) {
+ nativeRecordEnumeratedHistogram(name, System.identityHashCode(name), sample, 101);
+ }
}
/**
@@ -119,7 +146,9 @@ public class RecordHistogram {
* values.
*/
public static void recordSparseSlowlyHistogram(String name, int sample) {
- nativeRecordSparseHistogram(name, System.identityHashCode(name), sample);
+ if (isNativeInitialized()) {
+ nativeRecordSparseHistogram(name, System.identityHashCode(name), sample);
+ }
}
/**
@@ -176,8 +205,10 @@ public class RecordHistogram {
private static void recordCustomTimesHistogramMilliseconds(
String name, long duration, long min, long max, int numBuckets) {
- nativeRecordCustomTimesHistogramMilliseconds(
- name, System.identityHashCode(name), duration, min, max, numBuckets);
+ if (isNativeInitialized()) {
+ nativeRecordCustomTimesHistogramMilliseconds(
+ name, System.identityHashCode(name), duration, min, max, numBuckets);
+ }
}
/**
@@ -187,6 +218,7 @@ public class RecordHistogram {
*/
@VisibleForTesting
public static int getHistogramValueCountForTesting(String name, int sample) {
+ // Should fail if native is not loaded since this is testing-only.
return nativeGetHistogramValueCountForTesting(name, sample);
}
@@ -195,6 +227,7 @@ public class RecordHistogram {
*/
public static void initialize() {
nativeInitialize();
+ sNativeInitialized = true;
}
private static native void nativeRecordCustomTimesHistogramMilliseconds(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698