OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import org.chromium.base.JNINamespace; | 7 import java.lang.reflect.Constructor; |
8 | |
8 | 9 |
9 /** | 10 /** |
10 * Controls UMA histograms. | 11 * Controls UMA histograms. |
xunjieli
2015/02/06 19:05:01
nit: Maybe add a comment saying that this class is
mef
2015/02/06 19:28:55
Done. I'll add a test that it handles 'no native l
| |
11 */ | 12 */ |
12 @JNINamespace("cronet") | 13 public abstract class HistogramManager { |
13 public final class HistogramManager { | 14 private static final String CRONET_HISTOGRAM_MANAGER = |
14 public HistogramManager() { | 15 "org.chromium.net.CronetHistogramManager"; |
15 nativeEnsureInitialized(); | |
16 } | |
17 | 16 |
18 /** | 17 /** |
19 * Get histogram deltas serialized as protobuf. | 18 * Get histogram deltas serialized as protobuf. |
20 */ | 19 */ |
21 public byte[] getHistogramDeltas() { | 20 public abstract byte[] getHistogramDeltas(); |
22 return nativeGetHistogramDeltas(); | 21 |
22 public static HistogramManager createHistogramManager() { | |
23 HistogramManager histogramManager = null; | |
24 try { | |
25 Class<? extends HistogramManager> histogramManagerClass = | |
26 HistogramManager.class.getClassLoader() | |
27 .loadClass(CRONET_HISTOGRAM_MANAGER) | |
28 .asSubclass(HistogramManager.class); | |
29 Constructor<? extends HistogramManager> constructor = | |
30 histogramManagerClass.getConstructor(); | |
31 histogramManager = constructor.newInstance(); | |
32 } catch (ClassNotFoundException e) { | |
33 // Leave as null. | |
34 } catch (Exception e) { | |
35 throw new IllegalStateException( | |
36 "Cannot instantiate: " + CRONET_HISTOGRAM_MANAGER, | |
37 e); | |
38 } | |
39 return histogramManager; | |
23 } | 40 } |
24 | |
25 private native byte[] nativeGetHistogramDeltas(); | |
26 | |
27 private native void nativeEnsureInitialized(); | |
28 } | 41 } |
OLD | NEW |