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

Unified Diff: base/message_loop/message_pump_win.cc

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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
« no previous file with comments | « base/message_loop/message_pump_win.h ('k') | base/metrics/histogram.h » ('j') | 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 27b47e1a0f878cfceef3c04b2364116ca64ac4c8..cdbf0c260a9a49b773699e38b58193c00cba72e8 100644
--- a/base/message_loop/message_pump_win.cc
+++ b/base/message_loop/message_pump_win.cc
@@ -122,44 +122,8 @@ void MessagePumpForUI::ScheduleWork() {
}
void MessagePumpForUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time) {
- //
- // We would *like* to provide high resolution timers. Windows timers using
- // SetTimer() have a 10ms granularity. We have to use WM_TIMER as a wakeup
- // mechanism because the application can enter modal windows loops where it
- // is not running our MessageLoop; the only way to have our timers fire in
- // these cases is to post messages there.
- //
- // To provide sub-10ms timers, we process timers directly from our run loop.
- // For the common case, timers will be processed there as the run loop does
- // its normal work. However, we *also* set the system timer so that WM_TIMER
- // events fire. This mops up the case of timers not being able to work in
- // modal message loops. It is possible for the SetTimer to pop and have no
- // pending timers, because they could have already been processed by the
- // run loop itself.
- //
- // We use a single SetTimer corresponding to the timer that will expire
- // soonest. As new timers are created and destroyed, we update SetTimer.
- // Getting a spurrious SetTimer event firing is benign, as we'll just be
- // processing an empty timer queue.
- //
delayed_work_time_ = delayed_work_time;
-
- int delay_msec = GetCurrentDelay();
- DCHECK_GE(delay_msec, 0);
- if (delay_msec < USER_TIMER_MINIMUM)
- delay_msec = USER_TIMER_MINIMUM;
-
- // Create a WM_TIMER event that will wake us up to check for any pending
- // timers (in case we are running within a nested, external sub-pump).
- BOOL ret = SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this),
- delay_msec, NULL);
- if (ret)
- return;
- // If we can't set timers, we are in big trouble... but cross our fingers for
- // now.
- // TODO(jar): If we don't see this error, use a CHECK() here instead.
- UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR,
- MESSAGE_LOOP_PROBLEM_MAX);
+ RescheduleTimer();
}
//-----------------------------------------------------------------------------
@@ -318,6 +282,8 @@ void MessagePumpForUI::HandleWorkMessage() {
// needs to do more work.
if (state_->delegate->DoWork())
ScheduleWork();
+ state_->delegate->DoDelayedWork(&delayed_work_time_);
+ RescheduleTimer();
}
void MessagePumpForUI::HandleTimerMessage() {
@@ -330,9 +296,51 @@ void MessagePumpForUI::HandleTimerMessage() {
return;
state_->delegate->DoDelayedWork(&delayed_work_time_);
- if (!delayed_work_time_.is_null()) {
- // A bit gratuitous to set delayed_work_time_ again, but oh well.
- ScheduleDelayedWork(delayed_work_time_);
+ RescheduleTimer();
+}
+
+void MessagePumpForUI::RescheduleTimer() {
+ if (delayed_work_time_.is_null())
+ return;
+ //
+ // We would *like* to provide high resolution timers. Windows timers using
+ // SetTimer() have a 10ms granularity. We have to use WM_TIMER as a wakeup
+ // mechanism because the application can enter modal windows loops where it
+ // is not running our MessageLoop; the only way to have our timers fire in
+ // these cases is to post messages there.
+ //
+ // To provide sub-10ms timers, we process timers directly from our run loop.
+ // For the common case, timers will be processed there as the run loop does
+ // its normal work. However, we *also* set the system timer so that WM_TIMER
+ // events fire. This mops up the case of timers not being able to work in
+ // modal message loops. It is possible for the SetTimer to pop and have no
+ // pending timers, because they could have already been processed by the
+ // run loop itself.
+ //
+ // We use a single SetTimer corresponding to the timer that will expire
+ // soonest. As new timers are created and destroyed, we update SetTimer.
+ // Getting a spurrious SetTimer event firing is benign, as we'll just be
+ // processing an empty timer queue.
+ //
+ int delay_msec = GetCurrentDelay();
+ DCHECK_GE(delay_msec, 0);
+ if (delay_msec == 0) {
+ ScheduleWork();
+ } else {
+ if (delay_msec < USER_TIMER_MINIMUM)
+ delay_msec = USER_TIMER_MINIMUM;
+
+ // Create a WM_TIMER event that will wake us up to check for any pending
+ // timers (in case we are running within a nested, external sub-pump).
+ BOOL ret = SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this),
+ delay_msec, NULL);
+ if (ret)
+ return;
+ // If we can't set timers, we are in big trouble... but cross our fingers
+ // for now.
+ // TODO(jar): If we don't see this error, use a CHECK() here instead.
+ UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR,
+ MESSAGE_LOOP_PROBLEM_MAX);
}
}
@@ -364,11 +372,6 @@ bool MessagePumpForUI::ProcessNextWindowsMessage() {
}
bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) {
- // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
- tracked_objects::ScopedTracker tracking_profile1(
- FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "440919 MessagePumpForUI::ProcessMessageHelper1"));
-
TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper",
"message", msg.message);
if (WM_QUIT == msg.message) {
@@ -383,19 +386,9 @@ bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) {
if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_)
return ProcessPumpReplacementMessage();
- // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
- tracked_objects::ScopedTracker tracking_profile2(
- FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "440919 MessagePumpForUI::ProcessMessageHelper2"));
-
if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode))
return true;
- // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
- tracked_objects::ScopedTracker tracking_profile3(
- FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "440919 MessagePumpForUI::ProcessMessageHelper3"));
-
uint32_t action = MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT;
if (state_->dispatcher) {
// TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
@@ -408,18 +401,7 @@ bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) {
if (action & MessagePumpDispatcher::POST_DISPATCH_QUIT_LOOP)
state_->should_quit = true;
if (action & MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT) {
- // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
- tracked_objects::ScopedTracker tracking_profile5(
- FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "440919 MessagePumpForUI::ProcessMessageHelper5"));
-
TranslateMessage(&msg);
-
- // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
- tracked_objects::ScopedTracker tracking_profile6(
- FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "440919 MessagePumpForUI::ProcessMessageHelper6"));
-
DispatchMessage(&msg);
}
« no previous file with comments | « base/message_loop/message_pump_win.h ('k') | base/metrics/histogram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698