diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-26 19:48:34 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-26 19:48:34 +0000 |
commit | 097ae5a93a863b604fd6dbd939bed0c2be1afed2 (patch) | |
tree | 61177362b1c1bd2d1b2438acc50ccb2c061b176e /app/hi_res_timer_manager_win.cc | |
parent | 902c971382790170852fe5b5d22d1b79adb31056 (diff) | |
download | chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.zip chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.tar.gz chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.tar.bz2 |
Make SystemMonitor not a Singleton and move it out of base
SystemMonitor makes an assumption that through its lifetime a MessageLoop exists and stays the same. It is difficult and error-prone to satisfy that when it is a Singleton. It has caused problems in the past.
Additionally, extract HighResoltionTimerManager out of time_win.cc, eliminating yet another Singleton.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/431008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/hi_res_timer_manager_win.cc')
-rw-r--r-- | app/hi_res_timer_manager_win.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/hi_res_timer_manager_win.cc b/app/hi_res_timer_manager_win.cc new file mode 100644 index 0000000..b7cee1d --- /dev/null +++ b/app/hi_res_timer_manager_win.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "app/hi_res_timer_manager.h" + +#include "base/time.h" + +HighResolutionTimerManager::HighResolutionTimerManager() + : hi_res_clock_used_(false) { + SystemMonitor* system_monitor = SystemMonitor::Get(); + system_monitor->AddObserver(this); + UseHiResClock(!system_monitor->BatteryPower()); +} + +HighResolutionTimerManager::~HighResolutionTimerManager() { + SystemMonitor::Get()->RemoveObserver(this); + UseHiResClock(false); +} + +void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) { + UseHiResClock(!on_battery_power); +} + +void HighResolutionTimerManager::UseHiResClock(bool use) { + if (use == hi_res_clock_used_) + return; + bool result = base::Time::UseHighResolutionTimer(use); + DCHECK(result); + hi_res_clock_used_ = use; +} |