Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4059)

Unified Diff: base/time_win.cc

Issue 431008: Make SystemMonitor not a Singleton and move it out of base (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: fix ChromeFrame build Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698