Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop/message_pump_win.h" | 5 #include "base/message_loop/message_pump_win.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <math.h> | 8 #include <math.h> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 // | 139 // |
| 140 // We use a single SetTimer corresponding to the timer that will expire | 140 // We use a single SetTimer corresponding to the timer that will expire |
| 141 // soonest. As new timers are created and destroyed, we update SetTimer. | 141 // soonest. As new timers are created and destroyed, we update SetTimer. |
| 142 // Getting a spurrious SetTimer event firing is benign, as we'll just be | 142 // Getting a spurrious SetTimer event firing is benign, as we'll just be |
| 143 // processing an empty timer queue. | 143 // processing an empty timer queue. |
| 144 // | 144 // |
| 145 delayed_work_time_ = delayed_work_time; | 145 delayed_work_time_ = delayed_work_time; |
| 146 | 146 |
| 147 int delay_msec = GetCurrentDelay(); | 147 int delay_msec = GetCurrentDelay(); |
| 148 DCHECK_GE(delay_msec, 0); | 148 DCHECK_GE(delay_msec, 0); |
| 149 if (delay_msec < USER_TIMER_MINIMUM) | 149 if (delay_msec == 0) { |
| 150 delay_msec = USER_TIMER_MINIMUM; | 150 ScheduleWork(); |
| 151 } else { | |
| 152 if (delay_msec < USER_TIMER_MINIMUM) | |
| 153 delay_msec = USER_TIMER_MINIMUM; | |
| 151 | 154 |
| 152 // Create a WM_TIMER event that will wake us up to check for any pending | 155 // Create a WM_TIMER event that will wake us up to check for any pending |
| 153 // timers (in case we are running within a nested, external sub-pump). | 156 // timers (in case we are running within a nested, external sub-pump). |
| 154 BOOL ret = SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this), | 157 BOOL ret = SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this), |
| 155 delay_msec, NULL); | 158 delay_msec, NULL); |
| 156 if (ret) | 159 if (ret) |
| 157 return; | 160 return; |
| 158 // If we can't set timers, we are in big trouble... but cross our fingers for | 161 // If we can't set timers, we are in big trouble... but cross our fingers |
| 159 // now. | 162 // for now. |
| 160 // TODO(jar): If we don't see this error, use a CHECK() here instead. | 163 // TODO(jar): If we don't see this error, use a CHECK() here instead. |
| 161 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR, | 164 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", SET_TIMER_ERROR, |
| 162 MESSAGE_LOOP_PROBLEM_MAX); | 165 MESSAGE_LOOP_PROBLEM_MAX); |
| 166 } | |
| 163 } | 167 } |
| 164 | 168 |
| 165 //----------------------------------------------------------------------------- | 169 //----------------------------------------------------------------------------- |
| 166 // MessagePumpForUI private: | 170 // MessagePumpForUI private: |
| 167 | 171 |
| 168 // static | 172 // static |
| 169 LRESULT CALLBACK MessagePumpForUI::WndProcThunk( | 173 LRESULT CALLBACK MessagePumpForUI::WndProcThunk( |
| 170 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { | 174 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { |
| 171 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. | 175 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
| 172 tracked_objects::ScopedTracker tracking_profile1( | 176 tracked_objects::ScopedTracker tracking_profile1( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 | 315 |
| 312 // Let whatever would have run had we not been putting messages in the queue | 316 // Let whatever would have run had we not been putting messages in the queue |
| 313 // run now. This is an attempt to make our dummy message not starve other | 317 // run now. This is an attempt to make our dummy message not starve other |
| 314 // messages that may be in the Windows message queue. | 318 // messages that may be in the Windows message queue. |
| 315 ProcessPumpReplacementMessage(); | 319 ProcessPumpReplacementMessage(); |
| 316 | 320 |
| 317 // Now give the delegate a chance to do some work. He'll let us know if he | 321 // Now give the delegate a chance to do some work. He'll let us know if he |
| 318 // needs to do more work. | 322 // needs to do more work. |
| 319 if (state_->delegate->DoWork()) | 323 if (state_->delegate->DoWork()) |
| 320 ScheduleWork(); | 324 ScheduleWork(); |
| 325 state_->delegate->DoDelayedWork(&delayed_work_time_); | |
|
jar (doing other things)
2015/05/13 20:01:21
Note that you *might* effectively double the amoun
| |
| 326 if (!delayed_work_time_.is_null()) { | |
| 327 // A bit gratuitous to set delayed_work_time_ again, but oh well. | |
| 328 ScheduleDelayedWork(delayed_work_time_); | |
| 329 } | |
| 321 } | 330 } |
| 322 | 331 |
| 323 void MessagePumpForUI::HandleTimerMessage() { | 332 void MessagePumpForUI::HandleTimerMessage() { |
| 324 KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this)); | 333 KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this)); |
| 325 | 334 |
| 326 // If we are being called outside of the context of Run, then don't do | 335 // If we are being called outside of the context of Run, then don't do |
| 327 // anything. This could correspond to a MessageBox call or something of | 336 // anything. This could correspond to a MessageBox call or something of |
| 328 // that sort. | 337 // that sort. |
| 329 if (!state_) | 338 if (!state_) |
| 330 return; | 339 return; |
| 331 | 340 |
| 332 state_->delegate->DoDelayedWork(&delayed_work_time_); | 341 state_->delegate->DoDelayedWork(&delayed_work_time_); |
| 333 if (!delayed_work_time_.is_null()) { | 342 if (!delayed_work_time_.is_null()) { |
| 334 // A bit gratuitous to set delayed_work_time_ again, but oh well. | 343 // A bit gratuitous to set delayed_work_time_ again, but oh well. |
|
jar (doing other things)
2015/05/13 20:01:21
The CL is plausible.... but I'm not a fan of repli
jbauman
2015/05/20 01:31:35
Ok, refactored out the timer rescheduling logic to
| |
| 335 ScheduleDelayedWork(delayed_work_time_); | 344 ScheduleDelayedWork(delayed_work_time_); |
| 336 } | 345 } |
| 337 } | 346 } |
| 338 | 347 |
| 339 bool MessagePumpForUI::ProcessNextWindowsMessage() { | 348 bool MessagePumpForUI::ProcessNextWindowsMessage() { |
| 340 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. | 349 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
| 341 tracked_objects::ScopedTracker tracking_profile1( | 350 tracked_objects::ScopedTracker tracking_profile1( |
| 342 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 351 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 343 "440919 MessagePumpForUI::ProcessNextWindowsMessage1")); | 352 "440919 MessagePumpForUI::ProcessNextWindowsMessage1")); |
| 344 | 353 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 | 699 |
| 691 // static | 700 // static |
| 692 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 701 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
| 693 ULONG_PTR key, | 702 ULONG_PTR key, |
| 694 bool* has_valid_io_context) { | 703 bool* has_valid_io_context) { |
| 695 *has_valid_io_context = ((key & 1) == 0); | 704 *has_valid_io_context = ((key & 1) == 0); |
| 696 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 705 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
| 697 } | 706 } |
| 698 | 707 |
| 699 } // namespace base | 708 } // namespace base |
| OLD | NEW |