Commit 68f2ed57 authored by Wez's avatar Wez Committed by Commit Bot

Migrate ConnectTestApp off of RunLoop::QuitCurrent*Deprecated().

Change-Id: Ia3190dd63539ef85e33d13642ad9005910bffa70
Reviewed-on: https://chromium-review.googlesource.com/1157528Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579860}
parent 9fcd5ca2
...@@ -23,21 +23,21 @@ namespace service_manager { ...@@ -23,21 +23,21 @@ namespace service_manager {
namespace { namespace {
void QuitLoop(base::RunLoop* loop, void OnConnectResult(base::OnceClosure closure,
mojom::ConnectResult* out_result, mojom::ConnectResult* out_result,
Identity* out_resolved_identity, Identity* out_resolved_identity,
mojom::ConnectResult result, mojom::ConnectResult result,
const Identity& resolved_identity) { const Identity& resolved_identity) {
loop->Quit(); std::move(closure).Run();
*out_result = result; *out_result = result;
*out_resolved_identity = resolved_identity; *out_resolved_identity = resolved_identity;
} }
void ReceiveString(std::string* string, void OnResponseString(std::string* string,
base::RunLoop* loop, base::OnceClosure closure,
const std::string& response) { const std::string& response) {
*string = response; *string = response;
loop->Quit(); std::move(closure).Run();
} }
} // namespace } // namespace
...@@ -56,20 +56,18 @@ class ConnectTestApp : public Service, ...@@ -56,20 +56,18 @@ class ConnectTestApp : public Service,
private: private:
// service_manager::Service: // service_manager::Service:
void OnStart() override { void OnStart() override {
bindings_.set_connection_error_handler( bindings_.set_connection_error_handler(base::BindRepeating(
base::Bind(&ConnectTestApp::OnConnectionError, &ConnectTestApp::OnConnectionError, base::Unretained(this)));
base::Unretained(this))); standalone_bindings_.set_connection_error_handler(base::BindRepeating(
standalone_bindings_.set_connection_error_handler( &ConnectTestApp::OnConnectionError, base::Unretained(this)));
base::Bind(&ConnectTestApp::OnConnectionError,
base::Unretained(this)));
registry_.AddInterface<test::mojom::ConnectTestService>( registry_.AddInterface<test::mojom::ConnectTestService>(
base::Bind(&ConnectTestApp::BindConnectTestServiceRequest, base::BindRepeating(&ConnectTestApp::BindConnectTestServiceRequest,
base::Unretained(this))); base::Unretained(this)));
registry_.AddInterface<test::mojom::StandaloneApp>(base::Bind( registry_.AddInterface<test::mojom::StandaloneApp>(base::BindRepeating(
&ConnectTestApp::BindStandaloneAppRequest, base::Unretained(this))); &ConnectTestApp::BindStandaloneAppRequest, base::Unretained(this)));
registry_.AddInterface<test::mojom::BlockedInterface>(base::Bind( registry_.AddInterface<test::mojom::BlockedInterface>(base::BindRepeating(
&ConnectTestApp::BindBlockedInterfaceRequest, base::Unretained(this))); &ConnectTestApp::BindBlockedInterfaceRequest, base::Unretained(this)));
registry_.AddInterface<test::mojom::UserIdTest>(base::Bind( registry_.AddInterface<test::mojom::UserIdTest>(base::BindRepeating(
&ConnectTestApp::BindUserIdTestRequest, base::Unretained(this))); &ConnectTestApp::BindUserIdTestRequest, base::Unretained(this)));
} }
void OnBindInterface(const BindSourceInfo& source_info, void OnBindInterface(const BindSourceInfo& source_info,
...@@ -123,12 +121,12 @@ class ConnectTestApp : public Service, ...@@ -123,12 +121,12 @@ class ConnectTestApp : public Service,
base::RunLoop run_loop; base::RunLoop run_loop;
test::mojom::ConnectTestServicePtr test_service; test::mojom::ConnectTestServicePtr test_service;
context()->connector()->BindInterface("connect_test_a", &test_service); context()->connector()->BindInterface("connect_test_a", &test_service);
test_service.set_connection_error_handler( test_service.set_connection_error_handler(base::BindRepeating(
base::Bind(&ConnectTestApp::OnConnectionBlocked, base::Unretained(this), &ConnectTestApp::OnGotTitle, base::Unretained(this),
base::Unretained(&callback), &run_loop)); base::Unretained(&callback), run_loop.QuitClosure(), "uninitialized"));
test_service->GetTitle(base::Bind(&ConnectTestApp::OnGotTitle, test_service->GetTitle(
base::Unretained(this), base::BindOnce(&ConnectTestApp::OnGotTitle, base::Unretained(this),
base::Unretained(&callback), &run_loop)); base::Unretained(&callback), run_loop.QuitClosure()));
{ {
// This message is dispatched as a task on the same run loop, so we need // This message is dispatched as a task on the same run loop, so we need
// to allow nesting in order to pump additional signals. // to allow nesting in order to pump additional signals.
...@@ -144,7 +142,8 @@ class ConnectTestApp : public Service, ...@@ -144,7 +142,8 @@ class ConnectTestApp : public Service,
std::string ping_response; std::string ping_response;
{ {
base::RunLoop loop; base::RunLoop loop;
class_interface->Ping(base::Bind(&ReceiveString, &ping_response, &loop)); class_interface->Ping(base::BindOnce(&OnResponseString, &ping_response,
loop.QuitClosure()));
base::MessageLoopCurrent::ScopedNestableTaskAllower allow; base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
loop.Run(); loop.Run();
} }
...@@ -153,7 +152,8 @@ class ConnectTestApp : public Service, ...@@ -153,7 +152,8 @@ class ConnectTestApp : public Service,
std::string title_response; std::string title_response;
{ {
base::RunLoop loop; base::RunLoop loop;
service->GetTitle(base::Bind(&ReceiveString, &title_response, &loop)); service->GetTitle(base::BindOnce(&OnResponseString, &title_response,
loop.QuitClosure()));
base::MessageLoopCurrent::ScopedNestableTaskAllower allow; base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
loop.Run(); loop.Run();
} }
...@@ -175,31 +175,24 @@ class ConnectTestApp : public Service, ...@@ -175,31 +175,24 @@ class ConnectTestApp : public Service,
{ {
base::RunLoop loop; base::RunLoop loop;
Connector::TestApi test_api(context()->connector()); Connector::TestApi test_api(context()->connector());
test_api.SetStartServiceCallback( test_api.SetStartServiceCallback(base::BindRepeating(
base::Bind(&QuitLoop, &loop, &result, &resolved_identity)); &OnConnectResult, loop.QuitClosure(), &result, &resolved_identity));
base::MessageLoopCurrent::ScopedNestableTaskAllower allow; base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
loop.Run(); loop.Run();
} }
std::move(callback).Run(static_cast<int32_t>(result), resolved_identity); std::move(callback).Run(static_cast<int32_t>(result), resolved_identity);
} }
void OnConnectionBlocked(
ConnectToAllowedAppInBlockedPackageCallback* callback,
base::RunLoop* run_loop) {
std::move(*callback).Run("uninitialized");
run_loop->Quit();
}
void OnGotTitle(ConnectToAllowedAppInBlockedPackageCallback* callback, void OnGotTitle(ConnectToAllowedAppInBlockedPackageCallback* callback,
base::RunLoop* run_loop, base::OnceClosure closure,
const std::string& title) { const std::string& title) {
std::move(*callback).Run(title); std::move(*callback).Run(title);
run_loop->Quit(); std::move(closure).Run();
} }
void OnConnectionError() { void OnConnectionError() {
if (bindings_.empty() && standalone_bindings_.empty()) if (bindings_.empty() && standalone_bindings_.empty())
base::RunLoop::QuitCurrentWhenIdleDeprecated(); context()->QuitNow();
} }
BinderRegistryWithArgs<const BindSourceInfo&> registry_; BinderRegistryWithArgs<const BindSourceInfo&> registry_;
......
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