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> |
11 | 11 |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
14 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
15 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
16 #include "base/win/current_module.h" | 15 #include "base/win/current_module.h" |
17 #include "base/win/wrapped_window_proc.h" | 16 #include "base/win/wrapped_window_proc.h" |
18 | 17 |
19 namespace base { | 18 namespace base { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) | 377 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) |
379 return true; | 378 return true; |
380 | 379 |
381 TranslateMessage(&msg); | 380 TranslateMessage(&msg); |
382 DispatchMessage(&msg); | 381 DispatchMessage(&msg); |
383 | 382 |
384 return true; | 383 return true; |
385 } | 384 } |
386 | 385 |
387 bool MessagePumpForUI::ProcessPumpReplacementMessage() { | 386 bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
388 // When we encounter a kMsgHaveWork message, this method is called to peek | 387 // When we encounter a kMsgHaveWork message, this method is called to peek and |
389 // and process a replacement message, such as a WM_PAINT or WM_TIMER. The | 388 // process a replacement message. The goal is to make the kMsgHaveWork as non- |
390 // goal is to make the kMsgHaveWork as non-intrusive as possible, even though | 389 // intrusive as possible, even though a continuous stream of such messages are |
391 // a continuous stream of such messages are posted. This method carefully | 390 // posted. This method carefully peeks a message while there is no chance for |
392 // peeks a message while there is no chance for a kMsgHaveWork to be pending, | 391 // a kMsgHaveWork to be pending, then resets the |have_work_| flag (allowing a |
393 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to | 392 // replacement kMsgHaveWork to possibly be posted), and finally dispatches |
394 // possibly be posted), and finally dispatches that peeked replacement. Note | 393 // that peeked replacement. Note that the re-post of kMsgHaveWork may be |
395 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! | 394 // asynchronous to this thread!! |
396 | 395 |
397 bool have_message = false; | |
398 MSG msg; | 396 MSG msg; |
399 // We should not process all window messages if we are in the context of an | 397 const bool have_message = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE; |
400 // OS modal loop, i.e. in the context of a windows API call like MessageBox. | |
401 // This is to ensure that these messages are peeked out by the OS modal loop. | |
402 if (MessageLoop::current()->os_modal_loop()) { | |
403 // We only peek out WM_PAINT and WM_TIMER here for reasons mentioned above. | |
404 have_message = PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) || | |
405 PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE); | |
406 } else { | |
407 have_message = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE; | |
408 } | |
409 | 398 |
| 399 // Expect no message or a message different than kMsgHaveWork. |
410 DCHECK(!have_message || kMsgHaveWork != msg.message || | 400 DCHECK(!have_message || kMsgHaveWork != msg.message || |
411 msg.hwnd != message_hwnd_); | 401 msg.hwnd != message_hwnd_); |
412 | 402 |
413 // Since we discarded a kMsgHaveWork message, we must update the flag. | 403 // Since we discarded a kMsgHaveWork message, we must update the flag. |
414 int old_have_work = InterlockedExchange(&have_work_, 0); | 404 int old_have_work = InterlockedExchange(&have_work_, 0); |
415 DCHECK(old_have_work); | 405 DCHECK(old_have_work); |
416 | 406 |
417 // We don't need a special time slice if we didn't have_message to process. | 407 // We don't need a special time slice if we didn't have_message to process. |
418 if (!have_message) | 408 if (!have_message) |
419 return false; | 409 return false; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 if (!filter || it->handler == filter) { | 587 if (!filter || it->handler == filter) { |
598 *item = *it; | 588 *item = *it; |
599 completed_io_.erase(it); | 589 completed_io_.erase(it); |
600 return true; | 590 return true; |
601 } | 591 } |
602 } | 592 } |
603 return false; | 593 return false; |
604 } | 594 } |
605 | 595 |
606 } // namespace base | 596 } // namespace base |
OLD | NEW |