• Gabriel Charette's avatar
    Ensure that WM_QUIT is visible to nested ::GetMessage() loops. · 6b9a2faf
    Gabriel Charette authored
    When a kMsgHaveWork task is processed by the pump, allowing it a
    timeslice in which to process tasks, we pull the next MSG from the
    thread's queue and dispatch that, to minimize impact of kMsgHaveWork on
    MSG scheduling. WM_QUIT must be observed directly by GetMessage in order
    for a nested loop to exit, though, so we must re-post it to the thread
    queue, for GetMessage to report.
    
    Re-posting was removed by crrev.com/553653, which caused WM_QUIT to be
    ignored by MessagePumpForUI, missing that we must still re-post the
    message, in case we're inside a nested loop, to allow it to quit.
    
    To address this:
    - When pulling a MSG to replace kMsgHaveWork, we unconditionally re-post
      WM_QUIT messages, in case ::GetMessage() needs to see them.
    - Only actually handle WM_QUIT when it is observed directly by
      DoRunLoop(), i.e. if WM_QUIT was the kMsgHaveWork replacement, don't
      process it until we see it re-posted.
    - Continue ignoring WM_QUIT when handled iff |!enable_wm_quit_| to
      properties of crrev.com/573620.
    - Add comments and tests to properly explain and verify the special-case
      handling of WM_QUIT.
    - Document a another edge case bug uncovered by this investigation.
    
    Bug: 888559, 890016
    Change-Id: I548165b6103b1c7454f90335ba6dfb4f8cf149d9
    Reviewed-on: https://chromium-review.googlesource.com/1240158
    Commit-Queue: Gabriel Charette <gab@chromium.org>
    Reviewed-by: default avatarWez <wez@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#595217}
    6b9a2faf
message_pump_win.cc 22.5 KB