Commit 5085101b authored by rockot's avatar rockot Committed by Commit bot

Force immediate Mojo EDK shutdown on IO loop destruction.

This is an addendum to r329262 which still didn't quite
get it right.

The assumption here is now that the IPCSupportInitializer
must outlive the IO thread anyway, so the IO loop observer
may (and should) call ForceShutdown immediately rather
than posting a task.

BUG=486004
R=jam@chromium.org

Review URL: https://codereview.chromium.org/1143433003

Cr-Commit-Position: refs/heads/master@{#329692}
parent 3025623d
......@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
......@@ -26,8 +25,7 @@ class IPCSupportInitializer : public mojo::embedder::ProcessDelegate {
: init_count_(0),
shutting_down_(false),
was_shut_down_(false),
observer_(nullptr),
weak_factory_(this) {}
observer_(nullptr) {}
~IPCSupportInitializer() override { DCHECK(!observer_); }
......@@ -43,11 +41,8 @@ class IPCSupportInitializer : public mojo::embedder::ProcessDelegate {
// exists when the loop is being destroyed.
class MessageLoopObserver : public base::MessageLoop::DestructionObserver {
public:
MessageLoopObserver(
scoped_refptr<base::TaskRunner> initializer_task_runner,
base::WeakPtr<IPCSupportInitializer> weak_initializer)
: initializer_task_runner_(initializer_task_runner),
weak_initializer_(weak_initializer) {}
MessageLoopObserver(IPCSupportInitializer* initializer)
: initializer_(initializer) {}
~MessageLoopObserver() override {
base::MessageLoop::current()->RemoveDestructionObserver(this);
......@@ -56,13 +51,10 @@ class IPCSupportInitializer : public mojo::embedder::ProcessDelegate {
private:
// base::MessageLoop::DestructionObserver:
void WillDestroyCurrentMessageLoop() override {
initializer_task_runner_->PostTask(
FROM_HERE,
base::Bind(&IPCSupportInitializer::ForceShutdown, weak_initializer_));
initializer_->ForceShutdown();
}
scoped_refptr<base::TaskRunner> initializer_task_runner_;
base::WeakPtr<IPCSupportInitializer> weak_initializer_;
IPCSupportInitializer* initializer_;
DISALLOW_COPY_AND_ASSIGN(MessageLoopObserver);
};
......@@ -89,8 +81,6 @@ class IPCSupportInitializer : public mojo::embedder::ProcessDelegate {
scoped_refptr<base::TaskRunner> io_thread_task_runner_;
base::WeakPtrFactory<IPCSupportInitializer> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(IPCSupportInitializer);
};
......@@ -111,8 +101,7 @@ void IPCSupportInitializer::Init(
init_count_++;
if (init_count_ == 1) {
was_shut_down_ = false;
observer_ = new MessageLoopObserver(base::ThreadTaskRunnerHandle::Get(),
weak_factory_.GetWeakPtr());
observer_ = new MessageLoopObserver(this);
io_thread_task_runner_ = io_thread_task_runner;
io_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&WatchMessageLoopOnIOThread, observer_));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment