Skip to content

Commit

Permalink
Convert ipc to Once/Repeating variants of Bind/Callback. (pt 2)
Browse files Browse the repository at this point in the history
Bug: 1007797
Change-Id: I7ccb2694f2087e4af502d343b20347bcc56ade61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925829
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717370}
  • Loading branch information
mfalken authored and Commit Bot committed Nov 21, 2019
1 parent 0c99325 commit fb888f0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 37 deletions.
12 changes: 7 additions & 5 deletions ipc/ipc_cpu_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PerfCpuLogger {
MULTIPROCESS_TEST_MAIN(MojoPerfTestClientTestChildMain) {
MojoPerfTestClient client;
int rv = mojo::core::test::MultiprocessTestHelper::RunClientMain(
base::Bind(&MojoPerfTestClient::Run, base::Unretained(&client)),
base::BindOnce(&MojoPerfTestClient::Run, base::Unretained(&client)),
true /* pass_pipe_ownership_to_main */);

base::RunLoop run_loop;
Expand Down Expand Up @@ -286,8 +286,9 @@ class MojoSteadyPingPongTest : public mojo::core::test::MojoTestBase {
params_ = params;
payload_ = std::string(params.message_size, 'a');

ping_receiver_->Ping("hello", base::Bind(&MojoSteadyPingPongTest::OnHello,
base::Unretained(this)));
ping_receiver_->Ping("hello",
base::BindOnce(&MojoSteadyPingPongTest::OnHello,
base::Unretained(this)));
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitWhenIdleClosure();
run_loop.Run();
Expand Down Expand Up @@ -361,8 +362,9 @@ class MojoSteadyPingPongTest : public mojo::core::test::MojoTestBase {
}

void SendPing() {
ping_receiver_->Ping(payload_, base::Bind(&MojoSteadyPingPongTest::OnPong,
base::Unretained(this)));
ping_receiver_->Ping(payload_,
base::BindOnce(&MojoSteadyPingPongTest::OnPong,
base::Unretained(this)));
}

static int RunPingPongClient(MojoHandle mp) {
Expand Down
12 changes: 6 additions & 6 deletions ipc/ipc_message_pipe_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ MessagePipeReader::MessagePipeReader(
: delegate_(delegate),
sender_(std::move(sender)),
receiver_(this, std::move(receiver)) {
sender_.set_disconnect_handler(base::Bind(&MessagePipeReader::OnPipeError,
base::Unretained(this),
MOJO_RESULT_FAILED_PRECONDITION));
receiver_.set_disconnect_handler(base::Bind(&MessagePipeReader::OnPipeError,
base::Unretained(this),
MOJO_RESULT_FAILED_PRECONDITION));
sender_.set_disconnect_handler(base::BindRepeating(
&MessagePipeReader::OnPipeError, base::Unretained(this),
MOJO_RESULT_FAILED_PRECONDITION));
receiver_.set_disconnect_handler(base::BindRepeating(
&MessagePipeReader::OnPipeError, base::Unretained(this),
MOJO_RESULT_FAILED_PRECONDITION));
}

MessagePipeReader::~MessagePipeReader() {
Expand Down
4 changes: 2 additions & 2 deletions ipc/ipc_mojo_bootstrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class ChannelAssociatedGroupController
task_runner_));
connector_->set_incoming_receiver(&dispatcher_);
connector_->set_connection_error_handler(
base::Bind(&ChannelAssociatedGroupController::OnPipeError,
base::Unretained(this)));
base::BindRepeating(&ChannelAssociatedGroupController::OnPipeError,
base::Unretained(this)));
connector_->set_enforce_errors_from_incoming_receiver(false);
connector_->SetWatcherHeapProfilerTag("IPC Channel");
if (quota_checker_)
Expand Down
42 changes: 23 additions & 19 deletions ipc/ipc_mojo_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ TEST_F(MojoChannelPerfTest, ChannelProxySyncPing) {
MULTIPROCESS_TEST_MAIN(MojoPerfTestClientTestChildMain) {
MojoPerfTestClient client;
int rv = mojo::core::test::MultiprocessTestHelper::RunClientMain(
base::Bind(&MojoPerfTestClient::Run, base::Unretained(&client)),
base::BindOnce(&MojoPerfTestClient::Run, base::Unretained(&client)),
true /* pass_pipe_ownership_to_main */);

base::RunLoop run_loop;
Expand All @@ -295,8 +295,9 @@ class MojoInterfacePerfTest : public mojo::core::test::MojoTestBase {
LockThreadAffinity thread_locker(kSharedCore);
std::vector<PingPongTestParams> params = GetDefaultTestParams();
for (size_t i = 0; i < params.size(); i++) {
ping_receiver_->Ping("hello", base::Bind(&MojoInterfacePerfTest::OnPong,
base::Unretained(this)));
ping_receiver_->Ping("hello",
base::BindOnce(&MojoInterfacePerfTest::OnPong,
base::Unretained(this)));
message_count_ = count_down_ = params[i].message_count();
payload_ = std::string(params[i].message_size(), 'a');

Expand Down Expand Up @@ -336,8 +337,9 @@ class MojoInterfacePerfTest : public mojo::core::test::MojoTestBase {
perf_logger_.reset();
base::RunLoop::QuitCurrentWhenIdleDeprecated();
} else {
ping_receiver_->Ping(payload_, base::Bind(&MojoInterfacePerfTest::OnPong,
base::Unretained(this)));
ping_receiver_->Ping(payload_,
base::BindOnce(&MojoInterfacePerfTest::OnPong,
base::Unretained(this)));
}
}

Expand Down Expand Up @@ -441,8 +443,8 @@ class MojoInterfacePassingPerfTest : public mojo::core::test::MojoTestBase {
LockThreadAffinity thread_locker(kSharedCore);
for (size_t i = 0; i < params.size(); ++i) {
driver_remote_->Init(
base::Bind(&MojoInterfacePassingPerfTest::OnInitCallback,
base::Unretained(this)));
base::BindOnce(&MojoInterfacePassingPerfTest::OnInitCallback,
base::Unretained(this)));
rounds_ = count_down_ = params[i].rounds();
num_interfaces_ = params[i].num_interfaces();

Expand Down Expand Up @@ -480,8 +482,8 @@ class MojoInterfacePassingPerfTest : public mojo::core::test::MojoTestBase {

driver_remote_->GetAssociatedPingReceiver(
std::move(receivers),
base::Bind(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
base::Unretained(this)));
base::BindOnce(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
base::Unretained(this)));
} else {
std::vector<mojo::Remote<mojom::PingReceiver>> remotes(num_interfaces_);

Expand All @@ -495,8 +497,8 @@ class MojoInterfacePassingPerfTest : public mojo::core::test::MojoTestBase {

driver_remote_->GetPingReceiver(
std::move(receivers),
base::Bind(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
base::Unretained(this)));
base::BindOnce(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
base::Unretained(this)));
}
}

Expand Down Expand Up @@ -771,10 +773,12 @@ class CallbackPerfTest : public testing::Test {
void RunSingleThreadNoPostTaskPingPongServer() {
LockThreadAffinity thread_locker(kSharedCore);
std::vector<PingPongTestParams> params = GetDefaultTestParams();
base::Callback<void(const std::string&, int,
const base::Callback<void(const std::string&, int)>&)>
ping = base::Bind(&CallbackPerfTest::SingleThreadPingNoPostTask,
base::Unretained(this));
base::RepeatingCallback<void(
const std::string&, int,
base::OnceCallback<void(const std::string&, int)>)>
ping =
base::BindRepeating(&CallbackPerfTest::SingleThreadPingNoPostTask,
base::Unretained(this));
for (size_t i = 0; i < params.size(); i++) {
payload_ = std::string(params[i].message_size(), 'a');
std::string test_name =
Expand All @@ -783,8 +787,8 @@ class CallbackPerfTest : public testing::Test {
perf_logger_.reset(new base::PerfTimeLogger(test_name.c_str()));
for (int j = 0; j < params[i].message_count(); ++j) {
ping.Run(payload_, j,
base::Bind(&CallbackPerfTest::SingleThreadPongNoPostTask,
base::Unretained(this)));
base::BindOnce(&CallbackPerfTest::SingleThreadPongNoPostTask,
base::Unretained(this)));
}
perf_logger_.reset();
}
Expand All @@ -793,8 +797,8 @@ class CallbackPerfTest : public testing::Test {
void SingleThreadPingNoPostTask(
const std::string& value,
int i,
const base::Callback<void(const std::string&, int)>& pong) {
pong.Run(value, i);
base::OnceCallback<void(const std::string&, int)> pong) {
std::move(pong).Run(value, i);
}

void SingleThreadPongNoPostTask(const std::string& value, int i) {}
Expand Down
4 changes: 2 additions & 2 deletions ipc/ipc_security_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace IPC {
void IpcSecurityTestUtil::PwnMessageReceived(ChannelProxy* channel,
const IPC::Message& message) {
base::RunLoop run_loop;
base::Closure inject_message = base::Bind(
base::OnceClosure inject_message = base::BindOnce(
base::IgnoreResult(&IPC::ChannelProxy::Context::OnMessageReceived),
channel->context(), message);
channel->context()->ipc_task_runner()->PostTaskAndReply(
FROM_HERE, inject_message, run_loop.QuitClosure());
FROM_HERE, std::move(inject_message), run_loop.QuitClosure());
run_loop.Run();
}

Expand Down
4 changes: 2 additions & 2 deletions ipc/ipc_sync_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ bool SyncMessageFilter::Send(Message* message) {
bool shutdown = false;
scoped_refptr<mojo::SyncHandleRegistry> registry =
mojo::SyncHandleRegistry::current();
auto on_shutdown_callback = base::Bind(&OnEventReady, &shutdown);
auto on_done_callback = base::Bind(&OnEventReady, &done);
auto on_shutdown_callback = base::BindRepeating(&OnEventReady, &shutdown);
auto on_done_callback = base::BindRepeating(&OnEventReady, &done);
registry->RegisterEvent(shutdown_event_, on_shutdown_callback);
registry->RegisterEvent(&done_event, on_done_callback);

Expand Down
2 changes: 1 addition & 1 deletion ipc/run_all_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ int main(int argc, char** argv) {

return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
}

0 comments on commit fb888f0

Please sign in to comment.