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, | |
Alexei Svitkine (slow)
2015/01/05 15:54:41
Nit: I thought Chromium style doesn't permit omitt
ppi
2015/01/08 10:54:22
Done.
| |
17 jstring j_histogram_name, | |
18 jboolean j_sample) { | |
19 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | |
20 bool sample = static_cast<bool>(j_sample); | |
21 | |
22 BooleanHistogram::FactoryGet(histogram_name, | |
23 base::HistogramBase::kUmaTargetedHistogramFlag) | |
Alexei Svitkine (slow)
2015/01/05 15:54:41
Nit: This is already in base namespace right, so y
ppi
2015/01/08 10:54:22
Done.
| |
24 ->AddBoolean(sample); | |
25 } | |
26 | |
27 void RecordEnumeratedHistogram(JNIEnv* env, | |
28 jclass, | |
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 base::LinearHistogram::FactoryGet( | |
37 histogram_name, 1, boundary, boundary + 1, | |
38 base::HistogramBase::kUmaTargetedHistogramFlag)->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, | |
51 jstring histogram_name, | |
52 jint sample) { | |
53 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram( | |
54 base::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<base::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 |