| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "base/hi_res_timer_manager.h" | |
| 6 | |
| 7 #include "base/power_monitor/power_monitor.h" | |
| 8 #include "base/time.h" | |
| 9 | |
| 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()); | |
| 15 } | |
| 16 | |
| 17 HighResolutionTimerManager::~HighResolutionTimerManager() { | |
| 18 base::PowerMonitor::Get()->RemoveObserver(this); | |
| 19 UseHiResClock(false); | |
| 20 } | |
| 21 | |
| 22 void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) { | |
| 23 UseHiResClock(!on_battery_power); | |
| 24 } | |
| 25 | |
| 26 void HighResolutionTimerManager::UseHiResClock(bool use) { | |
| 27 if (use == hi_res_clock_available_) | |
| 28 return; | |
| 29 hi_res_clock_available_ = use; | |
| 30 base::Time::EnableHighResolutionTimer(use); | |
| 31 } | |
| OLD | NEW |