#include "chrome/browser/metrics/power/battery_discharge_reporter.h"
#include <utility>
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "chrome/browser/metrics/power/power_metrics.h"
#include "chrome/browser/metrics/power/process_metrics_recorder_util.h"
#include "chrome/browser/metrics/usage_scenario/usage_scenario.h"
#if BUILDFLAG(IS_MAC)
#include "base/metrics/histogram_functions.h"
#endif
namespace {
bool IsWithinTolerance(base::TimeDelta value,
base::TimeDelta expected,
base::TimeDelta tolerance) { … }
}
BatteryDischargeReporter::BatteryDischargeReporter(
base::BatteryStateSampler* battery_state_sampler,
UsageScenarioDataStore* battery_usage_scenario_data_store)
: … { … }
BatteryDischargeReporter::~BatteryDischargeReporter() = default;
void BatteryDischargeReporter::OnBatteryStateSampled(
const std::optional<base::BatteryLevelProvider::BatteryState>&
battery_state) { … }
void BatteryDischargeReporter::ReportOneMinuteInterval(
base::TimeDelta interval_duration,
const std::optional<base::BatteryLevelProvider::BatteryState>&
battery_state) { … }
#if BUILDFLAG(IS_WIN)
void BatteryDischargeReporter::ReportTenMinutesInterval(
base::TimeDelta interval_duration,
const std::optional<base::BatteryLevelProvider::BatteryState>&
battery_state) {
auto battery_discharge = GetBatteryDischargeDuringInterval(
ten_minutes_interval_start_battery_state_, battery_state,
interval_duration);
if (battery_discharge.mode == BatteryDischargeMode::kDischarging &&
!IsWithinTolerance(interval_duration, base::Minutes(10),
base::Seconds(1))) {
battery_discharge.mode = BatteryDischargeMode::kInvalidInterval;
}
ReportBatteryHistogramsTenMinutesInterval(interval_duration,
battery_discharge);
}
#endif
#if BUILDFLAG(IS_MAC)
void BatteryDischargeReporter::RecordIOPMPowerSourceSampleEventDelta(
base::TimeDelta sampling_event_delta) {
base::HistogramBase* histogram = base::LinearHistogram::FactoryTimeGet(
"Power.IOPMPowerSource.SamplingEventDelta",
base::Seconds(55), base::Seconds(65), 52,
base::HistogramBase::kUmaTargetedHistogramFlag);
histogram->AddTime(sampling_event_delta);
base::UmaHistogramMediumTimes(
"Power.IOPMPowerSource.SamplingEventDelta.MediumTimes",
sampling_event_delta);
}
#endif