From bbed3cf3c13555bc6560101a1014ba82074ca6ef Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Fri, 9 Jun 2017 13:40:34 -0700 Subject: [PATCH] Bug 1366072 - Use nsIRunnable instead of Runnable in MessageLoop (r=kanru) MozReview-Commit-ID: 9LmBghd0D46 --- ipc/chromium/src/base/message_loop.cc | 16 ++++++++-------- ipc/chromium/src/base/message_loop.h | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/ipc/chromium/src/base/message_loop.cc b/ipc/chromium/src/base/message_loop.cc index 24af0692f295..8ee3338e3a88 100644 --- a/ipc/chromium/src/base/message_loop.cc +++ b/ipc/chromium/src/base/message_loop.cc @@ -248,7 +248,7 @@ bool MessageLoop::ProcessNextDelayedNonNestableTask() { if (deferred_non_nestable_work_queue_.empty()) return false; - RefPtr task = deferred_non_nestable_work_queue_.front().task.forget(); + nsCOMPtr task = deferred_non_nestable_work_queue_.front().task.forget(); deferred_non_nestable_work_queue_.pop(); RunTask(task.forget()); @@ -266,15 +266,15 @@ void MessageLoop::Quit() { } } -void MessageLoop::PostTask(already_AddRefed task) { +void MessageLoop::PostTask(already_AddRefed task) { PostTask_Helper(Move(task), 0); } -void MessageLoop::PostDelayedTask(already_AddRefed task, int delay_ms) { +void MessageLoop::PostDelayedTask(already_AddRefed task, int delay_ms) { PostTask_Helper(Move(task), delay_ms); } -void MessageLoop::PostIdleTask(already_AddRefed task) { +void MessageLoop::PostIdleTask(already_AddRefed task) { DCHECK(current() == this); MOZ_ASSERT(NS_IsMainThread()); @@ -283,7 +283,7 @@ void MessageLoop::PostIdleTask(already_AddRefed task) { } // Possibly called on a background thread! -void MessageLoop::PostTask_Helper(already_AddRefed task, int delay_ms) { +void MessageLoop::PostTask_Helper(already_AddRefed task, int delay_ms) { if (nsIEventTarget* target = pump_->GetXPCOMThread()) { nsresult rv; if (delay_ms) { @@ -296,7 +296,7 @@ void MessageLoop::PostTask_Helper(already_AddRefed task, int delay_ms) } #ifdef MOZ_TASK_TRACER - RefPtr tracedTask = task; + nsCOMPtr tracedTask = task; if (mozilla::tasktracer::IsStartLogging()) { tracedTask = mozilla::tasktracer::CreateTracedRunnable(Move(task)); (static_cast(tracedTask.get()))->DispatchTask(); @@ -352,12 +352,12 @@ bool MessageLoop::NestableTasksAllowed() const { //------------------------------------------------------------------------------ -void MessageLoop::RunTask(already_AddRefed aTask) { +void MessageLoop::RunTask(already_AddRefed aTask) { DCHECK(nestable_tasks_allowed_); // Execute the task and assume the worst: It is probably not reentrant. nestable_tasks_allowed_ = false; - RefPtr task = aTask; + nsCOMPtr task = aTask; task->Run(); task = nullptr; diff --git a/ipc/chromium/src/base/message_loop.h b/ipc/chromium/src/base/message_loop.h index 6fbe6fcb5846..189e384998e3 100644 --- a/ipc/chromium/src/base/message_loop.h +++ b/ipc/chromium/src/base/message_loop.h @@ -26,6 +26,8 @@ #endif #include "nsAutoPtr.h" +#include "nsCOMPtr.h" +#include "nsIRunnable.h" #include "nsThreadUtils.h" class nsIThread; @@ -112,12 +114,12 @@ public: // NOTE: These methods may be called on any thread. The Task will be invoked // on the thread that executes MessageLoop::Run(). - void PostTask(already_AddRefed task); + void PostTask(already_AddRefed task); - void PostDelayedTask(already_AddRefed task, int delay_ms); + void PostDelayedTask(already_AddRefed task, int delay_ms); // PostIdleTask is not thread safe and should be called on this thread - void PostIdleTask(already_AddRefed task); + void PostIdleTask(already_AddRefed task); // Run the message loop. void Run(); @@ -282,12 +284,12 @@ public: // This structure is copied around by value. struct PendingTask { - RefPtr task; // The task to run. + nsCOMPtr task; // The task to run. base::TimeTicks delayed_run_time; // The time when the task should be run. int sequence_num; // Secondary sort key for run time. bool nestable; // OK to dispatch from a nested loop. - PendingTask(already_AddRefed aTask, bool aNestable) + PendingTask(already_AddRefed aTask, bool aNestable) : task(aTask), sequence_num(0), nestable(aNestable) { } @@ -355,10 +357,10 @@ public: // appended to the list work_queue_. Such re-entrancy generally happens when // an unrequested message pump (typical of a native dialog) is executing in // the context of a task. - bool QueueOrRunTask(already_AddRefed new_task); + bool QueueOrRunTask(already_AddRefed new_task); // Runs the specified task and deletes it. - void RunTask(already_AddRefed task); + void RunTask(already_AddRefed task); // Calls RunTask or queues the pending_task on the deferred task list if it // cannot be run right now. Returns true if the task was run. @@ -378,7 +380,7 @@ public: bool DeletePendingTasks(); // Post a task to our incomming queue. - void PostTask_Helper(already_AddRefed task, int delay_ms); + void PostTask_Helper(already_AddRefed task, int delay_ms); // base::MessagePump::Delegate methods: virtual bool DoWork() override;