d663b4eaee
* chore: fix cpplint 'include_what_you_use' warnings Typically by including <memory>, <utility> etc. * chore: fix 'static/global string constant' warning Use C style strings instead of std::string. Style guide forbids non-trivial static / global variables. https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables /home/charles/electron/electron-gn/src/electron/script/cpplint.js * refactor: remove global string variables. Fix 'global string variables are not permitted' linter warnings by using the base::NoDestructor<> wrapper to make it explicit that these variables are never destroyed. The style guide's take on globals with nontrivial destructors: https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables * fix: initializer error introduced in last commit * fix: remove WIP file that was included by accident * fix: include order * fix: include order * fix: include order * fix: include order, again
65 lines
2 KiB
C++
65 lines
2 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 <utility>
|
|
|
|
#include "base/message_loop/message_loop.h"
|
|
|
|
namespace atom {
|
|
|
|
BridgeTaskRunner::BridgeTaskRunner() = default;
|
|
BridgeTaskRunner::~BridgeTaskRunner() = default;
|
|
|
|
void BridgeTaskRunner::MessageLoopIsReady() {
|
|
auto* message_loop = base::MessageLoop::current();
|
|
CHECK(message_loop);
|
|
for (TaskPair& task : tasks_) {
|
|
message_loop->task_runner()->PostDelayedTask(
|
|
std::get<0>(task), std::move(std::get<1>(task)), std::get<2>(task));
|
|
}
|
|
for (TaskPair& task : non_nestable_tasks_) {
|
|
message_loop->task_runner()->PostNonNestableDelayedTask(
|
|
std::get<0>(task), std::move(std::get<1>(task)), std::get<2>(task));
|
|
}
|
|
}
|
|
|
|
bool BridgeTaskRunner::PostDelayedTask(const base::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, std::move(task), delay));
|
|
return true;
|
|
}
|
|
|
|
return message_loop->task_runner()->PostDelayedTask(from_here,
|
|
std::move(task), delay);
|
|
}
|
|
|
|
bool BridgeTaskRunner::RunsTasksInCurrentSequence() const {
|
|
auto* message_loop = base::MessageLoop::current();
|
|
if (!message_loop)
|
|
return true;
|
|
|
|
return message_loop->task_runner()->RunsTasksInCurrentSequence();
|
|
}
|
|
|
|
bool BridgeTaskRunner::PostNonNestableDelayedTask(
|
|
const base::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, std::move(task), delay));
|
|
return true;
|
|
}
|
|
|
|
return message_loop->task_runner()->PostNonNestableDelayedTask(
|
|
from_here, std::move(task), delay);
|
|
}
|
|
|
|
} // namespace atom
|