Index: base/time_win.cc |
diff --git a/base/time_win.cc b/base/time_win.cc |
index 9fdcab16042f69507968bd0d7ba58e00ea4a997b..eedf468ff0172ae4f6203c10e488cb33e64f3712 100644 |
--- a/base/time_win.cc |
+++ b/base/time_win.cc |
@@ -45,7 +45,6 @@ |
#include "base/logging.h" |
#include "base/cpu.h" |
#include "base/singleton.h" |
-#include "base/system_monitor.h" |
using base::Time; |
using base::TimeDelta; |
@@ -88,65 +87,6 @@ void InitializeClock() { |
initial_time = CurrentWallclockMicroseconds(); |
} |
-class HighResolutionTimerManager : public base::SystemMonitor::PowerObserver { |
- public: |
- ~HighResolutionTimerManager() { |
- StopMonitoring(); |
- UseHiResClock(false); |
- } |
- |
- void Enable() { |
- StopMonitoring(); |
- UseHiResClock(true); |
- } |
- |
- void StartMonitoring() { |
- if (is_monitoring_) |
- return; |
- is_monitoring_ = true; |
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); |
- system_monitor->AddObserver(this); |
- UseHiResClock(!system_monitor->BatteryPower()); |
- } |
- |
- void StopMonitoring() { |
- if (!is_monitoring_) |
- return; |
- is_monitoring_ = false; |
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); |
- if (system_monitor) |
- system_monitor->RemoveObserver(this); |
- } |
- |
- // Interfaces for monitoring Power changes. |
- void OnPowerStateChange(bool on_battery_power) { |
- UseHiResClock(!on_battery_power); |
- } |
- |
- private: |
- HighResolutionTimerManager() |
- : is_monitoring_(false), |
- hi_res_clock_enabled_(false) { |
- } |
- friend struct DefaultSingletonTraits<HighResolutionTimerManager>; |
- |
- // Enable or disable the faster multimedia timer. |
- void UseHiResClock(bool enabled) { |
- if (enabled == hi_res_clock_enabled_) |
- return; |
- if (enabled) |
- timeBeginPeriod(1); |
- else |
- timeEndPeriod(1); |
- hi_res_clock_enabled_ = enabled; |
- } |
- |
- bool is_monitoring_; |
- bool hi_res_clock_enabled_; |
- |
- DISALLOW_COPY_AND_ASSIGN(HighResolutionTimerManager); |
-}; |
- |
} // namespace |
// Time ----------------------------------------------------------------------- |
@@ -208,13 +148,18 @@ FILETIME Time::ToFileTime() const { |
} |
// static |
-void Time::StartSystemMonitorObserver() { |
- Singleton<HighResolutionTimerManager>()->StartMonitoring(); |
-} |
- |
-// static |
-void Time::EnableHiResClockForTests() { |
- Singleton<HighResolutionTimerManager>()->Enable(); |
+bool Time::UseHighResolutionTimer(bool use) { |
+ // TODO(mbelshe): Make sure that switching the system timer resolution |
+ // doesn't break Timer firing order etc. An example test would be to have |
+ // two threads. One would have a bunch of timers, and another would turn the |
+ // high resolution timer on and off. |
+ |
+ MMRESULT result; |
+ if (use) |
+ result = timeBeginPeriod(1); |
+ else |
+ result = timeEndPeriod(1); |
+ return (result == TIMERR_NOERROR); |
} |
// static |