| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/edk/system/message_pipe_test_utils.h" | 5 #include "mojo/edk/system/message_pipe_test_utils.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/platform_thread.h" // For |Sleep()|. | 8 #include "base/threading/platform_thread.h" // For |Sleep()|. |
| 9 #include "mojo/edk/system/channel.h" | 9 #include "mojo/edk/system/channel.h" |
| 10 #include "mojo/edk/system/channel_endpoint.h" | 10 #include "mojo/edk/system/channel_endpoint.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 ChannelThread::~ChannelThread() { | 40 ChannelThread::~ChannelThread() { |
| 41 Stop(); | 41 Stop(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void ChannelThread::Start(embedder::ScopedPlatformHandle platform_handle, | 44 void ChannelThread::Start(embedder::ScopedPlatformHandle platform_handle, |
| 45 scoped_refptr<ChannelEndpoint> channel_endpoint) { | 45 scoped_refptr<ChannelEndpoint> channel_endpoint) { |
| 46 test_io_thread_.Start(); | 46 test_io_thread_.Start(); |
| 47 test_io_thread_.PostTaskAndWait( | 47 test_io_thread_.PostTaskAndWait( |
| 48 FROM_HERE, | 48 FROM_HERE, |
| 49 base::Bind(&ChannelThread::InitChannelOnIOThread, | 49 base::Bind(&ChannelThread::InitChannelOnIOThread, base::Unretained(this), |
| 50 base::Unretained(this), | 50 base::Passed(&platform_handle), channel_endpoint)); |
| 51 base::Passed(&platform_handle), | |
| 52 channel_endpoint)); | |
| 53 } | 51 } |
| 54 | 52 |
| 55 void ChannelThread::Stop() { | 53 void ChannelThread::Stop() { |
| 56 if (channel_.get()) { | 54 if (channel_.get()) { |
| 57 // Hack to flush write buffers before quitting. | 55 // Hack to flush write buffers before quitting. |
| 58 // TODO(vtl): Remove this once |Channel| has a | 56 // TODO(vtl): Remove this once |Channel| has a |
| 59 // |FlushWriteBufferAndShutdown()| (or whatever). | 57 // |FlushWriteBufferAndShutdown()| (or whatever). |
| 60 while (!channel_->IsWriteBufferEmpty()) | 58 while (!channel_->IsWriteBufferEmpty()) |
| 61 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | 59 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
| 62 | 60 |
| 63 test_io_thread_.PostTaskAndWait( | 61 test_io_thread_.PostTaskAndWait( |
| 64 FROM_HERE, | 62 FROM_HERE, base::Bind(&ChannelThread::ShutdownChannelOnIOThread, |
| 65 base::Bind(&ChannelThread::ShutdownChannelOnIOThread, | 63 base::Unretained(this))); |
| 66 base::Unretained(this))); | |
| 67 } | 64 } |
| 68 test_io_thread_.Stop(); | 65 test_io_thread_.Stop(); |
| 69 } | 66 } |
| 70 | 67 |
| 71 void ChannelThread::InitChannelOnIOThread( | 68 void ChannelThread::InitChannelOnIOThread( |
| 72 embedder::ScopedPlatformHandle platform_handle, | 69 embedder::ScopedPlatformHandle platform_handle, |
| 73 scoped_refptr<ChannelEndpoint> channel_endpoint) { | 70 scoped_refptr<ChannelEndpoint> channel_endpoint) { |
| 74 CHECK_EQ(base::MessageLoop::current(), test_io_thread_.message_loop()); | 71 CHECK_EQ(base::MessageLoop::current(), test_io_thread_.message_loop()); |
| 75 CHECK(platform_handle.is_valid()); | 72 CHECK(platform_handle.is_valid()); |
| 76 | 73 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 102 } | 99 } |
| 103 | 100 |
| 104 void MultiprocessMessagePipeTestBase::Init(scoped_refptr<ChannelEndpoint> ep) { | 101 void MultiprocessMessagePipeTestBase::Init(scoped_refptr<ChannelEndpoint> ep) { |
| 105 channel_thread_.Start(helper_.server_platform_handle.Pass(), ep); | 102 channel_thread_.Start(helper_.server_platform_handle.Pass(), ep); |
| 106 } | 103 } |
| 107 #endif | 104 #endif |
| 108 | 105 |
| 109 } // namespace test | 106 } // namespace test |
| 110 } // namespace system | 107 } // namespace system |
| 111 } // namespace mojo | 108 } // namespace mojo |
| OLD | NEW |