| 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/system/message_pipe_test_utils.h" | 5 #include "mojo/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/system/channel_endpoint.h" |
| 9 #include "mojo/system/waiter.h" | 10 #include "mojo/system/waiter.h" |
| 10 | 11 |
| 11 namespace mojo { | 12 namespace mojo { |
| 12 namespace system { | 13 namespace system { |
| 13 namespace test { | 14 namespace test { |
| 14 | 15 |
| 15 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, | 16 MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, |
| 16 MojoHandleSignals signals, | 17 MojoHandleSignals signals, |
| 17 HandleSignalsState* signals_state) { | 18 HandleSignalsState* signals_state) { |
| 18 Waiter waiter; | 19 Waiter waiter; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 channel_ = new Channel(platform_support_); | 76 channel_ = new Channel(platform_support_); |
| 76 CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass()))); | 77 CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass()))); |
| 77 | 78 |
| 78 // Attach the message pipe endpoint. | 79 // Attach the message pipe endpoint. |
| 79 // Note: On the "server" (parent process) side, we need not attach the | 80 // Note: On the "server" (parent process) side, we need not attach the |
| 80 // message pipe endpoint immediately. However, on the "client" (child | 81 // message pipe endpoint immediately. However, on the "client" (child |
| 81 // process) side, this *must* be done here -- otherwise, the |Channel| may | 82 // process) side, this *must* be done here -- otherwise, the |Channel| may |
| 82 // receive/process messages (which it can do as soon as it's hooked up to | 83 // receive/process messages (which it can do as soon as it's hooked up to |
| 83 // the IO thread message loop, and that message loop runs) before the | 84 // the IO thread message loop, and that message loop runs) before the |
| 84 // message pipe endpoint is attached. | 85 // message pipe endpoint is attached. |
| 85 CHECK_EQ(channel_->AttachMessagePipeEndpoint(message_pipe, 1), | 86 CHECK_EQ(channel_->AttachEndpoint( |
| 87 make_scoped_refptr(new ChannelEndpoint(message_pipe.get(), 1))), |
| 86 Channel::kBootstrapEndpointId); | 88 Channel::kBootstrapEndpointId); |
| 87 CHECK(channel_->RunMessagePipeEndpoint(Channel::kBootstrapEndpointId, | 89 CHECK(channel_->RunMessagePipeEndpoint(Channel::kBootstrapEndpointId, |
| 88 Channel::kBootstrapEndpointId)); | 90 Channel::kBootstrapEndpointId)); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void ChannelThread::ShutdownChannelOnIOThread() { | 93 void ChannelThread::ShutdownChannelOnIOThread() { |
| 92 CHECK(channel_.get()); | 94 CHECK(channel_.get()); |
| 93 channel_->Shutdown(); | 95 channel_->Shutdown(); |
| 94 channel_ = NULL; | 96 channel_ = NULL; |
| 95 } | 97 } |
| 96 | 98 |
| 97 #if !defined(OS_IOS) | 99 #if !defined(OS_IOS) |
| 98 MultiprocessMessagePipeTestBase::MultiprocessMessagePipeTestBase() | 100 MultiprocessMessagePipeTestBase::MultiprocessMessagePipeTestBase() |
| 99 : channel_thread_(&platform_support_) { | 101 : channel_thread_(&platform_support_) { |
| 100 } | 102 } |
| 101 | 103 |
| 102 MultiprocessMessagePipeTestBase::~MultiprocessMessagePipeTestBase() { | 104 MultiprocessMessagePipeTestBase::~MultiprocessMessagePipeTestBase() { |
| 103 } | 105 } |
| 104 | 106 |
| 105 void MultiprocessMessagePipeTestBase::Init(scoped_refptr<MessagePipe> mp) { | 107 void MultiprocessMessagePipeTestBase::Init(scoped_refptr<MessagePipe> mp) { |
| 106 channel_thread_.Start(helper_.server_platform_handle.Pass(), mp); | 108 channel_thread_.Start(helper_.server_platform_handle.Pass(), mp); |
| 107 } | 109 } |
| 108 #endif | 110 #endif |
| 109 | 111 |
| 110 } // namespace test | 112 } // namespace test |
| 111 } // namespace system | 113 } // namespace system |
| 112 } // namespace mojo | 114 } // namespace mojo |
| OLD | NEW |