Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Issue 16020005: Fixed the racy code around the message-only window in base::MessagePumpForUI on Windows. (Closed)

Created:
7 years, 7 months ago by alexeypa (please no reviews)
Modified:
7 years, 6 months ago
CC:
chromium-reviews, jamiewalch+watch_chromium.org, dcaiafa+watch_chromium.org, sadrul, timurrrr+watch_chromium.org, hclam+watch_chromium.org, wez+watch_chromium.org, amit, sanjeevr, dcheng, garykac+watch_chromium.org, lambroslambrou+watch_chromium.org, rmsousa+watch_chromium.org, weitaosu+watch_chromium.org, alexeypa+watch_chromium.org, erikwright+watch_chromium.org, glider+watch_chromium.org, sergeyu+watch_chromium.org, bruening+watch_chromium.org
Visibility:
Public.

Description

Fixed the racy code around the message-only window in base::MessagePumpForUI on Windows. The current implementation of base::MessagePumpForUI has a couple of problems: - A window class registered for the message-only window has a predefined name. This leads to issues like registering the same class multiple times or unregistering it prematurely. - base::MessagePumpForUI is a ref-counted class and can be destroyed on a different thread. As the result DestroyWindow() can be called on a wrong thread. This CL introduces the following changes to address the above problems: - MessageWindow is used to create the message-only window in base::MessagePumpForUI. This class registers a unique window class name for every window to make sure multiple message-only windows can exist at the same time. The implementation of MessageWindow is moved to src/base/win along with the corresponding unit test. - The message pump is now notified when the owning message loop is being destroyed. The notification is used to free all resources that hve to be released on the base::MessageLoop's thread. - MessagePumpForUI::ScheduleWork() synchronizes access to the message-only window handle to avoid posting messages to the window during or after its destruction. BUG=241939

Patch Set 1 #

Patch Set 2 : - #

Total comments: 4

Patch Set 3 : synchronizing without a lock #

Total comments: 11

Patch Set 4 : - #

Total comments: 9
Unified diffs Side-by-side diffs Delta from patch set Stats (+174 lines, -389 lines) Patch
M base/base.gyp View 2 chunks +2 lines, -1 line 0 comments Download
M base/base.gypi View 3 chunks +6 lines, -4 lines 0 comments Download
M base/message_loop.cc View 1 1 chunk +3 lines, -0 lines 0 comments Download
M base/message_pump.h View 1 1 chunk +4 lines, -0 lines 0 comments Download
M base/message_pump_win.h View 1 2 7 chunks +24 lines, -18 lines 0 comments Download
M base/message_pump_win.cc View 1 2 3 19 chunks +106 lines, -50 lines 6 comments Download
A + base/win/message_window.h View 1 3 chunks +8 lines, -8 lines 0 comments Download
A + base/win/message_window.cc View 4 chunks +4 lines, -11 lines 3 comments Download
A + base/win/message_window_unittest.cc View 2 chunks +3 lines, -3 lines 0 comments Download
M remoting/host/clipboard_win.cc View 5 chunks +5 lines, -5 lines 0 comments Download
M remoting/host/local_input_monitor_win.cc View 5 chunks +5 lines, -5 lines 0 comments Download
M remoting/host/win/host_service.h View 3 chunks +3 lines, -3 lines 0 comments Download
M remoting/host/win/host_service.cc View 1 chunk +1 line, -1 line 0 comments Download
D remoting/host/win/message_window.h View 1 chunk +0 lines, -67 lines 0 comments Download
D remoting/host/win/message_window.cc View 1 chunk +0 lines, -118 lines 0 comments Download
D remoting/host/win/message_window_unittest.cc View 1 chunk +0 lines, -61 lines 0 comments Download
M remoting/remoting.gyp View 2 chunks +0 lines, -3 lines 0 comments Download
M tools/valgrind/tsan/suppressions.txt View 1 chunk +0 lines, -31 lines 0 comments Download

Messages

