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

Side by Side Diff: ipc/ipc_test_base.cc

Issue 2455823002: Support generic synchronization against an IPC::Channel (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_test_base.h ('k') | mojo/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ipc/ipc_test_base.h" 5 #include "ipc/ipc_test_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 scoped_refptr<base::SingleThreadTaskRunner> IPCTestBase::task_runner() { 164 scoped_refptr<base::SingleThreadTaskRunner> IPCTestBase::task_runner() {
165 return message_loop_->task_runner(); 165 return message_loop_->task_runner();
166 } 166 }
167 167
168 std::unique_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory( 168 std::unique_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory(
169 const IPC::ChannelHandle& handle, 169 const IPC::ChannelHandle& handle,
170 base::SingleThreadTaskRunner* runner) { 170 base::SingleThreadTaskRunner* runner) {
171 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER, runner); 171 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER, runner);
172 } 172 }
173
174 IPCChannelMojoTestBase::ClientHandle::ClientHandle() = default;
175
176 IPCChannelMojoTestBase::ClientHandle::~ClientHandle() = default;
177
178 void IPCChannelMojoTestBase::ClientHandle::Init(
179 const std::string& test_client_name) {
180 pipe_ = helper_.StartChild(test_client_name);
181 }
182
183 void IPCChannelMojoTestBase::ClientHandle::CreateChannel(
184 IPC::Listener* listener) {
185 channel_ =
186 IPC::ChannelMojo::Create(TakeHandle(), IPC::Channel::MODE_SERVER,
187 listener, base::ThreadTaskRunnerHandle::Get());
188 }
189
190 bool IPCChannelMojoTestBase::ClientHandle::ConnectChannel() {
191 return channel_->Connect();
192 }
193
194 void IPCChannelMojoTestBase::ClientHandle::DestroyChannel() {
195 channel_.reset();
196 }
197
198 bool IPCChannelMojoTestBase::ClientHandle::WaitForShutdown() {
199 return helper_.WaitForChildTestShutdown();
200 }
201
202 mojo::ScopedMessagePipeHandle
203 IPCChannelMojoTestBase::ClientHandle::TakeHandle() {
204 return std::move(pipe_);
205 }
206
173 IPCChannelMojoTestBase::IPCChannelMojoTestBase() = default; 207 IPCChannelMojoTestBase::IPCChannelMojoTestBase() = default;
208
174 IPCChannelMojoTestBase::~IPCChannelMojoTestBase() = default; 209 IPCChannelMojoTestBase::~IPCChannelMojoTestBase() = default;
175 210
176 void IPCChannelMojoTestBase::Init(const std::string& test_client_name) { 211 void IPCChannelMojoTestBase::Init(const std::string& test_client_name) {
177 handle_ = helper_.StartChild(test_client_name); 212 primary_client_.Init(test_client_name);
178 } 213 }
179 214
180 bool IPCChannelMojoTestBase::WaitForClientShutdown() { 215 bool IPCChannelMojoTestBase::WaitForClientShutdown() {
181 return helper_.WaitForChildTestShutdown(); 216 return primary_client_.WaitForShutdown();
182 } 217 }
183 218
184 void IPCChannelMojoTestBase::TearDown() { 219 void IPCChannelMojoTestBase::TearDown() {
185 base::RunLoop().RunUntilIdle(); 220 base::RunLoop().RunUntilIdle();
186 } 221 }
187 222
188 void IPCChannelMojoTestBase::CreateChannel(IPC::Listener* listener) { 223 void IPCChannelMojoTestBase::CreateChannel(IPC::Listener* listener) {
189 channel_ = 224 primary_client_.CreateChannel(listener);
190 IPC::ChannelMojo::Create(TakeHandle(), IPC::Channel::MODE_SERVER,
191 listener, base::ThreadTaskRunnerHandle::Get());
192 } 225 }
193 226
194 bool IPCChannelMojoTestBase::ConnectChannel() { 227 bool IPCChannelMojoTestBase::ConnectChannel() {
195 return channel_->Connect(); 228 return primary_client_.ConnectChannel();
196 } 229 }
197 230
198 void IPCChannelMojoTestBase::DestroyChannel() { 231 void IPCChannelMojoTestBase::DestroyChannel() {
199 channel_.reset(); 232 return primary_client_.DestroyChannel();
200 } 233 }
201 234
202 mojo::ScopedMessagePipeHandle IPCChannelMojoTestBase::TakeHandle() { 235 mojo::ScopedMessagePipeHandle IPCChannelMojoTestBase::TakeHandle() {
203 return std::move(handle_); 236 return primary_client_.TakeHandle();
204 } 237 }
205 238
206 IpcChannelMojoTestClient::IpcChannelMojoTestClient() = default; 239 IpcChannelMojoTestClient::IpcChannelMojoTestClient() = default;
207 240
208 IpcChannelMojoTestClient::~IpcChannelMojoTestClient() = default; 241 IpcChannelMojoTestClient::~IpcChannelMojoTestClient() = default;
209 242
210 void IpcChannelMojoTestClient::Init(mojo::ScopedMessagePipeHandle handle) { 243 void IpcChannelMojoTestClient::Init(mojo::ScopedMessagePipeHandle handle) {
211 handle_ = std::move(handle); 244 handle_ = std::move(handle);
212 } 245 }
213 246
214 void IpcChannelMojoTestClient::Connect(IPC::Listener* listener) { 247 void IpcChannelMojoTestClient::Connect(IPC::Listener* listener) {
215 channel_ = 248 channel_ =
216 IPC::ChannelMojo::Create(std::move(handle_), IPC::Channel::MODE_CLIENT, 249 IPC::ChannelMojo::Create(std::move(handle_), IPC::Channel::MODE_CLIENT,
217 listener, base::ThreadTaskRunnerHandle::Get()); 250 listener, base::ThreadTaskRunnerHandle::Get());
218 CHECK(channel_->Connect()); 251 CHECK(channel_->Connect());
219 } 252 }
220 253
221 void IpcChannelMojoTestClient::Close() { 254 void IpcChannelMojoTestClient::Close() {
222 channel_->Close(); 255 channel_->Close();
223 256
224 base::RunLoop run_loop; 257 base::RunLoop run_loop;
225 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 258 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
226 run_loop.QuitClosure()); 259 run_loop.QuitClosure());
227 run_loop.Run(); 260 run_loop.Run();
228 } 261 }
OLDNEW
« no previous file with comments | « ipc/ipc_test_base.h ('k') | mojo/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698