| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 mojom::ChannelAssociatedRequest receive_channel, | 300 mojom::ChannelAssociatedRequest receive_channel, |
| 301 int32_t peer_pid) { | 301 int32_t peer_pid) { |
| 302 InitMessageReader(std::move(send_channel), std::move(receive_channel), | 302 InitMessageReader(std::move(send_channel), std::move(receive_channel), |
| 303 peer_pid); | 303 peer_pid); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void ChannelMojo::OnBootstrapError() { | 306 void ChannelMojo::OnBootstrapError() { |
| 307 listener_->OnChannelError(); | 307 listener_->OnChannelError(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void ChannelMojo::OnAssociatedInterfaceRequest( |
| 311 const std::string& name, |
| 312 mojo::ScopedInterfaceEndpointHandle handle) { |
| 313 auto iter = associated_interfaces_.find(name); |
| 314 if (iter != associated_interfaces_.end()) |
| 315 iter->second.Run(std::move(handle)); |
| 316 } |
| 317 |
| 310 void ChannelMojo::InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, | 318 void ChannelMojo::InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, |
| 311 mojom::ChannelAssociatedRequest receiver, | 319 mojom::ChannelAssociatedRequest receiver, |
| 312 base::ProcessId peer_pid) { | 320 base::ProcessId peer_pid) { |
| 313 mojom::ChannelAssociatedPtr sender_ptr; | 321 mojom::ChannelAssociatedPtr sender_ptr; |
| 314 sender_ptr.Bind(std::move(sender)); | 322 sender_ptr.Bind(std::move(sender)); |
| 315 std::unique_ptr<internal::MessagePipeReader, ChannelMojo::ReaderDeleter> | 323 std::unique_ptr<internal::MessagePipeReader, ChannelMojo::ReaderDeleter> |
| 316 reader(new internal::MessagePipeReader( | 324 reader(new internal::MessagePipeReader( |
| 317 pipe_, std::move(sender_ptr), std::move(receiver), peer_pid, this)); | 325 pipe_, std::move(sender_ptr), std::move(receiver), peer_pid, this)); |
| 318 | 326 |
| 319 bool connected = true; | 327 bool connected = true; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 if (!message_reader_) | 393 if (!message_reader_) |
| 386 return base::kNullProcessId; | 394 return base::kNullProcessId; |
| 387 | 395 |
| 388 return message_reader_->GetPeerPid(); | 396 return message_reader_->GetPeerPid(); |
| 389 } | 397 } |
| 390 | 398 |
| 391 base::ProcessId ChannelMojo::GetSelfPID() const { | 399 base::ProcessId ChannelMojo::GetSelfPID() const { |
| 392 return bootstrap_->GetSelfPID(); | 400 return bootstrap_->GetSelfPID(); |
| 393 } | 401 } |
| 394 | 402 |
| 403 Channel::AssociatedInterfaceSupport* |
| 404 ChannelMojo::GetAssociatedInterfaceSupport() { return this; } |
| 405 |
| 395 void ChannelMojo::OnMessageReceived(const Message& message) { | 406 void ChannelMojo::OnMessageReceived(const Message& message) { |
| 396 TRACE_EVENT2("ipc,toplevel", "ChannelMojo::OnMessageReceived", | 407 TRACE_EVENT2("ipc,toplevel", "ChannelMojo::OnMessageReceived", |
| 397 "class", IPC_MESSAGE_ID_CLASS(message.type()), | 408 "class", IPC_MESSAGE_ID_CLASS(message.type()), |
| 398 "line", IPC_MESSAGE_ID_LINE(message.type())); | 409 "line", IPC_MESSAGE_ID_LINE(message.type())); |
| 399 if (AttachmentBroker* broker = AttachmentBroker::GetGlobal()) { | 410 if (AttachmentBroker* broker = AttachmentBroker::GetGlobal()) { |
| 400 if (broker->OnMessageReceived(message)) | 411 if (broker->OnMessageReceived(message)) |
| 401 return; | 412 return; |
| 402 } | 413 } |
| 403 listener_->OnMessageReceived(message); | 414 listener_->OnMessageReceived(message); |
| 404 if (message.dispatch_error()) | 415 if (message.dispatch_error()) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 std::move(unwrapped_attachment)); | 472 std::move(unwrapped_attachment)); |
| 462 DCHECK(ok); | 473 DCHECK(ok); |
| 463 if (!ok) { | 474 if (!ok) { |
| 464 LOG(ERROR) << "Failed to add new Mojo handle."; | 475 LOG(ERROR) << "Failed to add new Mojo handle."; |
| 465 return MOJO_RESULT_UNKNOWN; | 476 return MOJO_RESULT_UNKNOWN; |
| 466 } | 477 } |
| 467 } | 478 } |
| 468 return MOJO_RESULT_OK; | 479 return MOJO_RESULT_OK; |
| 469 } | 480 } |
| 470 | 481 |
| 482 mojo::AssociatedGroup* ChannelMojo::GetAssociatedGroup() { |
| 483 DCHECK(bootstrap_); |
| 484 return bootstrap_->GetAssociatedGroup(); |
| 485 } |
| 486 |
| 487 void ChannelMojo::AddGenericAssociatedInterface( |
| 488 const std::string& name, |
| 489 const GenericAssociatedInterfaceFactory& factory) { |
| 490 auto result = associated_interfaces_.insert({ name, factory }); |
| 491 DCHECK(result.second); |
| 492 } |
| 493 |
| 494 void ChannelMojo::GetGenericRemoteAssociatedInterface( |
| 495 const std::string& name, |
| 496 mojo::ScopedInterfaceEndpointHandle handle) { |
| 497 DCHECK(message_reader_); |
| 498 message_reader_->GetRemoteInterface(name, std::move(handle)); |
| 499 } |
| 500 |
| 471 } // namespace IPC | 501 } // namespace IPC |
| OLD | NEW |