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

Unified Diff: base/message_loop/message_pump_win.cc

Issue 873393004: [Windows] Fix for Browser IO MessageLoop spinning the CPU. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move constant out of platform-specific region of file. Created 5 years, 11 months 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
« base/message_loop/message_loop.cc ('K') | « base/message_loop/message_loop.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_pump_win.cc
diff --git a/base/message_loop/message_pump_win.cc b/base/message_loop/message_pump_win.cc
index a7a14859280f81d63015ab8bb99f8346551079d3..bfc1d51e59b04cb76ee7d61e6ee541082a810f02 100644
--- a/base/message_loop/message_pump_win.cc
+++ b/base/message_loop/message_pump_win.cc
@@ -4,6 +4,7 @@
#include "base/message_loop/message_pump_win.h"
+#include <limits>
#include <math.h>
#include "base/debug/trace_event.h"
@@ -70,12 +71,13 @@ int MessagePumpWin::GetCurrentDelay() const {
double timeout =
ceil((delayed_work_time_ - TimeTicks::Now()).InMillisecondsF());
- // If this value is negative, then we need to run delayed work soon.
- int delay = static_cast<int>(timeout);
- if (delay < 0)
- delay = 0;
-
- return delay;
+ // Range check the |timeout| while converting to an integer. If the |timeout|
+ // is negative, then we need to run delayed work soon. If the |timeout| is
+ // "overflowingly" large, that means a delayed task was posted with a
+ // super-long delay.
+ return timeout < 0 ? 0 :
+ (timeout > std::numeric_limits<int>::max() ?
darin (slow to review) 2015/01/27 07:52:39 you didn't want to use the max_int / 2 comparison
+ std::numeric_limits<int>::max() : static_cast<int>(timeout));
}
//-----------------------------------------------------------------------------
« base/message_loop/message_loop.cc ('K') | « base/message_loop/message_loop.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698