mist: use run_loop quit closure
BUG=chromium:909719
TEST=cros_run_unit_tests --board=betty --packages mist
Change-Id: If498a709fd4113ceabc87c9b3ed2984a28003e31
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1904774
Tested-by: Qijiang Fan <fqj@google.com>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
Commit-Queue: Qijiang Fan <fqj@google.com>
diff --git a/mist/event_dispatcher.cc b/mist/event_dispatcher.cc
index bb36485..562b458 100644
--- a/mist/event_dispatcher.cc
+++ b/mist/event_dispatcher.cc
@@ -4,6 +4,8 @@
#include "mist/event_dispatcher.h"
+#include <utility>
+
#include <base/location.h>
#include <base/run_loop.h>
#include <base/strings/stringprintf.h>
@@ -17,13 +19,13 @@
EventDispatcher::~EventDispatcher() = default;
void EventDispatcher::DispatchForever() {
- base::RunLoop().Run();
+ base::RunLoop run_loop;
+ quit_closure_ = run_loop.QuitWhenIdleClosure();
+ run_loop.Run();
}
void EventDispatcher::Stop() {
- // TODO(ejcaruso): move to RunLoop::QuitWhenIdleClosure after libchrome uprev
- base::MessageLoop::current()->task_runner()->PostTask(
- FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
+ task_runner_->PostTask(FROM_HERE, std::move(quit_closure_));
}
bool EventDispatcher::PostTask(const base::Closure& task) {
diff --git a/mist/event_dispatcher.h b/mist/event_dispatcher.h
index 6ca82c9..cfbaa73 100644
--- a/mist/event_dispatcher.h
+++ b/mist/event_dispatcher.h
@@ -68,6 +68,7 @@
base::MessageLoopForIO message_loop_; // Do not use this directly.
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ base::OnceClosure quit_closure_;
base::FileDescriptorWatcher watcher_{&message_loop_};
std::map<int, Watcher> file_descriptor_watchers_;