| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/timer/hi_res_timer_manager.h" | 5 #include "base/timer/hi_res_timer_manager.h" |
| 6 | 6 |
| 7 #include "base/power_monitor/power_monitor.h" | 7 #include "base/power_monitor/power_monitor.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| 11 | 11 |
| 12 HighResolutionTimerManager::HighResolutionTimerManager() | 12 HighResolutionTimerManager::HighResolutionTimerManager() |
| 13 : hi_res_clock_available_(false) { | 13 : hi_res_clock_available_(false) { |
| 14 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 14 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
| 15 power_monitor->AddObserver(this); | 15 power_monitor->AddObserver(this); |
| 16 UseHiResClock(!power_monitor->BatteryPower()); | 16 UseHiResClock(!power_monitor->IsOnBatteryPower()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 HighResolutionTimerManager::~HighResolutionTimerManager() { | 19 HighResolutionTimerManager::~HighResolutionTimerManager() { |
| 20 base::PowerMonitor::Get()->RemoveObserver(this); | 20 base::PowerMonitor::Get()->RemoveObserver(this); |
| 21 UseHiResClock(false); | 21 UseHiResClock(false); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) { | 24 void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) { |
| 25 UseHiResClock(!on_battery_power); | 25 UseHiResClock(!on_battery_power); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void HighResolutionTimerManager::UseHiResClock(bool use) { | 28 void HighResolutionTimerManager::UseHiResClock(bool use) { |
| 29 if (use == hi_res_clock_available_) | 29 if (use == hi_res_clock_available_) |
| 30 return; | 30 return; |
| 31 hi_res_clock_available_ = use; | 31 hi_res_clock_available_ = use; |
| 32 base::Time::EnableHighResolutionTimer(use); | 32 base::Time::EnableHighResolutionTimer(use); |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace base | 35 } // namespace base |
| OLD | NEW |