Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: ipc/ipc_message_pipe_reader.cc

Issue 2163633003: Support early associated interface binding on ChannelMojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicit-channel-ipc-task-runner
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_message_pipe_reader.h ('k') | ipc/ipc_mojo_bootstrap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 DISALLOW_COPY_AND_ASSIGN(MessageSerializer); 49 DISALLOW_COPY_AND_ASSIGN(MessageSerializer);
50 }; 50 };
51 51
52 } // namespace 52 } // namespace
53 53
54 MessagePipeReader::MessagePipeReader( 54 MessagePipeReader::MessagePipeReader(
55 mojo::MessagePipeHandle pipe, 55 mojo::MessagePipeHandle pipe,
56 mojom::ChannelAssociatedPtr sender, 56 mojom::ChannelAssociatedPtr sender,
57 mojo::AssociatedInterfaceRequest<mojom::Channel> receiver, 57 mojo::AssociatedInterfaceRequest<mojom::Channel> receiver,
58 base::ProcessId peer_pid,
59 MessagePipeReader::Delegate* delegate) 58 MessagePipeReader::Delegate* delegate)
60 : delegate_(delegate), 59 : delegate_(delegate),
61 peer_pid_(peer_pid),
62 sender_(std::move(sender)), 60 sender_(std::move(sender)),
63 binding_(this, std::move(receiver)), 61 binding_(this, std::move(receiver)),
64 sender_interface_id_(sender_.interface_id()), 62 sender_interface_id_(sender_.interface_id()),
65 sender_pipe_(pipe) { 63 sender_pipe_(pipe) {
66 sender_.set_connection_error_handler( 64 sender_.set_connection_error_handler(
67 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this), 65 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this),
68 MOJO_RESULT_FAILED_PRECONDITION)); 66 MOJO_RESULT_FAILED_PRECONDITION));
69 binding_.set_connection_error_handler( 67 binding_.set_connection_error_handler(
70 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this), 68 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this),
71 MOJO_RESULT_FAILED_PRECONDITION)); 69 MOJO_RESULT_FAILED_PRECONDITION));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 114 }
117 115
118 void MessagePipeReader::GetRemoteInterface( 116 void MessagePipeReader::GetRemoteInterface(
119 const std::string& name, 117 const std::string& name,
120 mojo::ScopedInterfaceEndpointHandle handle) { 118 mojo::ScopedInterfaceEndpointHandle handle) {
121 mojom::GenericInterfaceAssociatedRequest request; 119 mojom::GenericInterfaceAssociatedRequest request;
122 request.Bind(std::move(handle)); 120 request.Bind(std::move(handle));
123 sender_->GetAssociatedInterface(name, std::move(request)); 121 sender_->GetAssociatedInterface(name, std::move(request));
124 } 122 }
125 123
124 void MessagePipeReader::SetPeerPid(int32_t peer_pid) {
125 peer_pid_ = peer_pid;
126 delegate_->OnPeerPidReceived();
127 }
128
126 void MessagePipeReader::Receive( 129 void MessagePipeReader::Receive(
127 mojo::Array<uint8_t> data, 130 mojo::Array<uint8_t> data,
128 mojo::Array<mojom::SerializedHandlePtr> handles) { 131 mojo::Array<mojom::SerializedHandlePtr> handles) {
132 DCHECK_NE(peer_pid_, base::kNullProcessId);
129 Message message( 133 Message message(
130 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]), 134 data.size() == 0 ? "" : reinterpret_cast<const char*>(&data[0]),
131 static_cast<uint32_t>(data.size())); 135 static_cast<uint32_t>(data.size()));
132 message.set_sender_pid(peer_pid_); 136 message.set_sender_pid(peer_pid_);
133 137
134 DVLOG(4) << "Receive " << message.type() << ": " << message.size(); 138 DVLOG(4) << "Receive " << message.type() << ": " << message.size();
135 MojoResult write_result = 139 MojoResult write_result =
136 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message); 140 ChannelMojo::WriteToMessageAttachmentSet(std::move(handles), &message);
137 if (write_result != MOJO_RESULT_OK) { 141 if (write_result != MOJO_RESULT_OK) {
138 OnPipeError(write_result); 142 OnPipeError(write_result);
(...skipping 10 matching lines...) Expand all
149 void MessagePipeReader::GetAssociatedInterface( 153 void MessagePipeReader::GetAssociatedInterface(
150 const mojo::String& name, 154 const mojo::String& name,
151 mojom::GenericInterfaceAssociatedRequest request) { 155 mojom::GenericInterfaceAssociatedRequest request) {
152 DCHECK(thread_checker_.CalledOnValidThread()); 156 DCHECK(thread_checker_.CalledOnValidThread());
153 if (delegate_) 157 if (delegate_)
154 delegate_->OnAssociatedInterfaceRequest(name, request.PassHandle()); 158 delegate_->OnAssociatedInterfaceRequest(name, request.PassHandle());
155 } 159 }
156 160
157 void MessagePipeReader::OnPipeError(MojoResult error) { 161 void MessagePipeReader::OnPipeError(MojoResult error) {
158 DCHECK(thread_checker_.CalledOnValidThread()); 162 DCHECK(thread_checker_.CalledOnValidThread());
163
164 Close();
165
166 // NOTE: The delegate call below may delete |this|.
159 if (delegate_) 167 if (delegate_)
160 delegate_->OnPipeError(); 168 delegate_->OnPipeError();
161 Close();
162 }
163
164 void MessagePipeReader::DelayedDeleter::operator()(
165 MessagePipeReader* ptr) const {
166 ptr->Close();
167 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
168 base::Bind(&DeleteNow, ptr));
169 } 169 }
170 170
171 } // namespace internal 171 } // namespace internal
172 } // namespace IPC 172 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_pipe_reader.h ('k') | ipc/ipc_mojo_bootstrap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698