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 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 314 |
315 state_->delegate->DoDelayedWork(&delayed_work_time_); | 315 state_->delegate->DoDelayedWork(&delayed_work_time_); |
316 if (!delayed_work_time_.is_null()) { | 316 if (!delayed_work_time_.is_null()) { |
317 // A bit gratuitous to set delayed_work_time_ again, but oh well. | 317 // A bit gratuitous to set delayed_work_time_ again, but oh well. |
318 ScheduleDelayedWork(delayed_work_time_); | 318 ScheduleDelayedWork(delayed_work_time_); |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 bool MessagePumpForUI::ProcessNextWindowsMessage() { | 322 bool MessagePumpForUI::ProcessNextWindowsMessage() { |
323 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. | 323 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
324 tracked_objects::ScopedTracker tracking_profile( | 324 tracked_objects::ScopedTracker tracking_profile1( |
325 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 325 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
326 "440919 <<MessagePumpForUI::ProcessNextWindowsMessage>>")); | 326 "440919 MessagePumpForUI::ProcessNextWindowsMessage1")); |
327 | 327 |
328 // If there are sent messages in the queue then PeekMessage internally | 328 // If there are sent messages in the queue then PeekMessage internally |
329 // dispatches the message and returns false. We return true in this | 329 // dispatches the message and returns false. We return true in this |
330 // case to ensure that the message loop peeks again instead of calling | 330 // case to ensure that the message loop peeks again instead of calling |
331 // MsgWaitForMultipleObjectsEx again. | 331 // MsgWaitForMultipleObjectsEx again. |
332 bool sent_messages_in_queue = false; | 332 bool sent_messages_in_queue = false; |
333 DWORD queue_status = GetQueueStatus(QS_SENDMESSAGE); | 333 DWORD queue_status = GetQueueStatus(QS_SENDMESSAGE); |
334 if (HIWORD(queue_status) & QS_SENDMESSAGE) | 334 if (HIWORD(queue_status) & QS_SENDMESSAGE) |
335 sent_messages_in_queue = true; | 335 sent_messages_in_queue = true; |
336 | 336 |
| 337 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
| 338 tracked_objects::ScopedTracker tracking_profile2( |
| 339 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 340 "440919 MessagePumpForUI::ProcessNextWindowsMessage2")); |
| 341 |
337 MSG msg; | 342 MSG msg; |
338 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE) | 343 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE) |
339 return ProcessMessageHelper(msg); | 344 return ProcessMessageHelper(msg); |
340 | 345 |
341 return sent_messages_in_queue; | 346 return sent_messages_in_queue; |
342 } | 347 } |
343 | 348 |
344 bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) { | 349 bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) { |
345 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. | 350 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
346 tracked_objects::ScopedTracker tracking_profile( | 351 tracked_objects::ScopedTracker tracking_profile1( |
347 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 352 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
348 "440919 MessagePumpForUI::ProcessMessageHelper")); | 353 "440919 MessagePumpForUI::ProcessMessageHelper1")); |
349 | 354 |
350 TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper", | 355 TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper", |
351 "message", msg.message); | 356 "message", msg.message); |
352 if (WM_QUIT == msg.message) { | 357 if (WM_QUIT == msg.message) { |
353 // Repost the QUIT message so that it will be retrieved by the primary | 358 // Repost the QUIT message so that it will be retrieved by the primary |
354 // GetMessage() loop. | 359 // GetMessage() loop. |
355 state_->should_quit = true; | 360 state_->should_quit = true; |
356 PostQuitMessage(static_cast<int>(msg.wParam)); | 361 PostQuitMessage(static_cast<int>(msg.wParam)); |
357 return false; | 362 return false; |
358 } | 363 } |
359 | 364 |
360 // While running our main message pump, we discard kMsgHaveWork messages. | 365 // While running our main message pump, we discard kMsgHaveWork messages. |
361 if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_) | 366 if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_) |
362 return ProcessPumpReplacementMessage(); | 367 return ProcessPumpReplacementMessage(); |
363 | 368 |
| 369 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
| 370 tracked_objects::ScopedTracker tracking_profile2( |
| 371 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 372 "440919 MessagePumpForUI::ProcessMessageHelper2")); |
| 373 |
364 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) | 374 if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) |
365 return true; | 375 return true; |
366 | 376 |
| 377 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
| 378 tracked_objects::ScopedTracker tracking_profile3( |
| 379 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 380 "440919 MessagePumpForUI::ProcessMessageHelper3")); |
| 381 |
367 uint32_t action = MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT; | 382 uint32_t action = MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT; |
368 if (state_->dispatcher) | 383 if (state_->dispatcher) |
369 action = state_->dispatcher->Dispatch(msg); | 384 action = state_->dispatcher->Dispatch(msg); |
370 if (action & MessagePumpDispatcher::POST_DISPATCH_QUIT_LOOP) | 385 if (action & MessagePumpDispatcher::POST_DISPATCH_QUIT_LOOP) |
371 state_->should_quit = true; | 386 state_->should_quit = true; |
372 if (action & MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT) { | 387 if (action & MessagePumpDispatcher::POST_DISPATCH_PERFORM_DEFAULT) { |
373 TranslateMessage(&msg); | 388 TranslateMessage(&msg); |
374 DispatchMessage(&msg); | 389 DispatchMessage(&msg); |
375 } | 390 } |
376 | 391 |
377 return true; | 392 return true; |
378 } | 393 } |
379 | 394 |
380 bool MessagePumpForUI::ProcessPumpReplacementMessage() { | 395 bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
| 396 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed. |
| 397 tracked_objects::ScopedTracker tracking_profile( |
| 398 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 399 "440919 MessagePumpForUI::ProcessPumpReplacementMessage")); |
| 400 |
381 // When we encounter a kMsgHaveWork message, this method is called to peek | 401 // When we encounter a kMsgHaveWork message, this method is called to peek |
382 // and process a replacement message, such as a WM_PAINT or WM_TIMER. The | 402 // and process a replacement message, such as a WM_PAINT or WM_TIMER. The |
383 // goal is to make the kMsgHaveWork as non-intrusive as possible, even though | 403 // goal is to make the kMsgHaveWork as non-intrusive as possible, even though |
384 // a continuous stream of such messages are posted. This method carefully | 404 // a continuous stream of such messages are posted. This method carefully |
385 // peeks a message while there is no chance for a kMsgHaveWork to be pending, | 405 // peeks a message while there is no chance for a kMsgHaveWork to be pending, |
386 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to | 406 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to |
387 // possibly be posted), and finally dispatches that peeked replacement. Note | 407 // possibly be posted), and finally dispatches that peeked replacement. Note |
388 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! | 408 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! |
389 | 409 |
390 bool have_message = false; | 410 bool have_message = false; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 658 |
639 // static | 659 // static |
640 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 660 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
641 ULONG_PTR key, | 661 ULONG_PTR key, |
642 bool* has_valid_io_context) { | 662 bool* has_valid_io_context) { |
643 *has_valid_io_context = ((key & 1) == 0); | 663 *has_valid_io_context = ((key & 1) == 0); |
644 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 664 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
645 } | 665 } |
646 | 666 |
647 } // namespace base | 667 } // namespace base |
OLD | NEW |