OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_pump_win.h" | 5 #include "base/message_pump_win.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
| 9 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
10 #include "base/win/wrapped_window_proc.h" | 11 #include "base/win/wrapped_window_proc.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 | 14 |
14 static const wchar_t kWndClass[] = L"Chrome_MessagePumpWindow"; | 15 static const wchar_t kWndClass[] = L"Chrome_MessagePumpWindow"; |
15 | 16 |
16 // Message sent to get an additional time slice for pumping (processing) another | 17 // Message sent to get an additional time slice for pumping (processing) another |
17 // task (a series of such messages creates a continuous task pump). | 18 // task (a series of such messages creates a continuous task pump). |
18 static const int kMsgHaveWork = WM_USER + 1; | 19 static const int kMsgHaveWork = WM_USER + 1; |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 bool MessagePumpForUI::ProcessPumpReplacementMessage() { | 365 bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
365 // When we encounter a kMsgHaveWork message, this method is called to peek | 366 // When we encounter a kMsgHaveWork message, this method is called to peek |
366 // and process a replacement message, such as a WM_PAINT or WM_TIMER. The | 367 // and process a replacement message, such as a WM_PAINT or WM_TIMER. The |
367 // goal is to make the kMsgHaveWork as non-intrusive as possible, even though | 368 // goal is to make the kMsgHaveWork as non-intrusive as possible, even though |
368 // a continuous stream of such messages are posted. This method carefully | 369 // a continuous stream of such messages are posted. This method carefully |
369 // peeks a message while there is no chance for a kMsgHaveWork to be pending, | 370 // peeks a message while there is no chance for a kMsgHaveWork to be pending, |
370 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to | 371 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to |
371 // possibly be posted), and finally dispatches that peeked replacement. Note | 372 // possibly be posted), and finally dispatches that peeked replacement. Note |
372 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! | 373 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! |
373 | 374 |
| 375 bool have_message = false; |
374 MSG msg; | 376 MSG msg; |
375 bool have_message = (0 != PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)); | 377 // We should not process all window messages if we are in the context of an |
| 378 // OS modal loop, i.e. in the context of a windows API call like MessageBox. |
| 379 // This is to ensure that these messages are peeked out by the OS modal loop. |
| 380 if (MessageLoop::current()->os_modal_loop()) { |
| 381 // We only peek out WM_PAINT and WM_TIMER here for reasons mentioned above. |
| 382 have_message = PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) || |
| 383 PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE); |
| 384 } else { |
| 385 have_message = (0 != PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)); |
| 386 } |
| 387 |
376 DCHECK(!have_message || kMsgHaveWork != msg.message || | 388 DCHECK(!have_message || kMsgHaveWork != msg.message || |
377 msg.hwnd != message_hwnd_); | 389 msg.hwnd != message_hwnd_); |
378 | 390 |
379 // Since we discarded a kMsgHaveWork message, we must update the flag. | 391 // Since we discarded a kMsgHaveWork message, we must update the flag. |
380 int old_have_work = InterlockedExchange(&have_work_, 0); | 392 int old_have_work = InterlockedExchange(&have_work_, 0); |
381 DCHECK(old_have_work); | 393 DCHECK(old_have_work); |
382 | 394 |
383 // We don't need a special time slice if we didn't have_message to process. | 395 // We don't need a special time slice if we didn't have_message to process. |
384 if (!have_message) | 396 if (!have_message) |
385 return false; | 397 return false; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 | 574 |
563 void MessagePumpForIO::WillProcessIOEvent() { | 575 void MessagePumpForIO::WillProcessIOEvent() { |
564 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent()); | 576 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent()); |
565 } | 577 } |
566 | 578 |
567 void MessagePumpForIO::DidProcessIOEvent() { | 579 void MessagePumpForIO::DidProcessIOEvent() { |
568 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent()); | 580 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent()); |
569 } | 581 } |
570 | 582 |
571 } // namespace base | 583 } // namespace base |
OLD | NEW |