| 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 17 matching lines...) Expand all Loading... |
| 28 RECEIVED_WM_QUIT_ERROR, | 28 RECEIVED_WM_QUIT_ERROR, |
| 29 MESSAGE_LOOP_PROBLEM_MAX, | 29 MESSAGE_LOOP_PROBLEM_MAX, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 // Message sent to get an additional time slice for pumping (processing) another | 34 // Message sent to get an additional time slice for pumping (processing) another |
| 35 // task (a series of such messages creates a continuous task pump). | 35 // task (a series of such messages creates a continuous task pump). |
| 36 static const int kMsgHaveWork = WM_USER + 1; | 36 static const int kMsgHaveWork = WM_USER + 1; |
| 37 | 37 |
| 38 // The application-defined code passed to the hook procedure. | |
| 39 static const int kMessageFilterCode = 0x5001; | |
| 40 | |
| 41 //----------------------------------------------------------------------------- | 38 //----------------------------------------------------------------------------- |
| 42 // MessagePumpWin public: | 39 // MessagePumpWin public: |
| 43 | 40 |
| 44 MessagePumpWin::MessagePumpWin() = default; | 41 MessagePumpWin::MessagePumpWin() = default; |
| 45 | 42 |
| 46 void MessagePumpWin::Run(Delegate* delegate) { | 43 void MessagePumpWin::Run(Delegate* delegate) { |
| 47 RunState s; | 44 RunState s; |
| 48 s.delegate = delegate; | 45 s.delegate = delegate; |
| 49 s.should_quit = false; | 46 s.should_quit = false; |
| 50 s.run_depth = state_ ? state_->run_depth + 1 : 1; | 47 s.run_depth = state_ ? state_->run_depth + 1 : 1; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // GetMessage() loop. | 352 // GetMessage() loop. |
| 356 state_->should_quit = true; | 353 state_->should_quit = true; |
| 357 PostQuitMessage(static_cast<int>(msg.wParam)); | 354 PostQuitMessage(static_cast<int>(msg.wParam)); |
| 358 return false; | 355 return false; |
| 359 } | 356 } |
| 360 | 357 |
| 361 // While running our main message pump, we discard kMsgHaveWork messages. | 358 // While running our main message pump, we discard kMsgHaveWork messages. |
| 362 if (msg.message == kMsgHaveWork && msg.hwnd == message_window_.hwnd()) | 359 if (msg.message == kMsgHaveWork && msg.hwnd == message_window_.hwnd()) |
| 363 return ProcessPumpReplacementMessage(); | 360 return ProcessPumpReplacementMessage(); |
| 364 | 361 |
| 365 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) | |
| 366 return true; | |
| 367 | |
| 368 TranslateMessage(&msg); | 362 TranslateMessage(&msg); |
| 369 DispatchMessage(&msg); | 363 DispatchMessage(&msg); |
| 370 | 364 |
| 371 return true; | 365 return true; |
| 372 } | 366 } |
| 373 | 367 |
| 374 bool MessagePumpForUI::ProcessPumpReplacementMessage() { | 368 bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
| 375 // When we encounter a kMsgHaveWork message, this method is called to peek and | 369 // When we encounter a kMsgHaveWork message, this method is called to peek and |
| 376 // process a replacement message. The goal is to make the kMsgHaveWork as non- | 370 // process a replacement message. The goal is to make the kMsgHaveWork as non- |
| 377 // intrusive as possible, even though a continuous stream of such messages are | 371 // intrusive as possible, even though a continuous stream of such messages are |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 | 523 |
| 530 if (msg.message == WM_QUIT) { | 524 if (msg.message == WM_QUIT) { |
| 531 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", | 525 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", |
| 532 RECEIVED_WM_QUIT_ERROR, MESSAGE_LOOP_PROBLEM_MAX); | 526 RECEIVED_WM_QUIT_ERROR, MESSAGE_LOOP_PROBLEM_MAX); |
| 533 // WM_QUIT messages shouldn't be received by any threads in the GPU | 527 // WM_QUIT messages shouldn't be received by any threads in the GPU |
| 534 // process. If they are, just ignore them instead of causing threads to | 528 // process. If they are, just ignore them instead of causing threads to |
| 535 // exit prematurely. | 529 // exit prematurely. |
| 536 return true; | 530 return true; |
| 537 } | 531 } |
| 538 | 532 |
| 539 if (!CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) { | 533 TranslateMessage(&msg); |
| 540 TranslateMessage(&msg); | 534 DispatchMessage(&msg); |
| 541 DispatchMessage(&msg); | |
| 542 } | |
| 543 | 535 |
| 544 return true; | 536 return true; |
| 545 } | 537 } |
| 546 | 538 |
| 547 //----------------------------------------------------------------------------- | 539 //----------------------------------------------------------------------------- |
| 548 // MessagePumpForIO public: | 540 // MessagePumpForIO public: |
| 549 | 541 |
| 550 MessagePumpForIO::IOContext::IOContext() { | 542 MessagePumpForIO::IOContext::IOContext() { |
| 551 memset(&overlapped, 0, sizeof(overlapped)); | 543 memset(&overlapped, 0, sizeof(overlapped)); |
| 552 } | 544 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 if (!filter || it->handler == filter) { | 708 if (!filter || it->handler == filter) { |
| 717 *item = *it; | 709 *item = *it; |
| 718 completed_io_.erase(it); | 710 completed_io_.erase(it); |
| 719 return true; | 711 return true; |
| 720 } | 712 } |
| 721 } | 713 } |
| 722 return false; | 714 return false; |
| 723 } | 715 } |
| 724 | 716 |
| 725 } // namespace base | 717 } // namespace base |
| OLD | NEW |