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"
9 HighResolutionTimerManager::HighResolutionTimerManager()
10 : hi_res_clock_available_(false) {
11 base::SystemMonitor
* system_monitor
= base::SystemMonitor::Get();
12 system_monitor
->AddPowerObserver(this);
13 UseHiResClock(!system_monitor
->BatteryPower());
16 HighResolutionTimerManager::~HighResolutionTimerManager() {
17 base::SystemMonitor::Get()->RemovePowerObserver(this);
21 void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power
) {
22 UseHiResClock(!on_battery_power
);
25 void HighResolutionTimerManager::UseHiResClock(bool use
) {
26 if (use
== hi_res_clock_available_
)
28 hi_res_clock_available_
= use
;
29 base::Time::EnableHighResolutionTimer(use
);