Index: mojo/edk/system/message_pipe_dispatcher.cc |
diff --git a/mojo/edk/system/message_pipe_dispatcher.cc b/mojo/edk/system/message_pipe_dispatcher.cc |
index fb3ce4e9f3c2079041d56d04e22f46a191741991..df4cb0ffe816f85028a5d661db07a7a8743766c0 100644 |
--- a/mojo/edk/system/message_pipe_dispatcher.cc |
+++ b/mojo/edk/system/message_pipe_dispatcher.cc |
@@ -23,10 +23,6 @@ |
namespace mojo { |
namespace edk { |
-// TODO(jam): do more tests on using channel on same thread if it supports it ( |
-// i.e. with USE_CHROME_EDK and Windows). Also see ipc_channel_mojo.cc |
-bool g_use_channel_on_io_thread_only = true; |
- |
namespace { |
const size_t kInvalidMessagePipeHandleIndex = static_cast<size_t>(-1); |
@@ -134,13 +130,8 @@ void MessagePipeDispatcher::Init( |
serialized_read_buffer, serialized_read_buffer_size, |
serialized_write_buffer, serialized_write_buffer_size, |
serialized_read_fds, serialized_write_fds); |
- if (g_use_channel_on_io_thread_only) { |
- internal::g_io_thread_task_runner->PostTask( |
- FROM_HERE, base::Bind(&MessagePipeDispatcher::InitOnIO, this)); |
- } else { |
- InitOnIO(); |
- } |
- // TODO(jam): optimize for when running on IO thread? |
+ internal::g_io_thread_task_runner->PostTask( |
+ FROM_HERE, base::Bind(&MessagePipeDispatcher::InitOnIO, this)); |
} |
} |
@@ -357,8 +348,14 @@ MessagePipeDispatcher::MessagePipeDispatcher() |
} |
MessagePipeDispatcher::~MessagePipeDispatcher() { |
- // |Close()|/|CloseImplNoLock()| should have taken care of the channel. |
- DCHECK(!channel_); |
+ // |Close()|/|CloseImplNoLock()| should have taken care of the channel. The |
+ // exception is if they posted a task to run CloseOnIO but the IO thread shut |
+ // down and so when it was deleting pending tasks it caused the last reference |
+ // to destruct this object. In that case, safe to destroy the channel. |
+ if (channel_ && internal::g_io_thread_task_runner->RunsTasksOnCurrentThread()) |
+ channel_->Shutdown(); |
+ else |
+ DCHECK(!channel_); |
#if defined(OS_POSIX) |
ClosePlatformHandles(&serialized_fds_); |
#endif |
@@ -371,12 +368,8 @@ void MessagePipeDispatcher::CancelAllAwakablesNoLock() { |
void MessagePipeDispatcher::CloseImplNoLock() { |
lock().AssertAcquired(); |
- if (g_use_channel_on_io_thread_only) { |
- internal::g_io_thread_task_runner->PostTask( |
- FROM_HERE, base::Bind(&MessagePipeDispatcher::CloseOnIO, this)); |
- } else { |
- CloseOnIO(); |
- } |
+ internal::g_io_thread_task_runner->PostTask( |
+ FROM_HERE, base::Bind(&MessagePipeDispatcher::CloseOnIO, this)); |
} |
void MessagePipeDispatcher::SerializeInternal() { |