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