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 "ipc/ipc_channel_mojo.h" | 5 #include "ipc/ipc_channel_mojo.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // ChannelMojo from a different thread. | 275 // ChannelMojo from a different thread. |
276 bootstrap_ = | 276 bootstrap_ = |
277 MojoBootstrap::Create(std::move(handle), mode, this, ipc_task_runner); | 277 MojoBootstrap::Create(std::move(handle), mode, this, ipc_task_runner); |
278 } | 278 } |
279 | 279 |
280 ChannelMojo::~ChannelMojo() { | 280 ChannelMojo::~ChannelMojo() { |
281 Close(); | 281 Close(); |
282 } | 282 } |
283 | 283 |
284 bool ChannelMojo::Connect() { | 284 bool ChannelMojo::Connect() { |
| 285 if (!ConnectPaused()) |
| 286 return false; |
| 287 |
| 288 Unpause(true); |
| 289 return true; |
| 290 } |
| 291 |
| 292 bool ChannelMojo::ConnectPaused() { |
285 WillConnect(); | 293 WillConnect(); |
286 | 294 |
287 DCHECK(!task_runner_); | 295 DCHECK(!task_runner_); |
288 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 296 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
289 DCHECK(!message_reader_); | 297 DCHECK(!message_reader_); |
290 | 298 |
291 bootstrap_->Connect(); | 299 bootstrap_->Connect(); |
292 return true; | 300 return true; |
293 } | 301 } |
294 | 302 |
| 303 void ChannelMojo::Unpause(bool flush) { |
| 304 bootstrap_->Start(); |
| 305 |
| 306 // Ensure that no matter what messages have been queued so far, the first |
| 307 // message we send is always the peer PID. |
| 308 DCHECK(message_reader_); |
| 309 message_reader_->sender()->SetPeerPid(GetSelfPID()); |
| 310 |
| 311 if (flush) |
| 312 Flush(); |
| 313 } |
| 314 |
| 315 void ChannelMojo::Flush() { |
| 316 bootstrap_->Flush(); |
| 317 } |
| 318 |
295 void ChannelMojo::Close() { | 319 void ChannelMojo::Close() { |
296 // NOTE: The MessagePipeReader's destructor may re-enter this function. Use | 320 // NOTE: The MessagePipeReader's destructor may re-enter this function. Use |
297 // caution when changing this method. | 321 // caution when changing this method. |
298 std::unique_ptr<internal::MessagePipeReader> reader = | 322 std::unique_ptr<internal::MessagePipeReader> reader = |
299 std::move(message_reader_); | 323 std::move(message_reader_); |
300 reader.reset(); | 324 reader.reset(); |
301 | 325 |
302 base::AutoLock lock(associated_interface_lock_); | 326 base::AutoLock lock(associated_interface_lock_); |
303 associated_interfaces_.clear(); | 327 associated_interfaces_.clear(); |
304 } | 328 } |
305 | 329 |
306 // MojoBootstrap::Delegate implementation | 330 // MojoBootstrap::Delegate implementation |
307 void ChannelMojo::OnPipesAvailable(mojom::ChannelAssociatedPtr sender, | 331 void ChannelMojo::OnPipesAvailable(mojom::ChannelAssociatedPtr sender, |
308 mojom::ChannelAssociatedRequest receiver) { | 332 mojom::ChannelAssociatedRequest receiver) { |
309 sender->SetPeerPid(GetSelfPID()); | |
310 message_reader_.reset(new internal::MessagePipeReader( | 333 message_reader_.reset(new internal::MessagePipeReader( |
311 pipe_, std::move(sender), std::move(receiver), this)); | 334 pipe_, std::move(sender), std::move(receiver), this)); |
312 } | 335 } |
313 | 336 |
314 void ChannelMojo::OnPipeError() { | 337 void ChannelMojo::OnPipeError() { |
315 DCHECK(task_runner_); | 338 DCHECK(task_runner_); |
316 if (task_runner_->RunsTasksOnCurrentThread()) { | 339 if (task_runner_->RunsTasksOnCurrentThread()) { |
317 listener_->OnChannelError(); | 340 listener_->OnChannelError(); |
318 } else { | 341 } else { |
319 task_runner_->PostTask( | 342 task_runner_->PostTask( |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 504 } |
482 | 505 |
483 void ChannelMojo::GetGenericRemoteAssociatedInterface( | 506 void ChannelMojo::GetGenericRemoteAssociatedInterface( |
484 const std::string& name, | 507 const std::string& name, |
485 mojo::ScopedInterfaceEndpointHandle handle) { | 508 mojo::ScopedInterfaceEndpointHandle handle) { |
486 if (message_reader_) | 509 if (message_reader_) |
487 message_reader_->GetRemoteInterface(name, std::move(handle)); | 510 message_reader_->GetRemoteInterface(name, std::move(handle)); |
488 } | 511 } |
489 | 512 |
490 } // namespace IPC | 513 } // namespace IPC |
OLD | NEW |