From 2fef1eb8e8dca08a2edb084b52a4ca08702b46ee Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Thu, 2 Jun 2016 22:46:38 -0700 Subject: [PATCH] Bug 1259335 - Part 1.5: Collect use count telemetry for Battery Status API. r=baku --- dom/base/Navigator.cpp | 6 ++++++ dom/base/Navigator.h | 2 ++ toolkit/components/telemetry/Histograms.json | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 096d2d034b808..a45ee86f8e55c 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -204,6 +204,7 @@ Navigator::Init() Navigator::Navigator(nsPIDOMWindowInner* aWindow) : mWindow(aWindow) + , mBatteryTelemetryReported(false) { MOZ_ASSERT(aWindow->IsInnerWindow(), "Navigator must get an inner window!"); } @@ -307,6 +308,7 @@ Navigator::Invalidate() } mBatteryPromise = nullptr; + mBatteryTelemetryReported = false; #ifdef MOZ_B2G_FM if (mFMRadio) { @@ -1587,6 +1589,10 @@ Navigator::GetBattery(ErrorResult& aRv) } mBatteryPromise = batteryPromise; + // We just initialized mBatteryPromise, so we know this is the first time + // this page has accessed navigator.getBattery(). 1 = navigator.getBattery() + Telemetry::Accumulate(Telemetry::BATTERY_STATUS_COUNT, 1); + if (!mBatteryManager) { mBatteryManager = new battery::BatteryManager(mWindow); mBatteryManager->Init(); diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index 0b42e4e0afadb..7bb9c7c68ffe0 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -403,6 +403,8 @@ class Navigator final : public nsIDOMNavigator nsTArray > mVRGetDevicesPromises; nsTArray mRequestedVibrationPattern; + + bool mBatteryTelemetryReported; }; } // namespace dom diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index aad6c990a76fd..48870c5c6a2ee 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -100,6 +100,14 @@ "n_values": 21, "description": "Maximum number of concurrent threads reached during a given download session" }, + "BATTERY_STATUS_COUNT": { + "alert_emails": ["cpeterson@mozilla.com"], + "bug_numbers": [1259335], + "expires_in_version": "52", + "kind": "enumerated", + "n_values": 10, + "description": "Number of pages that use the Battery Status API: 0=navigator.battery, 1=navigator.getBattery()" + }, "BLOCKLIST_SYNC_FILE_LOAD": { "alert_emails": ["rvitillo@mozilla.com"], "expires_in_version": "35",