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

Unified Diff: mojo/system/raw_channel.cc

Issue 257623003: Mojo: Add RawChannel tests for calling Shutdown() from OnReadMessage()/OnFatalError(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add comment Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/system/raw_channel.h ('k') | mojo/system/raw_channel_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/raw_channel.cc
diff --git a/mojo/system/raw_channel.cc b/mojo/system/raw_channel.cc
index 80f21765fcd641a5ad8e28ef25d9e7a69ad671e6..d9febeb38fc61008d18de152f6100bf852ed30ae 100644
--- a/mojo/system/raw_channel.cc
+++ b/mojo/system/raw_channel.cc
@@ -92,8 +92,8 @@ size_t RawChannel::WriteBuffer::GetTotalBytesToWrite() const {
}
RawChannel::RawChannel()
- : delegate_(NULL),
- message_loop_for_io_(NULL),
+ : message_loop_for_io_(NULL),
+ delegate_(NULL),
read_stopped_(false),
write_stopped_(false),
weak_ptr_factory_(this) {
@@ -140,10 +140,11 @@ void RawChannel::Shutdown() {
LOG_IF(WARNING, !write_buffer_->message_queue_.empty())
<< "Shutting down RawChannel with write buffer nonempty";
- weak_ptr_factory_.InvalidateWeakPtrs();
-
+ // Reset the delegate so that it won't receive further calls.
+ delegate_ = NULL;
read_stopped_ = true;
write_stopped_ = true;
+ weak_ptr_factory_.InvalidateWeakPtrs();
OnShutdownNoLock(read_buffer_.Pass(), write_buffer_.Pass());
}
@@ -254,6 +255,7 @@ void RawChannel::OnReadCompleted(bool result, size_t bytes_read) {
DCHECK_EQ(message_view.total_size(), message_size);
// Dispatch the message.
+ DCHECK(delegate_);
delegate_->OnReadMessage(message_view);
if (read_stopped_) {
// |Shutdown()| was called in |OnReadMessage()|.
@@ -328,7 +330,8 @@ void RawChannel::OnWriteCompleted(bool result, size_t bytes_written) {
void RawChannel::CallOnFatalError(Delegate::FatalError fatal_error) {
DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io_);
// TODO(vtl): Add a "write_lock_.AssertNotAcquired()"?
- delegate_->OnFatalError(fatal_error);
+ if (delegate_)
+ delegate_->OnFatalError(fatal_error);
}
bool RawChannel::OnWriteCompletedNoLock(bool result, size_t bytes_written) {
« no previous file with comments | « mojo/system/raw_channel.h ('k') | mojo/system/raw_channel_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698