diff options
author | Gabriel Charette <gab@chromium.org> | 2017-08-07 13:22:48 +0900 |
---|---|---|
committer | Qijiang Fan <fqj@google.com> | 2020-06-05 06:53:08 +0900 |
commit | 3c6f00b050c9c50206e81b65341c2625eebdf640 (patch) | |
tree | 8d37e48684a9220f32a5a5f3035752848ec84930 /base/message_loop/message_loop.cc | |
parent | c6b81780cd5ff3ad3058cacaeae7530511eaad95 (diff) | |
download | libchrome-3c6f00b050c9c50206e81b65341c2625eebdf640.tar.gz |
Introduce RunLoop::Type::NESTABLE_TASKS_ALLOWED to replace MessageLoop::ScopedNestableTaskAllower.
(as well as MessageLoop::SetNestableTasksAllowed())
Surveying usage: the scoped object is always instantiated right before
RunLoop().Run(). The intent is really to allow nestable tasks in that
RunLoop so it's better to explicitly label that RunLoop as such and it
allows us to break the last dependency that forced some RunLoop users
to use MessageLoop APIs.
There's also the odd case of allowing nestable tasks for loops that are
reentrant from a native task (without going through RunLoop), these
are the minority but will have to be handled (after cleaning up the
majority of cases that are RunLoop induced).
As highlighted by robliao@ in https://chromium-review.googlesource.com/c/600517
(which was merged in this CL).
R=danakj@chromium.org
Bug: 750779
Change-Id: I43d122c93ec903cff3a6fe7b77ec461ea0656448
Reviewed-on: https://chromium-review.googlesource.com/594713
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: Robert Liao <robliao@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#492263}
CrOS-Libchrome-Original-Commit: 3ff403eecdd23a39853a4ebca52023fbba6c5d00
Diffstat (limited to 'base/message_loop/message_loop.cc')
-rw-r--r-- | base/message_loop/message_loop.cc | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc index b9cae6c6d5..19e47f21cc 100644 --- a/base/message_loop/message_loop.cc +++ b/base/message_loop/message_loop.cc @@ -236,14 +236,14 @@ void MessageLoop::SetNestableTasksAllowed(bool allowed) { CHECK(RunLoop::IsNestingAllowedOnCurrentThread()); // Kick the native pump just in case we enter a OS-driven nested message - // loop. + // loop that does not go through RunLoop::Run(). pump_->ScheduleWork(); } nestable_tasks_allowed_ = allowed; } bool MessageLoop::NestableTasksAllowed() const { - return nestable_tasks_allowed_; + return nestable_tasks_allowed_ || run_loop_client_->ProcessingTasksAllowed(); } // TODO(gab): Migrate TaskObservers to RunLoop as part of separating concerns @@ -355,6 +355,13 @@ void MessageLoop::Quit() { pump_->Quit(); } +void MessageLoop::EnsureWorkScheduled() { + DCHECK_EQ(this, current()); + ReloadWorkQueue(); + if (!work_queue_.empty()) + pump_->ScheduleWork(); +} + void MessageLoop::SetThreadTaskRunnerHandle() { DCHECK_EQ(this, current()); // Clear the previous thread task runner first, because only one can exist at @@ -386,7 +393,7 @@ bool MessageLoop::ProcessNextDelayedNonNestableTask() { } void MessageLoop::RunTask(PendingTask* pending_task) { - DCHECK(nestable_tasks_allowed_); + DCHECK(NestableTasksAllowed()); current_pending_task_ = pending_task; #if defined(OS_WIN) @@ -491,7 +498,7 @@ void MessageLoop::ScheduleWork() { } bool MessageLoop::DoWork() { - if (!nestable_tasks_allowed_) { + if (!NestableTasksAllowed()) { // Task can't be executed right now. return false; } @@ -529,7 +536,7 @@ bool MessageLoop::DoWork() { } bool MessageLoop::DoDelayedWork(TimeTicks* next_delayed_work_time) { - if (!nestable_tasks_allowed_ || + if (!NestableTasksAllowed() || !SweepDelayedWorkQueueAndReturnTrueIfStillHasWork()) { recent_time_ = *next_delayed_work_time = TimeTicks(); return false; |