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 <math.h> | 7 #include <math.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 DCHECK(atom_); | 213 DCHECK(atom_); |
| 214 | 214 |
| 215 message_hwnd_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, | 215 message_hwnd_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, |
| 216 HWND_MESSAGE, 0, instance, 0); | 216 HWND_MESSAGE, 0, instance, 0); |
| 217 DCHECK(message_hwnd_); | 217 DCHECK(message_hwnd_); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void MessagePumpForUI::WaitForWork() { | 220 void MessagePumpForUI::WaitForWork() { |
| 221 // Wait until a message is available, up to the time needed by the timer | 221 // Wait until a message is available, up to the time needed by the timer |
| 222 // manager to fire the next set of timers. | 222 // manager to fire the next set of timers. |
| 223 int delay = GetCurrentDelay(); | 223 int delay; |
| 224 if (delay < 0) // Negative value means no timers waiting. | 224 DWORD wait_flags = MWMO_INPUTAVAILABLE; |
| 225 delay = INFINITE; | |
| 226 | 225 |
| 227 DWORD result; | 226 while ((delay = GetCurrentDelay()) != 0) { |
|
danakj
2016/05/11 01:13:36
The old code when delay was 0 would call MsgWaitFo
stanisc
2016/05/11 01:46:41
You are right. This is a suble difference with the
| |
| 228 result = MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT, | 227 if (delay < 0) // Negative value means no timers waiting. |
| 229 MWMO_INPUTAVAILABLE); | 228 delay = INFINITE; |
| 230 | 229 |
| 231 if (WAIT_OBJECT_0 == result) { | 230 DWORD result = |
| 232 // A WM_* message is available. | 231 MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT, wait_flags); |
| 233 // If a parent child relationship exists between windows across threads | 232 |
| 234 // then their thread inputs are implicitly attached. | 233 if (WAIT_OBJECT_0 == result) { |
| 235 // This causes the MsgWaitForMultipleObjectsEx API to return indicating | 234 // A WM_* message is available. |
| 236 // that messages are ready for processing (Specifically, mouse messages | 235 // If a parent child relationship exists between windows across threads |
| 237 // intended for the child window may appear if the child window has | 236 // then their thread inputs are implicitly attached. |
| 238 // capture). | 237 // This causes the MsgWaitForMultipleObjectsEx API to return indicating |
| 239 // The subsequent PeekMessages call may fail to return any messages thus | 238 // that messages are ready for processing (Specifically, mouse messages |
| 240 // causing us to enter a tight loop at times. | 239 // intended for the child window may appear if the child window has |
| 241 // The WaitMessage call below is a workaround to give the child window | 240 // capture). |
| 242 // some time to process its input messages. | 241 // The subsequent PeekMessages call may fail to return any messages thus |
| 243 MSG msg = {0}; | 242 // causing us to enter a tight loop at times. |
| 244 bool has_pending_sent_message = | 243 // The code below is a workaround to give the child window |
| 245 (HIWORD(GetQueueStatus(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0; | 244 // some time to process its input messages by looping back to |
| 246 if (!has_pending_sent_message && | 245 // MsgWaitForMultipleObjectsEx above when there are no messages for the |
| 247 !PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { | 246 // current thread. |
| 248 WaitMessage(); | 247 MSG msg = {0}; |
| 248 bool has_pending_sent_message = | |
| 249 (HIWORD(GetQueueStatus(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0; | |
| 250 if (has_pending_sent_message || | |
| 251 PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { | |
| 252 return; | |
| 253 } | |
| 254 | |
| 255 // We know there are no more messages for this thread because PeekMessage | |
| 256 // has returned false. Reset |wait_flags| so that we wait for a *new* | |
| 257 // message. | |
| 258 wait_flags = 0; | |
| 249 } | 259 } |
| 250 return; | 260 |
| 261 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); | |
| 251 } | 262 } |
| 252 | |
| 253 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); | |
| 254 } | 263 } |
| 255 | 264 |
| 256 void MessagePumpForUI::HandleWorkMessage() { | 265 void MessagePumpForUI::HandleWorkMessage() { |
| 257 // If we are being called outside of the context of Run, then don't try to do | 266 // If we are being called outside of the context of Run, then don't try to do |
| 258 // any work. This could correspond to a MessageBox call or something of that | 267 // any work. This could correspond to a MessageBox call or something of that |
| 259 // sort. | 268 // sort. |
| 260 if (!state_) { | 269 if (!state_) { |
| 261 // Since we handled a kMsgHaveWork message, we must still update this flag. | 270 // Since we handled a kMsgHaveWork message, we must still update this flag. |
| 262 InterlockedExchange(&have_work_, 0); | 271 InterlockedExchange(&have_work_, 0); |
| 263 return; | 272 return; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 | 650 |
| 642 // static | 651 // static |
| 643 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 652 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
| 644 ULONG_PTR key, | 653 ULONG_PTR key, |
| 645 bool* has_valid_io_context) { | 654 bool* has_valid_io_context) { |
| 646 *has_valid_io_context = ((key & 1) == 0); | 655 *has_valid_io_context = ((key & 1) == 0); |
| 647 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 656 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
| 648 } | 657 } |
| 649 | 658 |
| 650 } // namespace base | 659 } // namespace base |
| OLD | NEW |