This source file includes following definitions.
- Initialize
- InitializeForTesting
- Shutdown
- Get
- PowerChanged
- SystemResumed
- battery_discharge_rate
#include "chrome/browser/chromeos/power/power_data_collector.h"
#include "base/logging.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
namespace chromeos {
namespace {
PowerDataCollector* g_power_data_collector = NULL;
}
const int PowerDataCollector::kSampleTimeLimitSec = 24 * 60 * 60;
void PowerDataCollector::Initialize() {
CHECK(DBusThreadManager::Get());
CHECK(g_power_data_collector == NULL);
g_power_data_collector = new PowerDataCollector(true);
}
void PowerDataCollector::InitializeForTesting() {
CHECK(DBusThreadManager::Get());
CHECK(g_power_data_collector == NULL);
g_power_data_collector = new PowerDataCollector(false);
}
void PowerDataCollector::Shutdown() {
CHECK(g_power_data_collector);
delete g_power_data_collector;
g_power_data_collector = NULL;
}
PowerDataCollector* PowerDataCollector::Get() {
CHECK(g_power_data_collector);
return g_power_data_collector;
}
void PowerDataCollector::PowerChanged(
const power_manager::PowerSupplyProperties& prop) {
PowerSupplySample sample;
sample.time = base::Time::Now();
sample.external_power = (prop.external_power() !=
power_manager::PowerSupplyProperties::DISCONNECTED);
sample.battery_percent = prop.battery_percent();
sample.battery_discharge_rate = prop.battery_discharge_rate();
AddSample(&power_supply_data_, sample);
}
void PowerDataCollector::SystemResumed(const base::TimeDelta& sleep_duration) {
SystemResumedSample sample;
sample.time = base::Time::Now();
sample.sleep_duration = sleep_duration;
AddSample(&system_resumed_data_, sample);
}
PowerDataCollector::PowerDataCollector(const bool start_cpu_data_collector) {
DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
if (start_cpu_data_collector)
cpu_data_collector_.Start();
}
PowerDataCollector::~PowerDataCollector() {
DBusThreadManager* dbus_manager = DBusThreadManager::Get();
CHECK(dbus_manager);
dbus_manager->GetPowerManagerClient()->RemoveObserver(this);
}
PowerDataCollector::PowerSupplySample::PowerSupplySample()
: external_power(false),
battery_percent(0.0),
battery_discharge_rate(0.0) {
}
PowerDataCollector::SystemResumedSample::SystemResumedSample() {
}
}