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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 DCHECK_LE(num_handles, std::numeric_limits<uint32_t>::max()); | 108 DCHECK_LE(num_handles, std::numeric_limits<uint32_t>::max()); |
109 | 109 |
110 mojo_message->set_interface_id(sender_interface_id_); | 110 mojo_message->set_interface_id(sender_interface_id_); |
111 result = mojo::WriteMessageNew(sender_pipe_, mojo_message->TakeMojoMessage(), | 111 result = mojo::WriteMessageNew(sender_pipe_, mojo_message->TakeMojoMessage(), |
112 MOJO_WRITE_MESSAGE_FLAG_NONE); | 112 MOJO_WRITE_MESSAGE_FLAG_NONE); |
113 | 113 |
114 DVLOG(4) << "Send " << message->type() << ": " << message->size(); | 114 DVLOG(4) << "Send " << message->type() << ": " << message->size(); |
115 return result == MOJO_RESULT_OK; | 115 return result == MOJO_RESULT_OK; |
116 } | 116 } |
117 | 117 |
118 void MessagePipeReader::GetRemoteInterface( | |
119 const std::string& name, | |
120 mojo::ScopedInterfaceEndpointHandle handle) { | |
121 mojom::GenericInterfaceAssociatedRequest request; | |
122 request.Bind(std::move(handle)); | |
123 sender_->GetAssociatedInterface(name, std::move(request)); | |
124 } | |
125 | |
126 void MessagePipeReader::Receive( | 118 void MessagePipeReader::Receive( |
127 mojo::Array<uint8_t> data, | 119 mojo::Array<uint8_t> data, |
128 mojo::Array<mojom::SerializedHandlePtr> handles) { | 120 mojo::Array<mojom::SerializedHandlePtr> handles) { |
129 Message message( | 121 Message message( |
130 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]), | 122 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]), |
131 static_cast<uint32_t>(data.size())); | 123 static_cast<uint32_t>(data.size())); |
132 message.set_sender_pid(peer_pid_); | 124 message.set_sender_pid(peer_pid_); |
133 | 125 |
134 DVLOG(4) << "Receive " << message.type() << ": " << message.size(); | 126 DVLOG(4) << "Receive " << message.type() << ": " << message.size(); |
135 MojoResult write_result = | 127 MojoResult write_result = |
136 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message); | 128 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message); |
137 if (write_result != MOJO_RESULT_OK) { | 129 if (write_result != MOJO_RESULT_OK) { |
138 OnPipeError(write_result); | 130 OnPipeError(write_result); |
139 return; | 131 return; |
140 } | 132 } |
141 | 133 |
142 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), | 134 TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), |
143 "MessagePipeReader::Receive", | 135 "MessagePipeReader::Receive", |
144 message.flags(), | 136 message.flags(), |
145 TRACE_EVENT_FLAG_FLOW_IN); | 137 TRACE_EVENT_FLAG_FLOW_IN); |
146 delegate_->OnMessageReceived(message); | 138 delegate_->OnMessageReceived(message); |
147 } | 139 } |
148 | 140 |
149 void MessagePipeReader::GetAssociatedInterface( | |
150 const mojo::String& name, | |
151 mojom::GenericInterfaceAssociatedRequest request) { | |
152 DCHECK(thread_checker_.CalledOnValidThread()); | |
153 if (delegate_) | |
154 delegate_->OnAssociatedInterfaceRequest(name, request.PassHandle()); | |
155 } | |
156 | |
157 void MessagePipeReader::OnPipeError(MojoResult error) { | 141 void MessagePipeReader::OnPipeError(MojoResult error) { |
158 DCHECK(thread_checker_.CalledOnValidThread()); | 142 DCHECK(thread_checker_.CalledOnValidThread()); |
159 if (delegate_) | 143 if (delegate_) |
160 delegate_->OnPipeError(); | 144 delegate_->OnPipeError(); |
161 Close(); | 145 Close(); |
162 } | 146 } |
163 | 147 |
164 void MessagePipeReader::DelayedDeleter::operator()( | 148 void MessagePipeReader::DelayedDeleter::operator()( |
165 MessagePipeReader* ptr) const { | 149 MessagePipeReader* ptr) const { |
166 ptr->Close(); | 150 ptr->Close(); |
167 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 151 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
168 base::Bind(&DeleteNow, ptr)); | 152 base::Bind(&DeleteNow, ptr)); |
169 } | 153 } |
170 | 154 |
171 } // namespace internal | 155 } // namespace internal |
172 } // namespace IPC | 156 } // namespace IPC |
OLD | NEW |