Commit 06d698e4 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Convert sandbox/{win,linux} away from base::Bind/base::Callback

base::Bind/base::Callback are deprecated in favor of either
base::BindOnce/base::OnceCallback or base::BindRepeating/
base::RepeatingCallback (depending on whether the callback
is invoked once or multiple time).

Convert all uses of base::Bind/base::Callback in sandbox/{win,linux}
to the recommended methods/types.

Bug: 1007829, 1007830
Change-Id: I5a6e03e2b823f1c2b3f48317b0451911f192b99f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835581
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702164}
parent 0a5b0867
......@@ -49,7 +49,7 @@ class InitializedOpenBroker {
syscall_broker::BrokerFilePermission::ReadOnly("/proc/cpuinfo")};
broker_process_ = std::make_unique<syscall_broker::BrokerProcess>(
EPERM, command_set, permissions);
BPF_ASSERT(broker_process_->Init(base::Bind([]() { return true; })));
BPF_ASSERT(broker_process_->Init(base::BindOnce([]() { return true; })));
initialized_ = true;
}
......
......@@ -33,7 +33,7 @@ void WaitForever() {
} // namespace
ScopedProcess::ScopedProcess(const base::Closure& child_callback)
ScopedProcess::ScopedProcess(base::OnceClosure child_callback)
: child_process_id_(-1), process_id_(getpid()) {
PCHECK(0 == pipe(pipe_fds_));
#if !defined(THREAD_SANITIZER)
......@@ -46,7 +46,7 @@ ScopedProcess::ScopedProcess(const base::Closure& child_callback)
if (0 == child_process_id_) {
PCHECK(0 == IGNORE_EINTR(close(pipe_fds_[0])));
pipe_fds_[0] = -1;
child_callback.Run();
std::move(child_callback).Run();
// Notify the parent that the closure has run.
CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds_[1], kSynchronisationChar, 1)));
WaitForever();
......
......@@ -24,7 +24,7 @@ class SANDBOX_EXPORT ScopedProcess {
// A new process will be created and |child_callback| will run in the child
// process. This callback is allowed to terminate the process or to simply
// return. If the callback returns, the process will wait forever.
explicit ScopedProcess(const base::Closure& child_callback);
explicit ScopedProcess(base::OnceClosure child_callback);
~ScopedProcess();
// Wait for the process to exit.
......
......@@ -38,7 +38,7 @@ void RaiseAndExit(int signal) {
TEST(ScopedProcess, ScopedProcessNormalExit) {
const int kCustomExitCode = 12;
ScopedProcess process(base::Bind(&ExitWithCode, kCustomExitCode));
ScopedProcess process(base::BindOnce(&ExitWithCode, kCustomExitCode));
bool got_signaled = true;
int exit_code = process.WaitForExit(&got_signaled);
EXPECT_FALSE(got_signaled);
......@@ -55,7 +55,7 @@ TEST(ScopedProcess, ScopedProcessNormalExit) {
// Disable this test on Android, SIGABRT is funky there.
TEST(ScopedProcess, DISABLE_ON_ANDROID(ScopedProcessAbort)) {
PCHECK(SIG_ERR != signal(SIGABRT, SIG_DFL));
ScopedProcess process(base::Bind(&RaiseAndExit, SIGABRT));
ScopedProcess process(base::BindOnce(&RaiseAndExit, SIGABRT));
bool got_signaled = false;
int exit_code = process.WaitForExit(&got_signaled);
EXPECT_TRUE(got_signaled);
......@@ -77,7 +77,7 @@ TEST(ScopedProcess, DiesForReal) {
base::ScopedFD read_end_closer(pipe_fds[0]);
base::ScopedFD write_end_closer(pipe_fds[1]);
{ ScopedProcess process(base::Bind(&DoExit)); }
{ ScopedProcess process(base::BindOnce(&DoExit)); }
// Close writing end of the pipe.
write_end_closer.reset();
......@@ -94,7 +94,7 @@ TEST(ScopedProcess, SynchronizationBasic) {
ScopedProcess process1{base::DoNothing()};
EXPECT_TRUE(process1.WaitForClosureToRun());
ScopedProcess process2(base::Bind(&DoExit));
ScopedProcess process2(base::BindOnce(&DoExit));
// The closure didn't finish running normally. This case is simple enough
// that process.WaitForClosureToRun() should return false, even though the
// API does not guarantees that it will return at all.
......@@ -114,7 +114,7 @@ TEST(ScopedProcess, SynchronizationWorks) {
// Start a process with a closure that takes a little bit to run.
ScopedProcess process(
base::Bind(&SleepInMsAndWriteOneByte, 100, pipe_fds[1]));
base::BindOnce(&SleepInMsAndWriteOneByte, 100, pipe_fds[1]));
EXPECT_TRUE(process.WaitForClosureToRun());
// Verify that the closure did, indeed, run.
......
......@@ -71,7 +71,8 @@ bool IsNotThreadPresentInProcFS(int proc_fd,
// Debug builds (2s on Release builds).
// This is guaranteed to not sleep more than twice as much as the bare minimum
// amount of time.
void RunWhileTrue(const base::Callback<bool(void)>& cb, const char* message) {
void RunWhileTrue(const base::RepeatingCallback<bool(void)>& cb,
const char* message) {
#if defined(NDEBUG)
// In Release mode, crash after 30 iterations, which means having spent
// roughly 2s in
......@@ -117,7 +118,7 @@ bool ChangeThreadStateAndWatchProcFS(
DCHECK(thread);
DCHECK(action == ThreadAction::Start || action == ThreadAction::Stop);
base::Callback<bool(void)> cb;
base::RepeatingCallback<bool(void)> cb;
const char* message;
if (action == ThreadAction::Start) {
......@@ -140,10 +141,12 @@ bool ChangeThreadStateAndWatchProcFS(
// /proc. Start() above or following Stop(), the thread is started or joined,
// but entries in /proc may not have been updated.
if (action == ThreadAction::Start) {
cb = base::Bind(&IsNotThreadPresentInProcFS, proc_fd, thread_id_dir_str);
cb = base::BindRepeating(&IsNotThreadPresentInProcFS, proc_fd,
thread_id_dir_str);
message = kAssertThreadDoesNotAppearInProcFS;
} else {
cb = base::Bind(&IsThreadPresentInProcFS, proc_fd, thread_id_dir_str);
cb = base::BindRepeating(&IsThreadPresentInProcFS, proc_fd,
thread_id_dir_str);
message = kAssertThreadDoesNotDisappearInProcFS;
}
RunWhileTrue(cb, message);
......@@ -171,7 +174,8 @@ bool ThreadHelpers::IsSingleThreaded() {
// static
void ThreadHelpers::AssertSingleThreaded(int proc_fd) {
DCHECK_LE(0, proc_fd);
const base::Callback<bool(void)> cb = base::Bind(&IsMultiThreaded, proc_fd);
const base::RepeatingCallback<bool(void)> cb =
base::BindRepeating(&IsMultiThreaded, proc_fd);
RunWhileTrue(cb, kAssertSingleThreadedError);
}
......
......@@ -66,7 +66,7 @@ void ExitZeroIfCanPtrace(pid_t pid) {
}
bool CanSubProcessPtrace(pid_t pid) {
ScopedProcess process(base::Bind(&ExitZeroIfCanPtrace, pid));
ScopedProcess process(base::BindOnce(&ExitZeroIfCanPtrace, pid));
bool signaled;
int exit_code = process.WaitForExit(&signaled);
CHECK(!signaled);
......@@ -134,7 +134,7 @@ TEST(Yama, RestrictPtraceWorks) {
if (HasLinux32Bug())
return;
ScopedProcess process1(base::Bind(&SetYamaRestrictions, true));
ScopedProcess process1(base::BindOnce(&SetYamaRestrictions, true));
ASSERT_TRUE(process1.WaitForClosureToRun());
if (Yama::IsEnforcing()) {
......@@ -147,7 +147,7 @@ TEST(Yama, RestrictPtraceWorks) {
ASSERT_TRUE(CanPtrace(process1.GetPid()));
// A sibling can ptrace process2 which disables any Yama protection.
ScopedProcess process2(base::Bind(&SetYamaRestrictions, false));
ScopedProcess process2(base::BindOnce(&SetYamaRestrictions, false));
ASSERT_TRUE(process2.WaitForClosureToRun());
ASSERT_TRUE(CanSubProcessPtrace(process2.GetPid()));
}
......
......@@ -59,7 +59,7 @@ BrokerProcess::~BrokerProcess() {
}
bool BrokerProcess::Init(
const base::Callback<bool(void)>& broker_process_init_callback) {
base::OnceCallback<bool(void)> broker_process_init_callback) {
CHECK(!initialized_);
BrokerChannel::EndPoint ipc_reader;
BrokerChannel::EndPoint ipc_writer;
......@@ -86,7 +86,7 @@ bool BrokerProcess::Init(
// We are the broker process. Make sure to close the writer's end so that
// we get notified if the client disappears.
ipc_writer.reset();
CHECK(broker_process_init_callback.Run());
CHECK(std::move(broker_process_init_callback).Run());
BrokerHost broker_host(broker_permission_list_, allowed_command_set_,
std::move(ipc_reader));
for (;;) {
......
......@@ -71,7 +71,7 @@ class SANDBOX_EXPORT BrokerProcess {
// point, since we need to fork().
// broker_process_init_callback will be called in the new broker process,
// after fork() returns.
bool Init(const base::Callback<bool(void)>& broker_process_init_callback);
bool Init(base::OnceCallback<bool(void)> broker_process_init_callback);
// Return the PID of the child created by Init().
int broker_pid() const { return broker_pid_; }
......
......@@ -69,7 +69,7 @@ int main(int argc, char* argv[]) {
// SIGABRT). The normal test launcher does this at initialization, but since
// we still do not use this on Android, we must install the handler ourselves.
logging::ScopedLogAssertHandler scoped_assert_handler(
base::Bind(UnitTestAssertHandler));
base::BindRepeating(UnitTestAssertHandler));
#endif
// Always go through re-execution for death tests.
// This makes gtest only marginally slower for us and has the
......
......@@ -30,8 +30,6 @@ int wmain(int argc, wchar_t **argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc,
argv,
false,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
argc, argv, false,
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
......@@ -16,8 +16,6 @@ int wmain(int argc, wchar_t **argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc,
argv,
false,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
argc, argv, false,
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
......@@ -20,8 +20,6 @@ int wmain(int argc, wchar_t **argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc,
argv,
false,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
argc, argv, false,
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment