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_message_pipe_reader.h" | 5 #include "ipc/ipc_message_pipe_reader.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 const std::string& name, | 78 const std::string& name, |
79 mojo::ScopedInterfaceEndpointHandle handle) { | 79 mojo::ScopedInterfaceEndpointHandle handle) { |
80 if (!sender_.is_bound()) | 80 if (!sender_.is_bound()) |
81 return; | 81 return; |
82 mojom::GenericInterfaceAssociatedRequest request; | 82 mojom::GenericInterfaceAssociatedRequest request; |
83 request.Bind(std::move(handle)); | 83 request.Bind(std::move(handle)); |
84 sender_->GetAssociatedInterface(name, std::move(request)); | 84 sender_->GetAssociatedInterface(name, std::move(request)); |
85 } | 85 } |
86 | 86 |
87 void MessagePipeReader::SetPeerPid(int32_t peer_pid) { | 87 void MessagePipeReader::SetPeerPid(int32_t peer_pid) { |
88 peer_pid_ = peer_pid; | 88 delegate_->OnPeerPidReceived(peer_pid); |
89 delegate_->OnPeerPidReceived(); | |
90 } | 89 } |
91 | 90 |
92 void MessagePipeReader::Receive( | 91 void MessagePipeReader::Receive( |
93 const std::vector<uint8_t>& data, | 92 const std::vector<uint8_t>& data, |
94 base::Optional<std::vector<mojom::SerializedHandlePtr>> handles) { | 93 base::Optional<std::vector<mojom::SerializedHandlePtr>> handles) { |
95 DCHECK_NE(peer_pid_, base::kNullProcessId); | |
96 Message message( | 94 Message message( |
97 data.empty() ? "" : reinterpret_cast<const char*>(data.data()), | 95 data.empty() ? "" : reinterpret_cast<const char*>(data.data()), |
98 static_cast<uint32_t>(data.size())); | 96 static_cast<uint32_t>(data.size())); |
99 message.set_sender_pid(peer_pid_); | |
100 | 97 |
101 DVLOG(4) << "Receive " << message.type() << ": " << message.size(); | 98 DVLOG(4) << "Receive " << message.type() << ": " << message.size(); |
102 MojoResult write_result = | 99 MojoResult write_result = |
103 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message); | 100 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message); |
104 if (write_result != MOJO_RESULT_OK) { | 101 if (write_result != MOJO_RESULT_OK) { |
105 OnPipeError(write_result); | 102 OnPipeError(write_result); |
106 return; | 103 return; |
107 } | 104 } |
108 | 105 |
109 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), | 106 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), |
(...skipping 16 matching lines...) Expand all Loading... |
126 | 123 |
127 Close(); | 124 Close(); |
128 | 125 |
129 // NOTE: The delegate call below may delete |this|. | 126 // NOTE: The delegate call below may delete |this|. |
130 if (delegate_) | 127 if (delegate_) |
131 delegate_->OnPipeError(); | 128 delegate_->OnPipeError(); |
132 } | 129 } |
133 | 130 |
134 } // namespace internal | 131 } // namespace internal |
135 } // namespace IPC | 132 } // namespace IPC |
OLD | NEW |