Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/android/jni_android.h" | |
| 6 #include "base/android/jni_string.h" | |
| 7 #include "base/android/record_histogram.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/metrics/statistics_recorder.h" | |
| 10 #include "jni/RecordHistogram_jni.h" | |
| 11 | |
| 12 namespace base { | |
| 13 namespace android { | |
| 14 | |
| 15 void RecordBooleanHistogram(JNIEnv* env, | |
| 16 jclass clazz, | |
| 17 jstring j_histogram_name, | |
| 18 jboolean j_sample) { | |
| 19 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | |
|
jdduke (slow)
2015/01/23 17:33:41
Ouch, JNI + string conversion isn't exactly the ch
Alexei Svitkine (slow)
2015/01/23 17:52:07
Having a shared enum adds more boiler plate that t
jdduke (slow)
2015/01/23 18:19:31
That sounds pretty reasonable, any objections?
| |
| 20 bool sample = static_cast<bool>(j_sample); | |
| 21 | |
| 22 BooleanHistogram::FactoryGet(histogram_name, | |
| 23 HistogramBase::kUmaTargetedHistogramFlag) | |
| 24 ->AddBoolean(sample); | |
| 25 } | |
| 26 | |
| 27 void RecordEnumeratedHistogram(JNIEnv* env, | |
| 28 jclass clazz, | |
| 29 jstring j_histogram_name, | |
| 30 jint j_sample, | |
| 31 jint j_boundary) { | |
| 32 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | |
| 33 int sample = static_cast<int>(j_sample); | |
| 34 int boundary = static_cast<int>(j_boundary); | |
| 35 | |
| 36 LinearHistogram::FactoryGet(histogram_name, 1, boundary, boundary + 1, | |
| 37 HistogramBase::kUmaTargetedHistogramFlag) | |
| 38 ->Add(sample); | |
| 39 } | |
| 40 | |
| 41 void Initialize(JNIEnv* env, jclass) { | |
| 42 StatisticsRecorder::Initialize(); | |
| 43 } | |
| 44 | |
| 45 // This backs a Java test util for testing histograms - | |
| 46 // MetricsUtils.HistogramDelta. It should live in a test-specific file, but we | |
| 47 // currently can't have test-specific native code packaged in test-specific Java | |
| 48 // targets - see http://crbug.com/415945. | |
| 49 jint GetHistogramValueCountForTesting(JNIEnv* env, | |
| 50 jclass clazz, | |
| 51 jstring histogram_name, | |
| 52 jint sample) { | |
| 53 HistogramBase* histogram = StatisticsRecorder::FindHistogram( | |
| 54 android::ConvertJavaStringToUTF8(env, histogram_name)); | |
| 55 if (histogram == nullptr) { | |
| 56 // No samples have been recorded for this histogram (yet?). | |
| 57 return 0; | |
| 58 } | |
| 59 | |
| 60 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); | |
| 61 return samples->GetCount(static_cast<int>(sample)); | |
| 62 } | |
| 63 | |
| 64 bool RegisterRecordHistogram(JNIEnv* env) { | |
| 65 return RegisterNativesImpl(env); | |
| 66 } | |
| 67 | |
| 68 } // namespace android | |
| 69 } // namespace base | |
| OLD | NEW |