summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mojo/edk/embedder/embedder.cc48
-rw-r--r--mojo/edk/embedder/embedder.h5
-rw-r--r--mojo/edk/embedder/embedder_internal.h3
-rw-r--r--mojo/edk/system/multiprocess_message_pipe_unittest.cc12
-rw-r--r--mojo/edk/system/raw_channel.cc2
-rw-r--r--mojo/edk/system/raw_channel_win.cc9
-rw-r--r--mojo/edk/system/run_all_unittests.cc3
-rw-r--r--mojo/edk/test/scoped_ipc_support.cc2
8 files changed, 22 insertions, 62 deletions
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc
index f9b5c9d..eb572c5 100644
--- a/mojo/edk/embedder/embedder.cc
+++ b/mojo/edk/embedder/embedder.cc
@@ -28,25 +28,10 @@
namespace mojo {
namespace edk {
-// TODO(jam): move into annonymous namespace. Keep outside for debugging in VS
-// temporarily.
-int g_channel_count = 0;
-bool g_wait_for_no_more_channels = false;
-base::TaskRunner* g_delegate_task_runner = nullptr; // Used at shutdown.
-
namespace {
// Note: Called on the I/O thread.
-void ShutdownIPCSupportHelper(bool wait_for_no_more_channels) {
- if (wait_for_no_more_channels && g_channel_count) {
- g_wait_for_no_more_channels = true;
- return;
- }
-
- g_delegate_task_runner->PostTask(
- FROM_HERE, base::Bind(&ProcessDelegate::OnShutdownComplete,
- base::Unretained(internal::g_process_delegate)));
- g_delegate_task_runner = nullptr;
+void ShutdownIPCSupportHelper() {
}
} // namespace
@@ -65,23 +50,6 @@ Core* GetCore() {
return g_core;
}
-void ChannelStarted() {
- DCHECK(g_io_thread_task_runner->RunsTasksOnCurrentThread());
- g_channel_count++;
-}
-
-void ChannelShutdown() {
- DCHECK(g_io_thread_task_runner->RunsTasksOnCurrentThread());
- DCHECK_GT(g_channel_count, 0);
- g_channel_count--;
- if (!g_channel_count && g_wait_for_no_more_channels) {
- // Reset g_wait_for_no_more_channels for unit tests which initialize and
- // tear down multiple times in a process.
- g_wait_for_no_more_channels = false;
- ShutdownIPCSupportHelper(false);
- }
-}
-
} // namespace internal
void SetMaxMessageSize(size_t bytes) {
@@ -188,15 +156,11 @@ void ShutdownIPCSupportOnIOThread() {
}
void ShutdownIPCSupport() {
- g_delegate_task_runner = base::MessageLoop::current()->task_runner().get();
- internal::g_io_thread_task_runner->PostTask(
- FROM_HERE, base::Bind(&ShutdownIPCSupportHelper, false));
-}
-
-void ShutdownIPCSupportAndWaitForNoChannels() {
- g_delegate_task_runner = base::MessageLoop::current()->task_runner().get();
- internal::g_io_thread_task_runner->PostTask(
- FROM_HERE, base::Bind(&ShutdownIPCSupportHelper, true));
+ internal::g_io_thread_task_runner->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&ShutdownIPCSupportHelper),
+ base::Bind(&ProcessDelegate::OnShutdownComplete,
+ base::Unretained(internal::g_process_delegate)));
}
ScopedMessagePipeHandle CreateMessagePipe(
diff --git a/mojo/edk/embedder/embedder.h b/mojo/edk/embedder/embedder.h
index 5ba2449..a96c610 100644
--- a/mojo/edk/embedder/embedder.h
+++ b/mojo/edk/embedder/embedder.h
@@ -115,11 +115,6 @@ MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupportOnIOThread();
// |OnShutdownComplete()|.
MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupport();
-// Like above, but doesn't call |OnShutdownComplete| until all channels are
-// gone.
-// TODO(jam): this should be the default behavior.
-MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupportAndWaitForNoChannels();
-
// Creates a message pipe from a platform handle. Safe to call from any thread.
MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
CreateMessagePipe(ScopedPlatformHandle platform_handle);
diff --git a/mojo/edk/embedder/embedder_internal.h b/mojo/edk/embedder/embedder_internal.h
index 99ea392..a6fb2b1 100644
--- a/mojo/edk/embedder/embedder_internal.h
+++ b/mojo/edk/embedder/embedder_internal.h
@@ -43,9 +43,6 @@ extern base::TaskRunner* g_io_thread_task_runner;
// TODO(use_chrome_edk): temporary until we have only one SDK.
MOJO_SYSTEM_IMPL_EXPORT Core* GetCore();
-// Called on the IO thread.
-void ChannelStarted();
-void ChannelShutdown();
} // namespace internal
} // namepace edk
diff --git a/mojo/edk/system/multiprocess_message_pipe_unittest.cc b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
index 4abac12..4bb3f13 100644
--- a/mojo/edk/system/multiprocess_message_pipe_unittest.cc
+++ b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
@@ -166,12 +166,6 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_QueueMessages) {
nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE));
}
- const std::string quitquitquit("quitquitquit");
- ASSERT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(mp.get().value(), quitquitquit.data(),
- static_cast<uint32_t>(quitquitquit.size()),
- nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE));
-
for (size_t i = 0; i < kNumMessages; i++) {
HandleSignalsState hss;
ASSERT_EQ(MOJO_RESULT_OK,
@@ -194,6 +188,12 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_QueueMessages) {
ASSERT_EQ(std::string(i * 2, 'A' + (i % 26)), read_buffer);
}
+ const std::string quitquitquit("quitquitquit");
+ ASSERT_EQ(MOJO_RESULT_OK,
+ MojoWriteMessage(mp.get().value(), quitquitquit.data(),
+ static_cast<uint32_t>(quitquitquit.size()),
+ nullptr, 0u, MOJO_WRITE_MESSAGE_FLAG_NONE));
+
// Wait for it to become readable, which should fail (since we sent
// "quitquitquit").
HandleSignalsState hss;
diff --git a/mojo/edk/system/raw_channel.cc b/mojo/edk/system/raw_channel.cc
index a7faead..b60438e 100644
--- a/mojo/edk/system/raw_channel.cc
+++ b/mojo/edk/system/raw_channel.cc
@@ -221,7 +221,6 @@ void RawChannel::LazyInitialize() {
if (initialized_)
return;
initialized_ = true;
- internal::ChannelStarted();
base::MessageLoop::current()->AddDestructionObserver(this);
OnInit();
@@ -288,7 +287,6 @@ void RawChannel::Shutdown() {
}
if (initialized_) {
- internal::ChannelShutdown();
base::MessageLoop::current()->RemoveDestructionObserver(this);
}
delete this;
diff --git a/mojo/edk/system/raw_channel_win.cc b/mojo/edk/system/raw_channel_win.cc
index fa968a4..51a8e68 100644
--- a/mojo/edk/system/raw_channel_win.cc
+++ b/mojo/edk/system/raw_channel_win.cc
@@ -124,6 +124,7 @@ class RawChannelWin final : public RawChannel {
RawChannelIOHandler(RawChannelWin* owner,
ScopedPlatformHandle handle)
: handle_(handle.Pass()),
+ io_task_runner_(internal::g_io_thread_task_runner),
owner_(owner),
suppress_self_destruct_(false),
pending_read_(false),
@@ -465,7 +466,7 @@ class RawChannelWin final : public RawChannel {
// that that is always a pointer to a valid RawChannelIOHandler.
RawChannelIOHandler* that = static_cast<RawChannelIOHandler*>(param);
that->read_event_signalled_ = true;
- internal::g_io_thread_task_runner->PostTask(
+ that->io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&RawChannelIOHandler::OnObjectSignaled,
that->this_weakptr_, that->read_event_.Get()));
@@ -477,7 +478,7 @@ class RawChannelWin final : public RawChannel {
// that that is always a pointer to a valid RawChannelIOHandler.
RawChannelIOHandler* that = static_cast<RawChannelIOHandler*>(param);
that->write_event_signalled_ = true;
- internal::g_io_thread_task_runner->PostTask(
+ that->io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&RawChannelIOHandler::OnObjectSignaled,
that->this_weakptr_, that->write_event_.Get()));
@@ -485,6 +486,10 @@ class RawChannelWin final : public RawChannel {
ScopedPlatformHandle handle_;
+ // We cache this because ReadCompleted and WriteCompleted might get fired
+ // after ShutdownIPCSupport is called.
+ scoped_refptr<base::TaskRunner> io_task_runner_;
+
// |owner_| is reset on the I/O thread under |owner_->write_lock()|.
// Therefore, it may be used on any thread under lock; or on the I/O thread
// without locking.
diff --git a/mojo/edk/system/run_all_unittests.cc b/mojo/edk/system/run_all_unittests.cc
index 71e1465..b68fd83 100644
--- a/mojo/edk/system/run_all_unittests.cc
+++ b/mojo/edk/system/run_all_unittests.cc
@@ -26,10 +26,11 @@ int main(int argc, char** argv) {
mojo::edk::PreInitializeChildProcess();
}
- mojo::edk::Init();
// TODO(use_chrome_edk): temporary to force new EDK.
base::CommandLine::ForCurrentProcess()->AppendSwitch("--use-new-edk");
+ mojo::edk::Init();
+
return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
diff --git a/mojo/edk/test/scoped_ipc_support.cc b/mojo/edk/test/scoped_ipc_support.cc
index 6e9c11c..2c5ecd1 100644
--- a/mojo/edk/test/scoped_ipc_support.cc
+++ b/mojo/edk/test/scoped_ipc_support.cc
@@ -21,7 +21,7 @@ ScopedIPCSupportHelper::~ScopedIPCSupportHelper() {
base::MessageLoop::current()->task_runner() == io_thread_task_runner_) {
ShutdownIPCSupportOnIOThread();
} else {
- ShutdownIPCSupportAndWaitForNoChannels();
+ ShutdownIPCSupport();
run_loop_.Run();
}
}