Total messages: 20 (0 generated)
alexeypa (please no reviews)
This is a 2nd attempt to land https://chromiumcodereview.appspot.com/15261005/. The previous CL was reverted because it ...
7 years, 7 months ago (2013-05-24 19:52:58 UTC) #1
darin (slow to review)
https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc File base/message_pump_win.cc (right): https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc#newcode118 base/message_pump_win.cc:118: if (PostMessage(window_->hwnd(), kMsgHaveWork, 0, 0)) Perhaps MessageWindow should be ...
7 years, 7 months ago (2013-05-24 21:42:57 UTC) #2
darin (slow to review)
Another solution might be to force the destruction of the MessagePump to its originating thread. ...
7 years, 7 months ago (2013-05-24 21:43:44 UTC) #3
alexeypa (please no reviews)
On 2013/05/24 21:43:44, darin wrote: > Another solution might be to force the destruction of ...
7 years, 7 months ago (2013-05-24 22:22:40 UTC) #4
alexeypa (please no reviews)
https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc File base/message_pump_win.cc (right): https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc#newcode118 base/message_pump_win.cc:118: if (PostMessage(window_->hwnd(), kMsgHaveWork, 0, 0)) On 2013/05/24 21:42:58, darin ...
7 years, 7 months ago (2013-05-24 22:22:47 UTC) #5
darin (slow to review)
On 2013/05/24 22:22:47, alexeypa wrote: > https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc > File base/message_pump_win.cc (right): > > https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc#newcode118 > ...
7 years, 7 months ago (2013-05-25 21:15:21 UTC) #6
darin (slow to review)
On 2013/05/25 21:15:21, darin wrote: ... > >On 2013/05/24 21:43:44, darin wrote: > >> Another ...
7 years, 7 months ago (2013-05-25 21:17:24 UTC) #7
darin (slow to review)
https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc File base/message_pump_win.cc (right): https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc#newcode115 base/message_pump_win.cc:115: AutoLock lock(window_lock_); Is it perhaps worth avoiding this lock ...
7 years, 7 months ago (2013-05-25 21:23:16 UTC) #8
alexeypa (please no reviews)
OK, here is another version that does not use an explicit lock. https://chromiumcodereview.appspot.com/16020005/diff/2001/base/message_pump_win.cc File base/message_pump_win.cc ...
7 years, 6 months ago (2013-05-29 18:11:51 UTC) #9
alexeypa (please no reviews)
Darin, ping.
7 years, 6 months ago (2013-05-30 20:29:20 UTC) #10
alexeypa (please no reviews)
Ping!
7 years, 6 months ago (2013-06-06 19:29:26 UTC) #11
Wez
https://chromiumcodereview.appspot.com/16020005/diff/27001/base/message_pump_win.cc File base/message_pump_win.cc (right): https://chromiumcodereview.appspot.com/16020005/diff/27001/base/message_pump_win.cc#newcode30 base/message_pump_win.cc:30: VOID CALLBACK DummyApc(ULONG_PTR) {} nit: Add a comment explaining ...
7 years, 6 months ago (2013-06-06 20:20:32 UTC) #12
alexeypa (please no reviews)
https://chromiumcodereview.appspot.com/16020005/diff/27001/base/message_pump_win.cc File base/message_pump_win.cc (right): https://chromiumcodereview.appspot.com/16020005/diff/27001/base/message_pump_win.cc#newcode30 base/message_pump_win.cc:30: VOID CALLBACK DummyApc(ULONG_PTR) {} On 2013/06/06 20:20:33, Wez wrote: ...
7 years, 6 months ago (2013-06-07 15:33:08 UTC) #13
alexeypa (please no reviews)
brettw@ could you please review this CL instead of darin@? Unfortunately I could not get ...
7 years, 6 months ago (2013-06-10 18:47:55 UTC) #14
darin (slow to review)
On 2013/06/10 18:47:55, alexeypa wrote: > brettw@ could you please review this CL instead of ...
7 years, 6 months ago (2013-06-10 18:53:36 UTC) #15
darin (slow to review)
https://chromiumcodereview.appspot.com/16020005/diff/45001/base/message_pump_win.cc File base/message_pump_win.cc (right): https://chromiumcodereview.appspot.com/16020005/diff/45001/base/message_pump_win.cc#newcode150 base/message_pump_win.cc:150: InterlockedExchange(&pump_state_, kPumpIdle); nit: Shouldn't this use InterlockedCompareExchange(&pump_state_, kPumpIdle, kPumpHaveWork) ...
7 years, 6 months ago (2013-06-10 19:28:44 UTC) #16
darin (slow to review)
+cpu for QueueUserAPC review
7 years, 6 months ago (2013-06-10 19:29:18 UTC) #17
alexeypa (please no reviews)
https://chromiumcodereview.appspot.com/16020005/diff/45001/base/message_pump_win.cc File base/message_pump_win.cc (right): https://chromiumcodereview.appspot.com/16020005/diff/45001/base/message_pump_win.cc#newcode150 base/message_pump_win.cc:150: InterlockedExchange(&pump_state_, kPumpIdle); On 2013/06/10 19:28:45, darin wrote: > nit: ...
7 years, 6 months ago (2013-06-10 20:16:11 UTC) #18
cpu_(ooo_6.6-7.5)
only got cc now, sorry to be late to this party. First off the message-only ...
7 years, 6 months ago (2013-06-10 21:27:18 UTC) #19
alexeypa (please no reviews)
7 years, 6 months ago (2013-06-10 21:57:15 UTC) #20
On 2013/06/10 21:27:18, cpu wrote:
> I suggest the following, create a CL with the first and foremost thing you
need
> to fix which is the class name to the existing window. This should be a
simple,
> straightforward patch, which addresses the bug, we can get that done in 24
hours
> or less.
> 
> In a second patch you then address the lifetime / threading issues of the
> MessagePumpforUi, this time please include rvargas@.

OK, great. I'll follow up with a couple of CL.

Powered by Google App Engine
This is Rietveld 408576698