From d4fc4d6a53b684d12218b066186b0ca0f702a25c Mon Sep 17 00:00:00 2001 From: "piman@chromium.org" Date: Sat, 8 Sep 2012 01:24:49 +0000 Subject: Fix ownership of the helper thread in IPCSyncChannelTest.SyncMessageFilter The Thread object could (depending on a race) be destroyed on its own thread, which is illegal. Instead, make sure that ownership of the thread is decoupled from the filter to ensure it's destroyed (and joined) on a good thread. BUG=129620 Review URL: https://chromiumcodereview.appspot.com/10914161 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155547 0039d316-1c4b-4281-b951-d872f2087c98 --- ipc/ipc_sync_channel_unittest.cc | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'ipc') diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc index 996ef99..e9ec021 100644 --- a/ipc/ipc_sync_channel_unittest.cc +++ b/ipc/ipc_sync_channel_unittest.cc @@ -1086,18 +1086,17 @@ namespace { class TestSyncMessageFilter : public SyncMessageFilter { public: - TestSyncMessageFilter(base::WaitableEvent* shutdown_event, Worker* worker) + TestSyncMessageFilter(base::WaitableEvent* shutdown_event, + Worker* worker, + scoped_refptr message_loop) : SyncMessageFilter(shutdown_event), worker_(worker), - thread_("helper_thread") { - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_DEFAULT; - thread_.StartWithOptions(options); + message_loop_(message_loop) { } virtual void OnFilterAdded(Channel* channel) { SyncMessageFilter::OnFilterAdded(channel); - thread_.message_loop()->PostTask( + message_loop_->PostTask( FROM_HERE, base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this)); } @@ -1115,20 +1114,26 @@ class TestSyncMessageFilter : public SyncMessageFilter { virtual ~TestSyncMessageFilter() {} Worker* worker_; - base::Thread thread_; + scoped_refptr message_loop_; }; class SyncMessageFilterServer : public Worker { public: SyncMessageFilterServer() - : Worker(Channel::MODE_SERVER, "sync_message_filter_server") { - filter_ = new TestSyncMessageFilter(shutdown_event(), this); + : Worker(Channel::MODE_SERVER, "sync_message_filter_server"), + thread_("helper_thread") { + base::Thread::Options options; + options.message_loop_type = MessageLoop::TYPE_DEFAULT; + thread_.StartWithOptions(options); + filter_ = new TestSyncMessageFilter(shutdown_event(), this, + thread_.message_loop_proxy()); } void Run() { channel()->AddFilter(filter_.get()); } + base::Thread thread_; scoped_refptr filter_; }; -- cgit v1.1