Battery Status API: add UMA logging for Android.
[chromium-blink-merge.git] / content / browser / battery_status / battery_status_manager_android.cc
bloba8438b855720eac59a2a9726537127990cd9b9e9
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.
5 #include "content/browser/battery_status/battery_status_manager.h"
7 #include "base/android/jni_android.h"
8 #include "base/metrics/histogram.h"
9 #include "jni/BatteryStatusManager_jni.h"
11 using base::android::AttachCurrentThread;
13 namespace content {
15 BatteryStatusManager::BatteryStatusManager(
16 const BatteryStatusService::BatteryUpdateCallback& callback)
17 : callback_(callback) {
18 j_manager_.Reset(
19 Java_BatteryStatusManager_getInstance(
20 AttachCurrentThread(), base::android::GetApplicationContext()));
23 BatteryStatusManager::BatteryStatusManager() {
26 BatteryStatusManager::~BatteryStatusManager() {
29 bool BatteryStatusManager::Register(JNIEnv* env) {
30 return RegisterNativesImpl(env);
33 void BatteryStatusManager::GotBatteryStatus(JNIEnv*, jobject,
34 jboolean charging, jdouble charging_time, jdouble discharging_time,
35 jdouble level) {
36 blink::WebBatteryStatus status;
37 status.charging = charging;
38 status.chargingTime = charging_time;
39 status.dischargingTime = discharging_time;
40 status.level = level;
41 callback_.Run(status);
44 bool BatteryStatusManager::StartListeningBatteryChange() {
45 bool result = Java_BatteryStatusManager_start(AttachCurrentThread(),
46 j_manager_.obj(), reinterpret_cast<intptr_t>(this));
47 UMA_HISTOGRAM_BOOLEAN("BatteryStatus.StartAndroid", result);
48 return result;
51 void BatteryStatusManager::StopListeningBatteryChange() {
52 Java_BatteryStatusManager_stop(
53 AttachCurrentThread(), j_manager_.obj());
56 } // namespace content