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 | |
318 void ChannelMojo::InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, | 310 void ChannelMojo::InitMessageReader(mojom::ChannelAssociatedPtrInfo sender, |
319 mojom::ChannelAssociatedRequest receiver, | 311 mojom::ChannelAssociatedRequest receiver, |
320 base::ProcessId peer_pid) { | 312 base::ProcessId peer_pid) { |
321 mojom::ChannelAssociatedPtr sender_ptr; | 313 mojom::ChannelAssociatedPtr sender_ptr; |
322 sender_ptr.Bind(std::move(sender)); | 314 sender_ptr.Bind(std::move(sender)); |
323 std::unique_ptr<internal::MessagePipeReader, ChannelMojo::ReaderDeleter> | 315 std::unique_ptr<internal::MessagePipeReader, ChannelMojo::ReaderDeleter> |
324 reader(new internal::MessagePipeReader( | 316 reader(new internal::MessagePipeReader( |
325 pipe_, std::move(sender_ptr), std::move(receiver), peer_pid, this)); | 317 pipe_, std::move(sender_ptr), std::move(receiver), peer_pid, this)); |
326 | 318 |
327 bool connected = true; | 319 bool connected = true; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 if (!message_reader_) | 385 if (!message_reader_) |
394 return base::kNullProcessId; | 386 return base::kNullProcessId; |
395 | 387 |
396 return message_reader_->GetPeerPid(); | 388 return message_reader_->GetPeerPid(); |
397 } | 389 } |
398 | 390 |
399 base::ProcessId ChannelMojo::GetSelfPID() const { | 391 base::ProcessId ChannelMojo::GetSelfPID() const { |
400 return bootstrap_->GetSelfPID(); | 392 return bootstrap_->GetSelfPID(); |
401 } | 393 } |
402 | 394 |
403 Channel::AssociatedInterfaceSupport* | |
404 ChannelMojo::GetAssociatedInterfaceSupport() { return this; } | |
405 | |
406 void ChannelMojo::OnMessageReceived(const Message& message) { | 395 void ChannelMojo::OnMessageReceived(const Message& message) { |
407 TRACE_EVENT2("ipc,toplevel", "ChannelMojo::OnMessageReceived", | 396 TRACE_EVENT2("ipc,toplevel", "ChannelMojo::OnMessageReceived", |
408 "class", IPC_MESSAGE_ID_CLASS(message.type()), | 397 "class", IPC_MESSAGE_ID_CLASS(message.type()), |
409 "line", IPC_MESSAGE_ID_LINE(message.type())); | 398 "line", IPC_MESSAGE_ID_LINE(message.type())); |
410 if (AttachmentBroker* broker = AttachmentBroker::GetGlobal()) { | 399 if (AttachmentBroker* broker = AttachmentBroker::GetGlobal()) { |
411 if (broker->OnMessageReceived(message)) | 400 if (broker->OnMessageReceived(message)) |
412 return; | 401 return; |
413 } | 402 } |
414 listener_->OnMessageReceived(message); | 403 listener_->OnMessageReceived(message); |
415 if (message.dispatch_error()) | 404 if (message.dispatch_error()) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 std::move(unwrapped_attachment)); | 461 std::move(unwrapped_attachment)); |
473 DCHECK(ok); | 462 DCHECK(ok); |
474 if (!ok) { | 463 if (!ok) { |
475 LOG(ERROR) << "Failed to add new Mojo handle."; | 464 LOG(ERROR) << "Failed to add new Mojo handle."; |
476 return MOJO_RESULT_UNKNOWN; | 465 return MOJO_RESULT_UNKNOWN; |
477 } | 466 } |
478 } | 467 } |
479 return MOJO_RESULT_OK; | 468 return MOJO_RESULT_OK; |
480 } | 469 } |
481 | 470 |
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 | |
501 } // namespace IPC | 471 } // namespace IPC |
OLD | NEW |