d09cab2e21
Migrate base::TaskRunner from Closure to OnceClosure https://codereview.chromium.org/2637843002 Pass Callback to TaskRunner by value and consume it on invocation (1) https://codereview.chromium.org/2726523002 Replace base::get with std::get https://codereview.chromium.org/2797133002
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
// Copyright (c) 2015 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "atom/browser/bridge_task_runner.h"
|
|
|
|
#include "base/message_loop/message_loop.h"
|
|
|
|
namespace atom {
|
|
|
|
void BridgeTaskRunner::MessageLoopIsReady() {
|
|
auto message_loop = base::MessageLoop::current();
|
|
CHECK(message_loop);
|
|
for (const TaskPair& task : tasks_) {
|
|
message_loop->task_runner()->PostDelayedTask(
|
|
std::get<0>(task), std::get<1>(task), std::get<2>(task));
|
|
}
|
|
for (const TaskPair& task : non_nestable_tasks_) {
|
|
message_loop->task_runner()->PostNonNestableDelayedTask(
|
|
std::get<0>(task), std::get<1>(task), std::get<2>(task));
|
|
}
|
|
}
|
|
|
|
bool BridgeTaskRunner::PostDelayedTask(
|
|
const tracked_objects::Location& from_here,
|
|
base::OnceClosure task,
|
|
base::TimeDelta delay) {
|
|
auto message_loop = base::MessageLoop::current();
|
|
if (!message_loop) {
|
|
tasks_.push_back(std::make_tuple(from_here, task, delay));
|
|
return true;
|
|
}
|
|
|
|
return message_loop->task_runner()->PostDelayedTask(
|
|
from_here, std::move(task), delay);
|
|
}
|
|
|
|
bool BridgeTaskRunner::RunsTasksOnCurrentThread() const {
|
|
auto message_loop = base::MessageLoop::current();
|
|
if (!message_loop)
|
|
return true;
|
|
|
|
return message_loop->task_runner()->RunsTasksOnCurrentThread();
|
|
}
|
|
|
|
bool BridgeTaskRunner::PostNonNestableDelayedTask(
|
|
const tracked_objects::Location& from_here,
|
|
base::OnceClosure task,
|
|
base::TimeDelta delay) {
|
|
auto message_loop = base::MessageLoop::current();
|
|
if (!message_loop) {
|
|
non_nestable_tasks_.push_back(std::make_tuple(from_here, task, delay));
|
|
return true;
|
|
}
|
|
|
|
return message_loop->task_runner()->PostNonNestableDelayedTask(
|
|
from_here, std::move(task), delay);
|
|
}
|
|
|
|
} // namespace atom
|