0

Convert SimpleTestClient and PingReceiver to new Mojo types

This CL converts SimpleTestClientAssociatedRequest,
PingReceiverPtr, PingReceiverRequest,
PingReceiverAssociatedRequest, and PingReceiverAssociatedPtr
to new Mojo types using AssociatedRemote,
PendingAssociatedReceiver, Remote, PendingReceiver,
AssociatedReceiver, and AssociatedReceiverSet.

Bug: 955171
Change-Id: Ie7df6c59edf6cd9f360b2032ac8a665d095a9bb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826957
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Sam McNally <sammc@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#700543}
This commit is contained in:
Julie Jeongeun Kim
2019-09-27 01:56:49 +00:00
committed by Commit Bot
parent 298569451d
commit 761a8ff52a
3 changed files with 48 additions and 39 deletions

@ -994,8 +994,7 @@ class ListenerWithIndirectProxyAssociatedInterface
public IPC::mojom::IndirectTestDriver,
public IPC::mojom::PingReceiver {
public:
ListenerWithIndirectProxyAssociatedInterface()
: driver_binding_(this), ping_receiver_binding_(this) {}
ListenerWithIndirectProxyAssociatedInterface() : driver_binding_(this) {}
~ListenerWithIndirectProxyAssociatedInterface() override = default;
// IPC::Listener:
@ -1016,9 +1015,9 @@ class ListenerWithIndirectProxyAssociatedInterface
private:
// IPC::mojom::IndirectTestDriver:
void GetPingReceiver(
IPC::mojom::PingReceiverAssociatedRequest request) override {
ping_receiver_binding_.Bind(std::move(request));
void GetPingReceiver(mojo::PendingAssociatedReceiver<IPC::mojom::PingReceiver>
receiver) override {
ping_receiver_receiver_.Bind(std::move(receiver));
}
// IPC::mojom::PingReceiver:
@ -1028,7 +1027,8 @@ class ListenerWithIndirectProxyAssociatedInterface
}
mojo::AssociatedBinding<IPC::mojom::IndirectTestDriver> driver_binding_;
mojo::AssociatedBinding<IPC::mojom::PingReceiver> ping_receiver_binding_;
mojo::AssociatedReceiver<IPC::mojom::PingReceiver> ping_receiver_receiver_{
this};
base::RepeatingClosure ping_handler_;
};
@ -1066,9 +1066,9 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(
// endpoint may not have been bound yet by the time the message is initially
// processed on the IO thread.
IPC::mojom::IndirectTestDriverAssociatedPtr driver;
IPC::mojom::PingReceiverAssociatedPtr ping_receiver;
mojo::AssociatedRemote<IPC::mojom::PingReceiver> ping_receiver;
proxy()->GetRemoteAssociatedInterface(&driver);
driver->GetPingReceiver(mojo::MakeRequest(&ping_receiver));
driver->GetPingReceiver(ping_receiver.BindNewEndpointAndPassReceiver());
base::RunLoop loop;
ping_receiver->Ping(loop.QuitClosure());
@ -1273,11 +1273,12 @@ class SimpleTestClientImpl : public IPC::mojom::SimpleTestClient,
DCHECK_EQ(interface_name, IPC::mojom::SimpleTestClient::Name_);
receiver_.Bind(
IPC::mojom::SimpleTestClientAssociatedRequest(std::move(handle)));
mojo::PendingAssociatedReceiver<IPC::mojom::SimpleTestClient>(
std::move(handle)));
}
bool use_sync_sender_ = false;
mojo::AssociatedBinding<IPC::mojom::SimpleTestClient> receiver_{this};
mojo::AssociatedReceiver<IPC::mojom::SimpleTestClient> receiver_{this};
IPC::Sender* sync_sender_ = nullptr;
IPC::mojom::SimpleTestDriver* driver_ = nullptr;
std::unique_ptr<base::RunLoop> run_loop_;

