1 // Copyright (c) 2011 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 "base/hi_res_timer_manager.h"
7 #include "base/power_monitor/power_monitor.h"
10 HighResolutionTimerManager::HighResolutionTimerManager()
11 : hi_res_clock_available_(false) {
12 base::PowerMonitor
* power_monitor
= base::PowerMonitor::Get();
13 power_monitor
->AddObserver(this);
14 UseHiResClock(!power_monitor
->BatteryPower());
17 HighResolutionTimerManager::~HighResolutionTimerManager() {
18 base::PowerMonitor::Get()->RemoveObserver(this);
22 void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power
) {
23 UseHiResClock(!on_battery_power
);
26 void HighResolutionTimerManager::UseHiResClock(bool use
) {
27 if (use
== hi_res_clock_available_
)
29 hi_res_clock_available_
= use
;
30 base::Time::EnableHighResolutionTimer(use
);