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

Side by Side Diff: ipc/ipc_channel_mojo.cc

Issue 2136903002: With ChannelMojo, don't error the channel on Send failure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplify 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 | « no previous file | no next file » | 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_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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (task_runner_->RunsTasksOnCurrentThread()) { 349 if (task_runner_->RunsTasksOnCurrentThread()) {
350 listener_->OnChannelError(); 350 listener_->OnChannelError();
351 } else { 351 } else {
352 task_runner_->PostTask( 352 task_runner_->PostTask(
353 FROM_HERE, 353 FROM_HERE,
354 base::Bind(&ChannelMojo::OnPipeError, weak_factory_.GetWeakPtr())); 354 base::Bind(&ChannelMojo::OnPipeError, weak_factory_.GetWeakPtr()));
355 } 355 }
356 } 356 }
357 357
358 bool ChannelMojo::Send(Message* message) { 358 bool ChannelMojo::Send(Message* message) {
359 bool sent = false; 359 base::AutoLock lock(lock_);
360 { 360 if (!message_reader_) {
361 base::AutoLock lock(lock_); 361 pending_messages_.push_back(base::WrapUnique(message));
362 if (!message_reader_) { 362 // Counts as OK before the connection is established, but it's an
363 pending_messages_.push_back(base::WrapUnique(message)); 363 // error otherwise.
364 // Counts as OK before the connection is established, but it's an 364 return waiting_connect_;
365 // error otherwise.
366 return waiting_connect_;
367 }
368
369 sent = message_reader_->Send(base::WrapUnique(message));
370 } 365 }
371 366
372 if (!sent) { 367 // Comment copied from ipc_channel_posix.cc:
373 OnPipeError(); 368 // We can't close the pipe here, because calling OnChannelError may destroy
374 return false; 369 // this object, and that would be bad if we are called from Send(). Instead,
375 } 370 // we return false and hope the caller will close the pipe. If they do not,
376 371 // the pipe will still be closed next time OnFileCanReadWithoutBlocking is
377 return true; 372 // called.
373 //
374 // With Mojo, there's no OnFileCanReadWithoutBlocking, but we expect the
375 // pipe's connection error handler will be invoked in its place.
376 return message_reader_->Send(base::WrapUnique(message));
378 } 377 }
379 378
380 bool ChannelMojo::IsSendThreadSafe() const { 379 bool ChannelMojo::IsSendThreadSafe() const {
381 return false; 380 return false;
382 } 381 }
383 382
384 base::ProcessId ChannelMojo::GetPeerPID() const { 383 base::ProcessId ChannelMojo::GetPeerPID() const {
385 base::AutoLock lock(lock_); 384 base::AutoLock lock(lock_);
386 if (!message_reader_) 385 if (!message_reader_)
387 return base::kNullProcessId; 386 return base::kNullProcessId;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 DCHECK(ok); 462 DCHECK(ok);
464 if (!ok) { 463 if (!ok) {
465 LOG(ERROR) << "Failed to add new Mojo handle."; 464 LOG(ERROR) << "Failed to add new Mojo handle.";
466 return MOJO_RESULT_UNKNOWN; 465 return MOJO_RESULT_UNKNOWN;
467 } 466 }
468 } 467 }
469 return MOJO_RESULT_OK; 468 return MOJO_RESULT_OK;
470 } 469 }
471 470
472 } // namespace IPC 471 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698