| 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 in native library. |
| 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 /** |
| 23 * Creates Histogram Manager if native library is loaded, returns null if no
t. |
| 24 */ |
| 25 public static HistogramManager createHistogramManager() { |
| 26 HistogramManager histogramManager = null; |
| 27 try { |
| 28 Class<? extends HistogramManager> histogramManagerClass = |
| 29 HistogramManager.class.getClassLoader() |
| 30 .loadClass(CRONET_HISTOGRAM_MANAGER) |
| 31 .asSubclass(HistogramManager.class); |
| 32 Constructor<? extends HistogramManager> constructor = |
| 33 histogramManagerClass.getConstructor(); |
| 34 histogramManager = constructor.newInstance(); |
| 35 } catch (ClassNotFoundException e) { |
| 36 // Leave as null. |
| 37 } catch (Exception e) { |
| 38 throw new IllegalStateException( |
| 39 "Cannot instantiate: " + CRONET_HISTOGRAM_MANAGER, |
| 40 e); |
| 41 } |
| 42 return histogramManager; |
| 23 } | 43 } |
| 24 | |
| 25 private native byte[] nativeGetHistogramDeltas(); | |
| 26 | |
| 27 private native void nativeEnsureInitialized(); | |
| 28 } | 44 } |
| OLD | NEW |