Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(927)

Unified Diff: content/browser/battery_status/battery_status_manager_win.cc

Issue 556873004: Battery Status API: add UMA logging for Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/battery_status/battery_status_manager_win.cc
diff --git a/content/browser/battery_status/battery_status_manager_win.cc b/content/browser/battery_status/battery_status_manager_win.cc
index d998d5aca0e2ab6405e323d659aa894cf179ef34..9e717a827d367880ac15a5e5b2b7efdb9f2c79bd 100644
--- a/content/browser/battery_status/battery_status_manager_win.cc
+++ b/content/browser/battery_status/battery_status_manager_win.cc
@@ -5,6 +5,7 @@
#include "content/browser/battery_status/battery_status_manager_win.h"
#include "base/memory/ref_counted.h"
+#include "base/metrics/histogram.h"
#include "base/strings/string16.h"
#include "base/win/message_window.h"
#include "base/win/windows_version.h"
@@ -19,6 +20,36 @@ typedef BatteryStatusService::BatteryUpdateCallback BatteryCallback;
const wchar_t kWindowClassName[] = L"BatteryStatusMessageWindow";
+// This enum is used for histogram. Don't change the order of the existing
+// values.
+enum NumberBatteriesType {
+ UNKNOWN_BATTERIES = 0,
+ NO_BATTERY = 1,
+ ONE_OR_MORE_BATTERIES = 2,
+ BATTERY_TYPES_COUNT = 3,
+};
+
+void UpdateNumberBatteriesHistogram(NumberBatteriesType count) {
+ UMA_HISTOGRAM_ENUMERATION("BatteryStatus.NumberBatteriesWin",
+ count,
+ BATTERY_TYPES_COUNT);
+}
+
+void UpdateNumberBatteriesHistogram() {
+ SYSTEM_POWER_STATUS win_status;
+ if (!GetSystemPowerStatus(&win_status)) {
+ UpdateNumberBatteriesHistogram(UNKNOWN_BATTERIES);
+ return;
+ }
+
+ if (win_status.BatteryFlag == 255)
+ UpdateNumberBatteriesHistogram(UNKNOWN_BATTERIES);
+ else if (win_status.BatteryFlag == 128)
+ UpdateNumberBatteriesHistogram(NO_BATTERY);
+ else
+ UpdateNumberBatteriesHistogram(ONE_OR_MORE_BATTERIES);
+}
+
// Message-only window for handling battery changes on Windows.
class BatteryStatusObserver
: public base::RefCountedThreadSafe<BatteryStatusObserver> {
@@ -68,6 +99,8 @@ class BatteryStatusObserver
// values.
callback_.Run(blink::WebBatteryStatus());
}
+
+ UpdateNumberBatteriesHistogram();
}
void StopOnUI() {
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698