Commit 903b34b2 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert mojom::Channel to new Mojo types

This CL converts ChannelPtr, ChannelRequest,
ChannelAssociatedPtr, and ChannelAssociatedRequest to
new Mojo types using PendingRemote or Remote,
PendingReceiver, Receiver, PendingAssociatedRemote or
AssociatedRemote, PendingAssociatedReceiver and
AssociatedReceiver.

It also updates OnConnection from
secure_channel.mojom.

Bug: 955171
Change-Id: I6065f8208a2a79316f812e9f48af6b3b88240e7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819288Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#699702}
parent 43becc01
......@@ -14,31 +14,30 @@ namespace {
const char kReasonForDisconnection[] = "Remote device disconnected.";
} // namespace
ChannelImpl::ChannelImpl(Delegate* delegate)
: delegate_(delegate), binding_(this) {}
ChannelImpl::ChannelImpl(Delegate* delegate) : delegate_(delegate) {}
ChannelImpl::~ChannelImpl() = default;
mojom::ChannelPtr ChannelImpl::GenerateInterfacePtr() {
// Only one InterfacePtr should be generated from this instance.
DCHECK(!binding_);
mojo::PendingRemote<mojom::Channel> ChannelImpl::GenerateRemote() {
// Only one PendingRemote should be generated from this instance.
DCHECK(!receiver_.is_bound());
mojom::ChannelPtr interface_ptr;
binding_.Bind(mojo::MakeRequest(&interface_ptr));
mojo::PendingRemote<mojom::Channel> interface_remote =
receiver_.BindNewPipeAndPassRemote();
binding_.set_connection_error_handler(base::BindOnce(
receiver_.set_disconnect_handler(base::BindOnce(
&ChannelImpl::OnBindingDisconnected, base::Unretained(this)));
return interface_ptr;
return interface_remote;
}
void ChannelImpl::HandleRemoteDeviceDisconnection() {
DCHECK(binding_);
DCHECK(receiver_.is_bound());
// If the RemoteDevice disconnected, alert clients by providing them a
// reason specific to this event.
binding_.CloseWithReason(mojom::Channel::kConnectionDroppedReason,
kReasonForDisconnection);
receiver_.ResetWithReason(mojom::Channel::kConnectionDroppedReason,
kReasonForDisconnection);
}
void ChannelImpl::SendMessage(const std::string& message,
......
......@@ -11,7 +11,8 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace chromeos {
......@@ -37,8 +38,9 @@ class ChannelImpl : public mojom::Channel {
explicit ChannelImpl(Delegate* delegate);
~ChannelImpl() override;
// Generates a ChannelPtr for this instance; can only be called once.
mojom::ChannelPtr GenerateInterfacePtr();
// Generates a mojo::PendingRemote<Channel> for this instance; can only be
// called once.
mojo::PendingRemote<mojom::Channel> GenerateRemote();
// Should be called when the underlying connection to the remote device has
// been disconnected (e.g., because the other device closed the connection or
......@@ -58,7 +60,7 @@ class ChannelImpl : public mojom::Channel {
void OnBindingDisconnected();
Delegate* delegate_;
mojo::Binding<mojom::Channel> binding_;
mojo::Receiver<mojom::Channel> receiver_{this};
base::WeakPtrFactory<ChannelImpl> weak_ptr_factory_{this};
......
......@@ -39,7 +39,7 @@ void ClientConnectionParameters::SetConnectionAttemptFailed(
}
void ClientConnectionParameters::SetConnectionSucceeded(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
static const std::string kFunctionName = "SetConnectionSucceeded";
VerifyDelegateWaitingForResponse(kFunctionName);
......
......@@ -12,6 +12,7 @@
#include "base/observer_list.h"
#include "base/unguessable_token.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos {
......@@ -52,7 +53,7 @@ class ClientConnectionParameters {
// only be called if IsActive() is true and SetConnectionAttemptFailed() has
// not been invoked.
void SetConnectionSucceeded(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request);
bool operator==(const ClientConnectionParameters& other) const;
......@@ -63,7 +64,7 @@ class ClientConnectionParameters {
virtual void PerformSetConnectionAttemptFailed(
mojom::ConnectionAttemptFailureReason reason) = 0;
virtual void PerformSetConnectionSucceeded(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) = 0;
void NotifyConnectionRequestCanceled();
......
......@@ -66,7 +66,7 @@ void ClientConnectionParametersImpl::PerformSetConnectionAttemptFailed(
}
void ClientConnectionParametersImpl::PerformSetConnectionSucceeded(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
connection_delegate_ptr_->OnConnection(std::move(channel),
std::move(message_receiver_request));
......
......@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "chromeos/services/secure_channel/client_connection_parameters.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos {
......@@ -42,7 +43,7 @@ class ClientConnectionParametersImpl : public ClientConnectionParameters {
void PerformSetConnectionAttemptFailed(
mojom::ConnectionAttemptFailureReason reason) override;
void PerformSetConnectionSucceeded(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override;
void OnConnectionDelegatePtrDisconnected();
......
......@@ -54,7 +54,7 @@ class SecureChannelClientConnectionParametersImplTest : public testing::Test {
}
void CallOnConnection(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
base::RunLoop run_loop;
fake_connection_delegate_->set_closure_for_next_delegate_callback(
......@@ -109,7 +109,7 @@ TEST_F(SecureChannelClientConnectionParametersImplTest, OnConnection) {
auto fake_channel = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr;
CallOnConnection(fake_channel->GenerateInterfacePtr(),
CallOnConnection(fake_channel->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr));
VerifyStatus(false /* expected_to_be_waiting_for_response */,
false /* expected_to_be_canceled */);
......
......@@ -12,19 +12,17 @@ namespace {
const char kDisconnectionDescription[] = "Remote device disconnected.";
} // namespace
FakeChannel::FakeChannel() : binding_(this) {}
FakeChannel::FakeChannel() = default;
FakeChannel::~FakeChannel() = default;
mojom::ChannelPtr FakeChannel::GenerateInterfacePtr() {
mojom::ChannelPtr interface_ptr;
binding_.Bind(mojo::MakeRequest(&interface_ptr));
return interface_ptr;
mojo::PendingRemote<mojom::Channel> FakeChannel::GenerateRemote() {
return receiver_.BindNewPipeAndPassRemote();
}
void FakeChannel::DisconnectGeneratedPtr() {
binding_.CloseWithReason(mojom::Channel::kConnectionDroppedReason,
kDisconnectionDescription);
void FakeChannel::DisconnectGeneratedRemote() {
receiver_.ResetWithReason(mojom::Channel::kConnectionDroppedReason,
kDisconnectionDescription);
}
void FakeChannel::SendMessage(const std::string& message,
......
......@@ -11,7 +11,8 @@
#include "base/macros.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace chromeos {
......@@ -23,8 +24,8 @@ class FakeChannel : public mojom::Channel {
FakeChannel();
~FakeChannel() override;
mojom::ChannelPtr GenerateInterfacePtr();
void DisconnectGeneratedPtr();
mojo::PendingRemote<mojom::Channel> GenerateRemote();
void DisconnectGeneratedRemote();
void set_connection_metadata_for_next_call(
mojom::ConnectionMetadataPtr connection_metadata_for_next_call) {
......@@ -42,7 +43,7 @@ class FakeChannel : public mojom::Channel {
SendMessageCallback callback) override;
void GetConnectionMetadata(GetConnectionMetadataCallback callback) override;
mojo::Binding<mojom::Channel> binding_;
mojo::Receiver<mojom::Channel> receiver_{this};
std::vector<std::pair<std::string, SendMessageCallback>> sent_messages_;
mojom::ConnectionMetadataPtr connection_metadata_for_next_call_;
......
......@@ -36,13 +36,13 @@ void FakeClientConnectionParameters::PerformSetConnectionAttemptFailed(
}
void FakeClientConnectionParameters::PerformSetConnectionSucceeded(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
DCHECK(message_receiver_);
DCHECK(!message_receiver_binding_);
channel_ = std::move(channel);
channel_->set_connection_error_with_reason_handler(
channel_.Bind(std::move(channel));
channel_.set_disconnect_with_reason_handler(
base::BindOnce(&FakeClientConnectionParameters::OnChannelDisconnected,
weak_ptr_factory_.GetWeakPtr()));
......
......@@ -11,6 +11,8 @@
#include "chromeos/services/secure_channel/client_connection_parameters.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
......@@ -32,7 +34,7 @@ class FakeClientConnectionParameters : public ClientConnectionParameters {
return failure_reason_;
}
base::Optional<mojom::ChannelPtr>& channel() { return channel_; }
mojo::Remote<mojom::Channel>& channel() { return channel_; }
void set_message_receiver(
std::unique_ptr<mojom::MessageReceiver> message_receiver) {
......@@ -50,7 +52,7 @@ class FakeClientConnectionParameters : public ClientConnectionParameters {
void PerformSetConnectionAttemptFailed(
mojom::ConnectionAttemptFailureReason reason) override;
void PerformSetConnectionSucceeded(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override;
void OnChannelDisconnected(uint32_t disconnection_reason,
......@@ -64,7 +66,7 @@ class FakeClientConnectionParameters : public ClientConnectionParameters {
base::Optional<mojom::ConnectionAttemptFailureReason> failure_reason_;
base::Optional<mojom::ChannelPtr> channel_;
mojo::Remote<mojom::Channel> channel_;
uint32_t disconnection_reason_ = 0u;
base::OnceCallback<void(const base::UnguessableToken&)> destructor_callback_;
......
......@@ -34,9 +34,9 @@ void FakeConnectionDelegate::OnConnectionAttemptFailure(
}
void FakeConnectionDelegate::OnConnection(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
channel_ = std::move(channel);
channel_.Bind(std::move(channel));
message_receiver_request_ = std::move(message_receiver_request);
if (closure_for_next_delegate_callback_)
......
......@@ -8,6 +8,8 @@
#include "base/macros.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
......@@ -31,7 +33,7 @@ class FakeConnectionDelegate : public mojom::ConnectionDelegate {
closure_for_next_delegate_callback_ = std::move(closure);
}
const base::Optional<mojom::ChannelPtr>& channel() const { return channel_; }
const mojo::Remote<mojom::Channel>& channel() const { return channel_; }
const base::Optional<mojom::MessageReceiverRequest>&
message_receiver_request() const {
......@@ -43,7 +45,7 @@ class FakeConnectionDelegate : public mojom::ConnectionDelegate {
void OnConnectionAttemptFailure(
mojom::ConnectionAttemptFailureReason reason) override;
void OnConnection(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override;
void OnChannelDisconnected(uint32_t disconnection_reason,
......@@ -54,7 +56,7 @@ class FakeConnectionDelegate : public mojom::ConnectionDelegate {
base::Optional<mojom::ConnectionAttemptFailureReason>
connection_attempt_failure_reason_;
base::Optional<mojom::ChannelPtr> channel_;
mojo::Remote<mojom::Channel> channel_;
base::Optional<mojom::MessageReceiverRequest> message_receiver_request_;
DISALLOW_COPY_AND_ASSIGN(FakeConnectionDelegate);
......
......@@ -32,18 +32,18 @@ void ClientChannelImpl::Factory::SetFactoryForTesting(Factory* test_factory) {
ClientChannelImpl::Factory::~Factory() = default;
std::unique_ptr<ClientChannel> ClientChannelImpl::Factory::BuildInstance(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
return base::WrapUnique(new ClientChannelImpl(
std::move(channel), std::move(message_receiver_request)));
}
ClientChannelImpl::ClientChannelImpl(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request)
: channel_(std::move(channel)),
binding_(this, std::move(message_receiver_request)) {
channel_.set_connection_error_with_reason_handler(
channel_.set_disconnect_with_reason_handler(
base::BindOnce(&ClientChannelImpl::OnChannelDisconnected,
weak_ptr_factory_.GetWeakPtr()));
}
......
......@@ -10,6 +10,8 @@
#include "chromeos/services/secure_channel/public/cpp/client/client_channel.h"
#include "chromeos/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
......@@ -24,7 +26,7 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver {
static void SetFactoryForTesting(Factory* test_factory);
virtual ~Factory();
virtual std::unique_ptr<ClientChannel> BuildInstance(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request);
private:
......@@ -36,7 +38,7 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver {
private:
friend class SecureChannelClientChannelImplTest;
ClientChannelImpl(mojom::ChannelPtr channel,
ClientChannelImpl(mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request);
// ClientChannel:
......@@ -57,7 +59,7 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver {
void FlushForTesting();
mojom::ChannelPtr channel_;
mojo::Remote<mojom::Channel> channel_;
mojo::Binding<mojom::MessageReceiver> binding_;
base::WeakPtrFactory<ClientChannelImpl> weak_ptr_factory_{this};
......
......@@ -40,7 +40,7 @@ class SecureChannelClientChannelImplTest : public testing::Test {
fake_channel_ = std::make_unique<FakeChannel>();
client_channel_ = ClientChannelImpl::Factory::Get()->BuildInstance(
fake_channel_->GenerateInterfacePtr(),
fake_channel_->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr_));
fake_observer_ = std::make_unique<FakeClientChannelObserver>();
......@@ -167,7 +167,7 @@ TEST_F(SecureChannelClientChannelImplTest, TestReceiveMessage) {
}
TEST_F(SecureChannelClientChannelImplTest, TestDisconnectRemotely) {
fake_channel_->DisconnectGeneratedPtr();
fake_channel_->DisconnectGeneratedRemote();
SendPendingMojoMessages();
......
......@@ -54,7 +54,7 @@ void ConnectionAttemptImpl::OnConnectionAttemptFailure(
}
void ConnectionAttemptImpl::OnConnection(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
NotifyConnection(ClientChannelImpl::Factory::Get()->BuildInstance(
std::move(channel), std::move(message_receiver_request)));
......
......@@ -9,6 +9,7 @@
#include "base/memory/weak_ptr.h"
#include "chromeos/services/secure_channel/public/cpp/client/connection_attempt.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos {
......@@ -40,7 +41,7 @@ class ConnectionAttemptImpl : public ConnectionAttempt,
void OnConnectionAttemptFailure(
mojom::ConnectionAttemptFailureReason reason) override;
void OnConnection(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override;
private:
......
......@@ -19,7 +19,7 @@ void FakeConnectionAttempt::OnConnectionAttemptFailure(
}
void FakeConnectionAttempt::OnConnection(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) {
ConnectionAttemptImpl::OnConnection(std::move(channel),
std::move(message_receiver_request));
......
......@@ -8,7 +8,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/services/secure_channel/public/cpp/client/connection_attempt_impl.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos {
......@@ -27,7 +27,7 @@ class FakeConnectionAttempt : public ConnectionAttemptImpl {
void OnConnectionAttemptFailure(
mojom::ConnectionAttemptFailureReason reason) override;
void OnConnection(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override;
void set_on_connection_attempt_failure_callback(base::OnceClosure callback) {
......
......@@ -74,7 +74,7 @@ class FakeClientChannelImplFactory : public ClientChannelImpl::Factory {
// ClientChannelImpl::Factory:
std::unique_ptr<ClientChannel> BuildInstance(
mojom::ChannelPtr channel,
mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override {
auto client_channel = std::make_unique<FakeClientChannel>();
last_client_channel_created_ = client_channel.get();
......@@ -236,8 +236,7 @@ TEST_F(SecureChannelClientImplTest, TestInitiateConnectionToDevice) {
mojom::MessageReceiverPtr message_receiver_ptr;
fake_secure_channel_->delegate_from_last_initiate_call()->OnConnection(
fake_channel->GenerateInterfacePtr(),
mojo::MakeRequest(&message_receiver_ptr));
fake_channel->GenerateRemote(), mojo::MakeRequest(&message_receiver_ptr));
run_loop.Run();
......@@ -279,8 +278,7 @@ TEST_F(SecureChannelClientImplTest, TestListenForConnectionFromDevice) {
mojom::MessageReceiverPtr message_receiver_ptr;
fake_secure_channel_->delegate_from_last_listen_call()->OnConnection(
fake_channel->GenerateInterfacePtr(),
mojo::MakeRequest(&message_receiver_ptr));
fake_channel->GenerateRemote(), mojo::MakeRequest(&message_receiver_ptr));
run_loop.Run();
......@@ -319,7 +317,7 @@ TEST_F(SecureChannelClientImplTest, TestMultipleConnections) {
auto fake_channel_1 = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr_1;
fake_secure_channel_->delegate_from_last_initiate_call()->OnConnection(
fake_channel_1->GenerateInterfacePtr(),
fake_channel_1->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr_1));
run_loop_1.Run();
......@@ -337,7 +335,7 @@ TEST_F(SecureChannelClientImplTest, TestMultipleConnections) {
auto fake_channel_2 = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr_2;
fake_secure_channel_->delegate_from_last_listen_call()->OnConnection(
fake_channel_2->GenerateInterfacePtr(),
fake_channel_2->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr_2));
run_loop_2.Run();
......
......@@ -134,7 +134,8 @@ interface ConnectionDelegate {
// |channel| to be notified when it has been invalidated due to a dropped
// connection. Note that clients are expected to hold the reference to
// |channel| until they are done using the connection.
OnConnection(Channel channel, MessageReceiver& message_receiver);
OnConnection(pending_remote<Channel> channel,
MessageReceiver& message_receiver);
};
// Brokers connections between the current Chromebook and remote devices,
......
......@@ -48,8 +48,7 @@ SingleClientMessageProxyImpl::SingleClientMessageProxyImpl(
channel_(std::make_unique<ChannelImpl>(this /* delegate */)) {
DCHECK(client_connection_parameters_);
client_connection_parameters_->SetConnectionSucceeded(
channel_->GenerateInterfacePtr(),
mojo::MakeRequest(&message_receiver_ptr_));
channel_->GenerateRemote(), mojo::MakeRequest(&message_receiver_ptr_));
}
SingleClientMessageProxyImpl::~SingleClientMessageProxyImpl() = default;
......
......@@ -71,7 +71,8 @@ class SecureChannelSingleClientMessageProxyImplTest : public testing::Test {
int message_counter = next_message_counter_++;
mojom::ChannelPtr& channel = *fake_client_connection_parameters_->channel();
mojo::Remote<mojom::Channel>& channel =
fake_client_connection_parameters_->channel();
channel->SendMessage(
message,
base::BindOnce(
......@@ -158,7 +159,8 @@ class SecureChannelSingleClientMessageProxyImplTest : public testing::Test {
mojom::ConnectionMetadataPtr GetConnectionMetadataFromChannel() {
EXPECT_FALSE(last_metadata_from_channel_);
mojom::ChannelPtr& channel = *fake_client_connection_parameters_->channel();
mojo::Remote<mojom::Channel>& channel =
fake_client_connection_parameters_->channel();
channel->GetConnectionMetadata(base::BindOnce(
&SecureChannelSingleClientMessageProxyImplTest::OnConnectionMetadata,
base::Unretained(this)));
......
......@@ -26,7 +26,8 @@
#include "ipc/ipc_mojo_bootstrap.h"
#include "ipc/ipc_mojo_handle_attachment.h"
#include "ipc/native_handle_type_converters.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace IPC {
......@@ -150,8 +151,8 @@ bool ChannelMojo::Connect() {
WillConnect();
mojom::ChannelAssociatedPtr sender;
mojom::ChannelAssociatedRequest receiver;
mojo::AssociatedRemote<mojom::Channel> sender;
mojo::PendingAssociatedReceiver<mojom::Channel> receiver;
bootstrap_->Connect(&sender, &receiver);
DCHECK(!message_reader_);
......
......@@ -23,18 +23,18 @@ namespace internal {
MessagePipeReader::MessagePipeReader(
mojo::MessagePipeHandle pipe,
mojom::ChannelAssociatedPtr sender,
mojo::AssociatedInterfaceRequest<mojom::Channel> receiver,
mojo::AssociatedRemote<mojom::Channel> sender,
mojo::PendingAssociatedReceiver<mojom::Channel> receiver,
MessagePipeReader::Delegate* delegate)
: delegate_(delegate),
sender_(std::move(sender)),
binding_(this, std::move(receiver)) {
sender_.set_connection_error_handler(
base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this),
MOJO_RESULT_FAILED_PRECONDITION));
binding_.set_connection_error_handler(
base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this),
MOJO_RESULT_FAILED_PRECONDITION));
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));
}
MessagePipeReader::~MessagePipeReader() {
......@@ -45,8 +45,8 @@ MessagePipeReader::~MessagePipeReader() {
void MessagePipeReader::Close() {
DCHECK(thread_checker_.CalledOnValidThread());
sender_.reset();
if (binding_.is_bound())
binding_.Close();
if (receiver_.is_bound())
receiver_.reset();
}
bool MessagePipeReader::Send(std::unique_ptr<Message> message) {
......
......@@ -18,7 +18,9 @@
#include "base/threading/thread_checker.h"
#include "ipc/ipc.mojom.h"
#include "ipc/ipc_message.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/message_pipe.h"
......@@ -66,8 +68,8 @@ class COMPONENT_EXPORT(IPC) MessagePipeReader : public mojom::Channel {
//
// Note that MessagePipeReader doesn't delete |delegate|.
MessagePipeReader(mojo::MessagePipeHandle pipe,
mojom::ChannelAssociatedPtr sender,
mojo::AssociatedInterfaceRequest<mojom::Channel> receiver,
mojo::AssociatedRemote<mojom::Channel> sender,
mojo::PendingAssociatedReceiver<mojom::Channel> receiver,
Delegate* delegate);
~MessagePipeReader() override;
......@@ -85,7 +87,7 @@ class COMPONENT_EXPORT(IPC) MessagePipeReader : public mojom::Channel {
void GetRemoteInterface(const std::string& name,
mojo::ScopedInterfaceEndpointHandle handle);
mojom::ChannelAssociatedPtr& sender() { return sender_; }
mojo::AssociatedRemote<mojom::Channel>& sender() { return sender_; }
protected:
void OnPipeClosed();
......@@ -101,8 +103,8 @@ class COMPONENT_EXPORT(IPC) MessagePipeReader : public mojom::Channel {
// |delegate_| is null once the message pipe is closed.
Delegate* delegate_;
mojom::ChannelAssociatedPtr sender_;
mojo::AssociatedBinding<mojom::Channel> binding_;
mojo::AssociatedRemote<mojom::Channel> sender_;
mojo::AssociatedReceiver<mojom::Channel> receiver_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(MessagePipeReader);
......
......@@ -202,8 +202,9 @@ class ChannelAssociatedGroupController
SendMessage(&message);
}
void CreateChannelEndpoints(mojom::ChannelAssociatedPtr* sender,
mojom::ChannelAssociatedRequest* receiver) {
void CreateChannelEndpoints(
mojo::AssociatedRemote<mojom::Channel>* sender,
mojo::PendingAssociatedReceiver<mojom::Channel>* receiver) {
mojo::InterfaceId sender_id, receiver_id;
if (set_interface_id_namespace_bit_) {
sender_id = 1 | mojo::kInterfaceIdNamespaceMask;
......@@ -228,8 +229,10 @@ class ChannelAssociatedGroupController
mojo::ScopedInterfaceEndpointHandle receiver_handle =
CreateScopedInterfaceEndpointHandle(receiver_id);
sender->Bind(mojom::ChannelAssociatedPtrInfo(std::move(sender_handle), 0));
*receiver = mojom::ChannelAssociatedRequest(std::move(receiver_handle));
sender->Bind(mojo::PendingAssociatedRemote<mojom::Channel>(
std::move(sender_handle), 0));
*receiver = mojo::PendingAssociatedReceiver<mojom::Channel>(
std::move(receiver_handle));
}
void ShutDown() {
......@@ -1059,8 +1062,9 @@ class MojoBootstrapImpl : public MojoBootstrap {
}
private:
void Connect(mojom::ChannelAssociatedPtr* sender,
mojom::ChannelAssociatedRequest* receiver) override {
void Connect(
mojo::AssociatedRemote<mojom::Channel>* sender,
mojo::PendingAssociatedReceiver<mojom::Channel>* receiver) override {
controller_->Bind(std::move(handle_));
controller_->CreateChannelEndpoints(sender, receiver);
}
......
......@@ -18,6 +18,8 @@
#include "ipc/ipc_channel.h"
#include "ipc/ipc_listener.h"
#include "mojo/public/cpp/bindings/associated_group.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/system/message_pipe.h"
namespace IPC {
......@@ -43,8 +45,9 @@ class COMPONENT_EXPORT(IPC) MojoBootstrap {
const scoped_refptr<base::SingleThreadTaskRunner>& proxy_task_runner);
// Start the handshake over the underlying message pipe.
virtual void Connect(mojom::ChannelAssociatedPtr* sender,
mojom::ChannelAssociatedRequest* receiver) = 0;
virtual void Connect(
mojo::AssociatedRemote<mojom::Channel>* sender,
mojo::PendingAssociatedReceiver<mojom::Channel>* receiver) = 0;
// Stop transmitting messages and start queueing them instead.
virtual void Pause() = 0;
......
......@@ -14,7 +14,7 @@
#include "ipc/ipc.mojom.h"
#include "ipc/ipc_test_base.h"
#include "mojo/core/test/multiprocess_test_helper.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
namespace {
......@@ -30,15 +30,16 @@ class Connection {
sender_->SetPeerPid(sender_id);
}
void TakeReceiver(IPC::mojom::ChannelAssociatedRequest* receiver) {
void TakeReceiver(
mojo::PendingAssociatedReceiver<IPC::mojom::Channel>* receiver) {
*receiver = std::move(receiver_);
}
IPC::mojom::ChannelAssociatedPtr& GetSender() { return sender_; }
mojo::AssociatedRemote<IPC::mojom::Channel>& GetSender() { return sender_; }
private:
IPC::mojom::ChannelAssociatedPtr sender_;
IPC::mojom::ChannelAssociatedRequest receiver_;
mojo::AssociatedRemote<IPC::mojom::Channel> sender_;
mojo::PendingAssociatedReceiver<IPC::mojom::Channel> receiver_;
std::unique_ptr<IPC::MojoBootstrap> bootstrap_;
};
......@@ -51,13 +52,13 @@ class PeerPidReceiver : public IPC::mojom::Channel {
};
PeerPidReceiver(
IPC::mojom::ChannelAssociatedRequest request,
mojo::PendingAssociatedReceiver<IPC::mojom::Channel> receiver,
const base::Closure& on_peer_pid_set,
MessageExpectation message_expectation = MessageExpectation::kNotExpected)
: binding_(this, std::move(request)),
: receiver_(this, std::move(receiver)),
on_peer_pid_set_(on_peer_pid_set),
message_expectation_(message_expectation) {
binding_.set_connection_error_handler(disconnect_run_loop_.QuitClosure());
receiver_.set_disconnect_handler(disconnect_run_loop_.QuitClosure());
}
~PeerPidReceiver() override {
......@@ -91,7 +92,7 @@ class PeerPidReceiver : public IPC::mojom::Channel {
void RunUntilDisconnect() { disconnect_run_loop_.Run(); }
private:
mojo::AssociatedBinding<IPC::mojom::Channel> binding_;
mojo::AssociatedReceiver<IPC::mojom::Channel> receiver_;
const base::Closure on_peer_pid_set_;
MessageExpectation message_expectation_;
int32_t peer_pid_ = -1;
......@@ -115,7 +116,7 @@ TEST_F(IPCMojoBootstrapTest, Connect) {
base::ThreadTaskRunnerHandle::Get()),
kTestServerPid);
IPC::mojom::ChannelAssociatedRequest receiver;
mojo::PendingAssociatedReceiver<IPC::mojom::Channel> receiver;
connection.TakeReceiver(&receiver);
base::RunLoop run_loop;
......@@ -140,7 +141,7 @@ MULTIPROCESS_TEST_MAIN_WITH_SETUP(
base::ThreadTaskRunnerHandle::Get()),
kTestClientPid);
IPC::mojom::ChannelAssociatedRequest receiver;
mojo::PendingAssociatedReceiver<IPC::mojom::Channel> receiver;
connection.TakeReceiver(&receiver);
base::RunLoop run_loop;
......@@ -161,7 +162,7 @@ TEST_F(IPCMojoBootstrapTest, ReceiveEmptyMessage) {
base::ThreadTaskRunnerHandle::Get()),
kTestServerPid);
IPC::mojom::ChannelAssociatedRequest receiver;
mojo::PendingAssociatedReceiver<IPC::mojom::Channel> receiver;
connection.TakeReceiver(&receiver);
base::RunLoop run_loop;
......@@ -188,7 +189,7 @@ MULTIPROCESS_TEST_MAIN_WITH_SETUP(
base::ThreadTaskRunnerHandle::Get()),
kTestClientPid);
IPC::mojom::ChannelAssociatedRequest receiver;
mojo::PendingAssociatedReceiver<IPC::mojom::Channel> receiver;
connection.TakeReceiver(&receiver);
auto& sender = connection.GetSender();
......
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