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