diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 01:24:49 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-08 01:24:49 +0000 |
commit | d4fc4d6a53b684d12218b066186b0ca0f702a25c (patch) | |
tree | 25b10b49e90a19599957f8908f6be66f5501d06c /ipc/ipc_sync_channel_unittest.cc | |
parent | a2aa6864001f732418075bfe137d17e0c08413ba (diff) | |
download | chromium_src-d4fc4d6a53b684d12218b066186b0ca0f702a25c.zip chromium_src-d4fc4d6a53b684d12218b066186b0ca0f702a25c.tar.gz chromium_src-d4fc4d6a53b684d12218b066186b0ca0f702a25c.tar.bz2 |
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
Diffstat (limited to 'ipc/ipc_sync_channel_unittest.cc')
-rw-r--r-- | ipc/ipc_sync_channel_unittest.cc | 23 |
1 files changed, 14 insertions, 9 deletions
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<base::MessageLoopProxy> 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<base::MessageLoopProxy> 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<TestSyncMessageFilter> filter_; }; |