Commit 29cb9cb7 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert TestService to new Mojo types

This CL converts TestServicePtr and TestServiceRequest
to new Mojo types.

It uses Remote, PendingReceiver and Receiver instead of
QueryableDataStorePtr, QueryableDataStoreRequest and Binding.

Bug: 955171
Change-Id: I61f3d6b66ac6f5faffe533800bbe482a2db772ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1803948
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697068}
parent 9b5d966b
......@@ -16,6 +16,7 @@
#include "content/public/common/bind_interface_helpers.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/test_service.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/interface_provider.h"
namespace content {
......@@ -65,12 +66,12 @@ class MojoSandboxTest : public ContentBrowserTest {
IN_PROC_BROWSER_TEST_F(MojoSandboxTest, SubprocessSharedBuffer) {
// Ensures that a shared buffer can be created within a sandboxed process.
mojom::TestServicePtr test_service;
BindInterface(host_.get(), &test_service);
mojo::Remote<mojom::TestService> test_service;
BindInterface(host_.get(), test_service.BindNewPipeAndPassReceiver());
bool got_response = false;
base::RunLoop run_loop;
test_service.set_connection_error_handler(run_loop.QuitClosure());
test_service.set_disconnect_handler(run_loop.QuitClosure());
test_service->CreateSharedBuffer(
kTestMessage,
base::BindOnce(
......
......@@ -38,6 +38,7 @@
#include "media/base/media_switches.h"
#include "media/base/test_data_util.h"
#include "media/mojo/buildflags.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
......@@ -235,9 +236,9 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRenderProcessHostKilled) {
RenderProcessHost* spare_renderer =
RenderProcessHostImpl::GetSpareRenderProcessHostForTesting();
mojom::TestServicePtr service;
mojo::Remote<mojom::TestService> service;
ASSERT_NE(nullptr, spare_renderer);
BindInterface(spare_renderer, &service);
BindInterface(spare_renderer, service.BindNewPipeAndPassReceiver());
base::RunLoop run_loop;
set_process_exit_callback(run_loop.QuitClosure());
......@@ -673,8 +674,8 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KillProcessOnBadMojoMessage) {
process_exits_ = 0;
rph->AddObserver(this);
mojom::TestServicePtr service;
BindInterface(rph, &service);
mojo::Remote<mojom::TestService> service;
BindInterface(rph, service.BindNewPipeAndPassReceiver());
base::RunLoop run_loop;
set_process_exit_callback(run_loop.QuitClosure());
......@@ -752,8 +753,8 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, KillProcessZerosAudioStreams) {
process_exits_ = 0;
rph->AddObserver(this);
mojom::TestServicePtr service;
BindInterface(rph, &service);
mojo::Remote<mojom::TestService> service;
BindInterface(rph, service.BindNewPipeAndPassReceiver());
{
// Force a bad message event to occur which will terminate the renderer.
......@@ -855,8 +856,8 @@ IN_PROC_BROWSER_TEST_F(CaptureStreamRenderProcessHostTest,
process_exits_ = 0;
rph->AddObserver(this);
mojom::TestServicePtr service;
BindInterface(rph, &service);
mojo::Remote<mojom::TestService> service;
BindInterface(rph, service.BindNewPipeAndPassReceiver());
{
// Force a bad message event to occur which will terminate the renderer.
......@@ -921,8 +922,8 @@ IN_PROC_BROWSER_TEST_F(CaptureStreamRenderProcessHostTest,
process_exits_ = 0;
rph->AddObserver(this);
mojom::TestServicePtr service;
BindInterface(rph, &service);
mojo::Remote<mojom::TestService> service;
BindInterface(rph, service.BindNewPipeAndPassReceiver());
{
// Force a bad message event to occur which will terminate the renderer.
......
......@@ -17,6 +17,7 @@
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_service.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#if defined(OS_MACOSX) || defined(OS_LINUX)
#include <sys/wait.h>
......@@ -73,7 +74,7 @@ class UtilityProcessHostBrowserTest : public BrowserChildProcessObserver,
#endif
EXPECT_TRUE(host->Start());
BindInterface(host, &service_);
BindInterface(host, service_.BindNewPipeAndPassReceiver());
if (crash) {
service_->DoCrashImmediately(
base::BindOnce(&UtilityProcessHostBrowserTest::OnSomethingOnIOThread,
......@@ -98,7 +99,7 @@ class UtilityProcessHostBrowserTest : public BrowserChildProcessObserver,
base::PostTask(FROM_HERE, {BrowserThread::UI}, std::move(done_closure_));
}
mojom::TestServicePtr service_;
mojo::Remote<mojom::TestService> service_;
base::OnceClosure done_closure_;
// Access on UI thread.
......
......@@ -31,9 +31,9 @@ void TestService::OnBindInterface(
registry_.BindInterface(interface_name, std::move(interface_pipe));
}
void TestService::Create(mojom::TestServiceRequest request) {
DCHECK(!binding_.is_bound());
binding_.Bind(std::move(request));
void TestService::Create(mojo::PendingReceiver<mojom::TestService> receiver) {
DCHECK(!receiver_.is_bound());
receiver_.Bind(std::move(receiver));
}
void TestService::DoSomething(DoSomethingCallback callback) {
......
......@@ -9,7 +9,8 @@
#include "base/macros.h"
#include "content/public/test/test_service.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_binding.h"
......@@ -32,7 +33,7 @@ class TestService : public service_manager::Service, public mojom::TestService {
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
void Create(mojom::TestServiceRequest request);
void Create(mojo::PendingReceiver<mojom::TestService> receiver);
// TestService:
void DoSomething(DoSomethingCallback callback) override;
......@@ -45,7 +46,7 @@ class TestService : public service_manager::Service, public mojom::TestService {
service_manager::ServiceBinding service_binding_;
service_manager::BinderRegistry registry_;
mojo::Binding<mojom::TestService> binding_{this};
mojo::Receiver<mojom::TestService> receiver_{this};
// The name of the app connecting to us.
std::string requestor_name_;
......
......@@ -21,9 +21,9 @@
#include "content/public/test/test_service.mojom.h"
#include "content/public/utility/utility_thread.h"
#include "content/shell/common/power_monitor_test_impl.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/bindings/service_factory.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/system/buffer.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/test/echo/echo_service.h"
......@@ -34,9 +34,9 @@ namespace {
class TestUtilityServiceImpl : public mojom::TestService {
public:
static void Create(mojom::TestServiceRequest request) {
mojo::MakeStrongBinding(base::WrapUnique(new TestUtilityServiceImpl),
std::move(request));
static void Create(mojo::PendingReceiver<mojom::TestService> receiver) {
mojo::MakeSelfOwnedReceiver(base::WrapUnique(new TestUtilityServiceImpl),
std::move(receiver));
}
// mojom::TestService implementation:
......
......@@ -5,7 +5,8 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/task/single_thread_task_executor.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/public/cpp/service_binding.h"
......@@ -21,7 +22,7 @@ class TestClient : public Service, public mojom::TestService {
TestClient(mojom::ServiceRequest request)
: service_binding_(this, std::move(request)) {
registry_.AddInterface(base::BindRepeating(
&TestClient::BindTestServiceRequest, base::Unretained(this)));
&TestClient::BindTestServiceReceiver, base::Unretained(this)));
}
~TestClient() override = default;
......@@ -37,15 +38,16 @@ class TestClient : public Service, public mojom::TestService {
// mojom::TestService
void Test(TestCallback callback) override { std::move(callback).Run(); }
void BindTestServiceRequest(mojom::TestServiceRequest request) {
bindings_.AddBinding(this, std::move(request));
void BindTestServiceReceiver(
mojo::PendingReceiver<mojom::TestService> receiver) {
receivers_.Add(this, std::move(receiver));
}
void Quit() override { service_binding_.RequestClose(); }
ServiceBinding service_binding_;
BinderRegistry registry_;
mojo::BindingSet<mojom::TestService> bindings_;
mojo::ReceiverSet<mojom::TestService> receivers_;
DISALLOW_COPY_AND_ASSIGN(TestClient);
};
......
......@@ -14,6 +14,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/constants.h"
#include "services/service_manager/public/cpp/manifest.h"
......@@ -90,9 +91,9 @@ TEST(BackgroundServiceManagerTest, MAYBE_Basic) {
base::Token::CreateRandom()),
service.PassInterface(), mojo::NullReceiver() /* metadata_receiver */);
mojom::TestServicePtr test_service;
service_impl.connector()->BindInterface(ServiceFilter::ByName(kAppName),
&test_service);
mojo::Remote<mojom::TestService> test_service;
service_impl.connector()->Connect(ServiceFilter::ByName(kAppName),
test_service.BindNewPipeAndPassReceiver());
base::RunLoop run_loop;
bool got_result = false;
test_service->Test(base::BindOnce(&SetFlagAndRunClosure, &got_result,
......
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