summaryrefslogtreecommitdiffstats
path: root/base/message_loop.h
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 04:58:15 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 04:58:15 +0000
commit57f030a503ed96f974a4edcb8c65c982ea8fd765 (patch)
tree07036d200a6f22c529fda6db035e874ef7f5f3d5 /base/message_loop.h
parent13729e7753dfdaf4cc90f5050827a8ebc9875390 (diff)
downloadchromium_src-57f030a503ed96f974a4edcb8c65c982ea8fd765.zip
chromium_src-57f030a503ed96f974a4edcb8c65c982ea8fd765.tar.gz
chromium_src-57f030a503ed96f974a4edcb8c65c982ea8fd765.tar.bz2
Change chrome from statically enabling high resolution timers on windows
to enabling them dynamically - only when the application really needs them. I am working on some test cases for this, and will add them. But wanted to send out the concept for review. In this implementation, I modify the message loop to detect when the application has requested high resolution timers. Note that there are multiple MessageLoops active in a single process. After a period of time, we simply shut it off again. We could have set a timer or kept a count of active timers, or any number of more complex algorithms. But I think this algorithm is very simple and good enough. If an application continues needing high resolution timers for more than 1s, we'll turn the high-resolution timers back on again. One last change - since we've implemented the clamp at 4ms, there isn't a lot of point to our use of 1ms for timeBeginPeriod. I've modified that to 2 (which is half of 4ms, our target minimal interval). BUG=46531 TEST=MessageLoop.HighResolutionTimers Review URL: http://codereview.chromium.org/2822035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop.h')
-rw-r--r--base/message_loop.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/base/message_loop.h b/base/message_loop.h
index 8b4be7c..8deacec 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -287,6 +287,20 @@ class MessageLoop : public base::MessagePump::Delegate {
typedef base::MessagePumpForUI::Observer Observer;
#endif
+ // Returns true if the message loop has high resolution timers enabled.
+ // Provided for testing.
+ bool high_resolution_timers_enabled() {
+#if defined(OS_WIN)
+ return !high_resolution_timer_expiration_.is_null();
+#else
+ return true;
+#endif
+ }
+
+ // When we go into high resolution timer mode, we will stay in hi-res mode
+ // for at least 1s.
+ static const int kHighResolutionTimerModeLeaseTimeMs = 1000;
+
//----------------------------------------------------------------------------
protected:
struct RunState {
@@ -454,6 +468,10 @@ class MessageLoop : public base::MessagePump::Delegate {
RunState* state_;
+#if defined(OS_WIN)
+ base::TimeTicks high_resolution_timer_expiration_;
+#endif
+
// The next sequence number to use for delayed tasks.
int next_sequence_num_;