@ -25,9 +25,13 @@
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/test/mojo_test_base.h"
#include "mojo/core/test/multiprocess_test_helper.h"
#include "mojo/public/cpp/bindings/associated_binding_set.h"
#include "mojo/public/cpp/bindings/associated_receiver_set.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/message_pipe.h"
namespace IPC {
@ -378,20 +382,22 @@ class InterfacePassingTestDriverImpl : public mojom::InterfacePassingTestDriver,
// mojom::InterfacePassingTestDriver implementation:
void Init(InitCallback callback) override { std::move(callback).Run(); }
void GetPingReceiver(std::vector<mojom::PingReceiverRequest> requests,
GetPingReceiverCallback callback) override {
for (auto& request : requests)
ping_receiver_bindings_.AddBinding(this, std::move(request));
ping_receiver_bindings_.CloseAllBindings();
void GetPingReceiver(
std::vector<mojo::PendingReceiver<mojom::PingReceiver>> receivers,
GetPingReceiverCallback callback) override {
for (auto& receiver : receivers)
ping_receiver_receivers_.Add(this, std::move(receiver));
ping_receiver_receivers_.Clear();
std::move(callback).Run();
}
void GetAssociatedPingReceiver(
std::vector<mojom::PingReceiverAssociatedRequest> requests,
std::vector<mojo::PendingAssociatedReceiver<mojom::PingReceiver>>
receivers,
GetAssociatedPingReceiverCallback callback) override {
for (auto& request : requests)
ping_receiver_associated_bindings_.AddBinding(this, std::move(request));
ping_receiver_associated_bindings_.CloseAllBindings();
for (auto& receiver : receivers)
ping_receiver_associated_receivers_.Add(this, std::move(receiver));
ping_receiver_associated_receivers_.Clear();
std::move(callback).Run();
}
@ -403,9 +409,9 @@ class InterfacePassingTestDriverImpl : public mojom::InterfacePassingTestDriver,
// mojom::PingReceiver implementation:
void Ping(PingCallback callback) override { std::move(callback).Run(); }
mojo::BindingSet<mojom::PingReceiver> ping_receiver_bindings_;
mojo::AssociatedBindingSet<mojom::PingReceiver>
ping_receiver_associated_bindings_;
mojo::ReceiverSet<mojom::PingReceiver> ping_receiver_receivers_;
mojo::AssociatedReceiverSet<mojom::PingReceiver>
ping_receiver_associated_receivers_;
mojo::Binding<mojom::InterfacePassingTestDriver> binding_;
base::Closure quit_closure_;
@ -458,33 +464,34 @@ class MojoInterfacePassingPerfTest : public mojo::core::test::MojoTestBase {
void DoNextRound() {
if (associated_) {
std::vector<mojom::PingReceiverAssociatedPtr> associated_interfaces(
num_interfaces_);
std::vector<mojo::AssociatedRemote<mojom::PingReceiver>>
associated_remotes(num_interfaces_);
std::vector<mojom::PingReceiverAssociatedRequest> requests(
num_interfaces_);
std::vector<mojo::PendingAssociatedReceiver<mojom::PingReceiver>>
receivers(num_interfaces_);
for (size_t i = 0; i < num_interfaces_; ++i) {
requests[i] = mojo::MakeRequest(&associated_interfaces[i]);
receivers[i] = associated_remotes[i].BindNewEndpointAndPassReceiver();
// Force the interface pointer to do full initialization.
associated_interfaces[i].get();
associated_remotes[i].get();
}
driver_ptr_->GetAssociatedPingReceiver(
std::move(requests),
std::move(receivers),
base::Bind(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
base::Unretained(this)));
} else {
std::vector<mojom::PingReceiverPtr> interfaces(num_interfaces_);
std::vector<mojo::Remote<mojom::PingReceiver>> remotes(num_interfaces_);
std::vector<mojom::PingReceiverRequest> requests(num_interfaces_);
std::vector<mojo::PendingReceiver<mojom::PingReceiver>> receivers(
num_interfaces_);
for (size_t i = 0; i < num_interfaces_; ++i) {
requests[i] = mojo::MakeRequest(&interfaces[i]);
receivers[i] = remotes[i].BindNewPipeAndPassReceiver();
// Force the interface pointer to do full initialization.
interfaces[i].get();
remotes[i].get();
}
driver_ptr_->GetPingReceiver(
std::move(requests),
std::move(receivers),
base::Bind(&MojoInterfacePassingPerfTest::OnGetReceiverCallback,
base::Unretained(this)));
}

@ -32,7 +32,7 @@ interface TestStructPasser {
};
interface IndirectTestDriver {
GetPingReceiver(associated PingReceiver& request);
GetPingReceiver(pending_associated_receiver<PingReceiver> receiver);
};
interface Reflector {
@ -48,7 +48,8 @@ interface AssociatedInterfaceVendor {
interface InterfacePassingTestDriver {
Init() => ();
GetPingReceiver(array<PingReceiver&> request) => ();
GetAssociatedPingReceiver(array<associated PingReceiver&> request) => ();
GetPingReceiver(array<pending_receiver<PingReceiver>> receiver) => ();
GetAssociatedPingReceiver(
array<pending_associated_receiver<PingReceiver>> receiver) => ();
Quit();
};