2015-09-02 07:52:17 +00:00
|
|
|
// 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 {
|
|
|
|
|
2015-10-22 07:54:27 +00:00
|
|
|
void BridgeTaskRunner::MessageLoopIsReady() {
|
|
|
|
auto message_loop = base::MessageLoop::current();
|
|
|
|
CHECK(message_loop);
|
2017-06-20 16:18:23 +00:00
|
|
|
for (TaskPair& task : tasks_) {
|
2015-10-22 07:54:27 +00:00
|
|
|
message_loop->task_runner()->PostDelayedTask(
|
2017-06-20 16:18:23 +00:00
|
|
|
std::get<0>(task), std::move(std::get<1>(task)), std::get<2>(task));
|
2015-10-22 07:54:27 +00:00
|
|
|
}
|
2017-06-20 16:18:23 +00:00
|
|
|
for (TaskPair& task : non_nestable_tasks_) {
|
2015-10-22 07:54:27 +00:00
|
|
|
message_loop->task_runner()->PostNonNestableDelayedTask(
|
2017-06-20 16:18:23 +00:00
|
|
|
std::get<0>(task), std::move(std::get<1>(task)), std::get<2>(task));
|
2015-10-22 07:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 07:52:17 +00:00
|
|
|
bool BridgeTaskRunner::PostDelayedTask(
|
|
|
|
const tracked_objects::Location& from_here,
|
2017-06-16 20:39:08 +00:00
|
|
|
base::OnceClosure task,
|
2015-09-02 07:52:17 +00:00
|
|
|
base::TimeDelta delay) {
|
|
|
|
auto message_loop = base::MessageLoop::current();
|
2015-10-22 07:54:27 +00:00
|
|
|
if (!message_loop) {
|
2017-06-20 16:18:23 +00:00
|
|
|
tasks_.push_back(std::make_tuple(from_here, std::move(task), delay));
|
2015-10-22 07:54:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-02 07:52:17 +00:00
|
|
|
|
2017-06-16 20:39:08 +00:00
|
|
|
return message_loop->task_runner()->PostDelayedTask(
|
|
|
|
from_here, std::move(task), delay);
|
2015-09-02 07:52:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-07 21:14:35 +00:00
|
|
|
bool BridgeTaskRunner::RunsTasksInCurrentSequence() const {
|
2015-09-02 07:52:17 +00:00
|
|
|
auto message_loop = base::MessageLoop::current();
|
|
|
|
if (!message_loop)
|
2015-10-22 07:54:27 +00:00
|
|
|
return true;
|
2015-09-02 07:52:17 +00:00
|
|
|
|
2017-08-07 21:14:35 +00:00
|
|
|
return message_loop->task_runner()->RunsTasksInCurrentSequence();
|
2015-09-02 07:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BridgeTaskRunner::PostNonNestableDelayedTask(
|
|
|
|
const tracked_objects::Location& from_here,
|
2017-06-16 20:39:08 +00:00
|
|
|
base::OnceClosure task,
|
2015-09-02 07:52:17 +00:00
|
|
|
base::TimeDelta delay) {
|
|
|
|
auto message_loop = base::MessageLoop::current();
|
2015-10-22 07:54:27 +00:00
|
|
|
if (!message_loop) {
|
2017-06-20 16:18:23 +00:00
|
|
|
non_nestable_tasks_.push_back(std::make_tuple(
|
|
|
|
from_here, std::move(task), delay));
|
2015-10-22 07:54:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-02 07:52:17 +00:00
|
|
|
|
|
|
|
return message_loop->task_runner()->PostNonNestableDelayedTask(
|
2017-06-16 20:39:08 +00:00
|
|
|
from_here, std::move(task), delay);
|
2015-09-02 07:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|