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

Side by Side Diff: ipc/mojo/ipc_channel_mojo.cc

Issue 554363004: ChannelMojo: Handle errors in pending message processing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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/mojo/ipc_channel_mojo.h" 5 #include "ipc/mojo/ipc_channel_mojo.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "ipc/ipc_listener.h" 10 #include "ipc/ipc_listener.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return control_reader_->Connect(); 164 return control_reader_->Connect();
165 } 165 }
166 166
167 void ChannelMojo::Close() { 167 void ChannelMojo::Close() {
168 control_reader_.reset(); 168 control_reader_.reset();
169 message_reader_.reset(); 169 message_reader_.reset();
170 channel_info_.reset(); 170 channel_info_.reset();
171 } 171 }
172 172
173 void ChannelMojo::OnConnected(mojo::ScopedMessagePipeHandle pipe) { 173 void ChannelMojo::OnConnected(mojo::ScopedMessagePipeHandle pipe) {
174 message_reader_ = 174 message_reader_ = CreateMessageReader(pipe.Pass());
175 make_scoped_ptr(new internal::MessageReader(pipe.Pass(), this));
176 175
177 for (size_t i = 0; i < pending_messages_.size(); ++i) { 176 for (size_t i = 0; i < pending_messages_.size(); ++i) {
178 message_reader_->Send(make_scoped_ptr(pending_messages_[i])); 177 bool sent = message_reader_->Send(make_scoped_ptr(pending_messages_[i]));
179 pending_messages_[i] = NULL; 178 pending_messages_[i] = NULL;
179 if (!sent) {
180 pending_messages_.clear();
181 listener_->OnChannelError();
182 return;
183 }
180 } 184 }
181 185
182 pending_messages_.clear(); 186 pending_messages_.clear();
183 187
184 listener_->OnChannelConnected(GetPeerPID()); 188 listener_->OnChannelConnected(GetPeerPID());
185 } 189 }
186 190
187 void ChannelMojo::OnPipeClosed(internal::MessagePipeReader* reader) { 191 void ChannelMojo::OnPipeClosed(internal::MessagePipeReader* reader) {
188 Close(); 192 Close();
189 } 193 }
(...skipping 23 matching lines...) Expand all
213 ChannelHandle ChannelMojo::TakePipeHandle() { 217 ChannelHandle ChannelMojo::TakePipeHandle() {
214 return bootstrap_->TakePipeHandle(); 218 return bootstrap_->TakePipeHandle();
215 } 219 }
216 220
217 void ChannelMojo::OnMessageReceived(Message& message) { 221 void ChannelMojo::OnMessageReceived(Message& message) {
218 listener_->OnMessageReceived(message); 222 listener_->OnMessageReceived(message);
219 if (message.dispatch_error()) 223 if (message.dispatch_error())
220 listener_->OnBadMessageReceived(message); 224 listener_->OnBadMessageReceived(message);
221 } 225 }
222 226
227 scoped_ptr<internal::MessageReader>
228 ChannelMojo::CreateMessageReader(
yzshen1 2014/09/15 17:26:07 nit: you could merge this line onto the previous o
Hajime Morrita 2014/09/15 18:16:53 Done.
229 mojo::ScopedMessagePipeHandle pipe) {
230 return make_scoped_ptr(new internal::MessageReader(pipe.Pass(), this));
231 }
232
233
223 #if defined(OS_POSIX) && !defined(OS_NACL) 234 #if defined(OS_POSIX) && !defined(OS_NACL)
224 int ChannelMojo::GetClientFileDescriptor() const { 235 int ChannelMojo::GetClientFileDescriptor() const {
225 return bootstrap_->GetClientFileDescriptor(); 236 return bootstrap_->GetClientFileDescriptor();
226 } 237 }
227 238
228 int ChannelMojo::TakeClientFileDescriptor() { 239 int ChannelMojo::TakeClientFileDescriptor() {
229 return bootstrap_->TakeClientFileDescriptor(); 240 return bootstrap_->TakeClientFileDescriptor();
230 } 241 }
231 242
232 // static 243 // static
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 handles->push_back(wrapped_handle); 291 handles->push_back(wrapped_handle);
281 } 292 }
282 } 293 }
283 294
284 return MOJO_RESULT_OK; 295 return MOJO_RESULT_OK;
285 } 296 }
286 297
287 #endif // defined(OS_POSIX) && !defined(OS_NACL) 298 #endif // defined(OS_POSIX) && !defined(OS_NACL)
288 299
289 } // namespace IPC 300 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698