Commit cdf6b796 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert mojom::MessageReceiver to new Mojo types

This CL converts MessageReceiverPtr, MessageReceiverRequest to
new Mojo types using PendingRemote or Remote, PendingReceiver,
and Receiver.

It also updates OnConnection from secure_channel.mojom.

Bug: 955171
Change-Id: Id630cb964ad03f439b696e93182bc29b13fa689d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1820777
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699734}
parent f9951b66
...@@ -40,12 +40,12 @@ void ClientConnectionParameters::SetConnectionAttemptFailed( ...@@ -40,12 +40,12 @@ void ClientConnectionParameters::SetConnectionAttemptFailed(
void ClientConnectionParameters::SetConnectionSucceeded( void ClientConnectionParameters::SetConnectionSucceeded(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
static const std::string kFunctionName = "SetConnectionSucceeded"; static const std::string kFunctionName = "SetConnectionSucceeded";
VerifyDelegateWaitingForResponse(kFunctionName); VerifyDelegateWaitingForResponse(kFunctionName);
has_invoked_delegate_function_ = true; has_invoked_delegate_function_ = true;
PerformSetConnectionSucceeded(std::move(channel), PerformSetConnectionSucceeded(std::move(channel),
std::move(message_receiver_request)); std::move(message_receiver_receiver));
} }
bool ClientConnectionParameters::operator==( bool ClientConnectionParameters::operator==(
......
...@@ -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_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos { namespace chromeos {
...@@ -49,12 +50,12 @@ class ClientConnectionParameters { ...@@ -49,12 +50,12 @@ class ClientConnectionParameters {
void SetConnectionAttemptFailed(mojom::ConnectionAttemptFailureReason reason); void SetConnectionAttemptFailed(mojom::ConnectionAttemptFailureReason reason);
// Alerts the client that the connection has succeeded, providing the client // Alerts the client that the connection has succeeded, providing the client
// with a Channel and a request to bind a MessageReceiver. This function can // with a Channel and a receiver to bind a MessageReceiver. This function can
// 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(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request); mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver);
bool operator==(const ClientConnectionParameters& other) const; bool operator==(const ClientConnectionParameters& other) const;
bool operator<(const ClientConnectionParameters& other) const; bool operator<(const ClientConnectionParameters& other) const;
...@@ -65,7 +66,8 @@ class ClientConnectionParameters { ...@@ -65,7 +66,8 @@ class ClientConnectionParameters {
mojom::ConnectionAttemptFailureReason reason) = 0; mojom::ConnectionAttemptFailureReason reason) = 0;
virtual void PerformSetConnectionSucceeded( virtual void PerformSetConnectionSucceeded(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) = 0; mojo::PendingReceiver<mojom::MessageReceiver>
message_receiver_receiver) = 0;
void NotifyConnectionRequestCanceled(); void NotifyConnectionRequestCanceled();
......
...@@ -67,9 +67,9 @@ void ClientConnectionParametersImpl::PerformSetConnectionAttemptFailed( ...@@ -67,9 +67,9 @@ void ClientConnectionParametersImpl::PerformSetConnectionAttemptFailed(
void ClientConnectionParametersImpl::PerformSetConnectionSucceeded( void ClientConnectionParametersImpl::PerformSetConnectionSucceeded(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
connection_delegate_ptr_->OnConnection(std::move(channel), connection_delegate_ptr_->OnConnection(std::move(channel),
std::move(message_receiver_request)); std::move(message_receiver_receiver));
} }
void ClientConnectionParametersImpl::OnConnectionDelegatePtrDisconnected() { void ClientConnectionParametersImpl::OnConnectionDelegatePtrDisconnected() {
......
...@@ -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_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos { namespace chromeos {
...@@ -44,7 +45,8 @@ class ClientConnectionParametersImpl : public ClientConnectionParameters { ...@@ -44,7 +45,8 @@ class ClientConnectionParametersImpl : public ClientConnectionParameters {
mojom::ConnectionAttemptFailureReason reason) override; mojom::ConnectionAttemptFailureReason reason) override;
void PerformSetConnectionSucceeded( void PerformSetConnectionSucceeded(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override; mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver)
override;
void OnConnectionDelegatePtrDisconnected(); void OnConnectionDelegatePtrDisconnected();
......
...@@ -55,12 +55,12 @@ class SecureChannelClientConnectionParametersImplTest : public testing::Test { ...@@ -55,12 +55,12 @@ class SecureChannelClientConnectionParametersImplTest : public testing::Test {
void CallOnConnection( void CallOnConnection(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
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(
run_loop.QuitClosure()); run_loop.QuitClosure());
client_connection_parameters_->SetConnectionSucceeded( client_connection_parameters_->SetConnectionSucceeded(
std::move(channel), std::move(message_receiver_request)); std::move(channel), std::move(message_receiver_receiver));
run_loop.Run(); run_loop.Run();
} }
...@@ -107,15 +107,15 @@ TEST_F(SecureChannelClientConnectionParametersImplTest, ...@@ -107,15 +107,15 @@ TEST_F(SecureChannelClientConnectionParametersImplTest,
TEST_F(SecureChannelClientConnectionParametersImplTest, OnConnection) { TEST_F(SecureChannelClientConnectionParametersImplTest, OnConnection) {
auto fake_channel = std::make_unique<FakeChannel>(); auto fake_channel = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr; mojo::PendingRemote<mojom::MessageReceiver> message_receiver_remote;
CallOnConnection(fake_channel->GenerateRemote(), CallOnConnection(fake_channel->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr)); message_receiver_remote.InitWithNewPipeAndPassReceiver());
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 */);
EXPECT_TRUE(fake_connection_delegate()->channel()); EXPECT_TRUE(fake_connection_delegate()->channel());
EXPECT_TRUE(fake_connection_delegate()->message_receiver_request()); EXPECT_TRUE(fake_connection_delegate()->message_receiver_receiver());
} }
TEST_F(SecureChannelClientConnectionParametersImplTest, OnConnectionFailed) { TEST_F(SecureChannelClientConnectionParametersImplTest, OnConnectionFailed) {
......
...@@ -37,18 +37,18 @@ void FakeClientConnectionParameters::PerformSetConnectionAttemptFailed( ...@@ -37,18 +37,18 @@ void FakeClientConnectionParameters::PerformSetConnectionAttemptFailed(
void FakeClientConnectionParameters::PerformSetConnectionSucceeded( void FakeClientConnectionParameters::PerformSetConnectionSucceeded(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
DCHECK(message_receiver_); DCHECK(message_receiver_);
DCHECK(!message_receiver_binding_); DCHECK(!message_receiver_receiver_);
channel_.Bind(std::move(channel)); channel_.Bind(std::move(channel));
channel_.set_disconnect_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()));
message_receiver_binding_ = message_receiver_receiver_ =
std::make_unique<mojo::Binding<mojom::MessageReceiver>>( std::make_unique<mojo::Receiver<mojom::MessageReceiver>>(
message_receiver_.get(), std::move(message_receiver_request)); message_receiver_.get(), std::move(message_receiver_receiver));
} }
void FakeClientConnectionParameters::OnChannelDisconnected( void FakeClientConnectionParameters::OnChannelDisconnected(
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.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/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
namespace chromeos { namespace chromeos {
...@@ -53,7 +54,8 @@ class FakeClientConnectionParameters : public ClientConnectionParameters { ...@@ -53,7 +54,8 @@ class FakeClientConnectionParameters : public ClientConnectionParameters {
mojom::ConnectionAttemptFailureReason reason) override; mojom::ConnectionAttemptFailureReason reason) override;
void PerformSetConnectionSucceeded( void PerformSetConnectionSucceeded(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override; mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver)
override;
void OnChannelDisconnected(uint32_t disconnection_reason, void OnChannelDisconnected(uint32_t disconnection_reason,
const std::string& disconnection_description); const std::string& disconnection_description);
...@@ -61,8 +63,8 @@ class FakeClientConnectionParameters : public ClientConnectionParameters { ...@@ -61,8 +63,8 @@ class FakeClientConnectionParameters : public ClientConnectionParameters {
bool has_canceled_client_request_ = false; bool has_canceled_client_request_ = false;
std::unique_ptr<mojom::MessageReceiver> message_receiver_; std::unique_ptr<mojom::MessageReceiver> message_receiver_;
std::unique_ptr<mojo::Binding<mojom::MessageReceiver>> std::unique_ptr<mojo::Receiver<mojom::MessageReceiver>>
message_receiver_binding_; message_receiver_receiver_;
base::Optional<mojom::ConnectionAttemptFailureReason> failure_reason_; base::Optional<mojom::ConnectionAttemptFailureReason> failure_reason_;
......
...@@ -35,9 +35,9 @@ void FakeConnectionDelegate::OnConnectionAttemptFailure( ...@@ -35,9 +35,9 @@ void FakeConnectionDelegate::OnConnectionAttemptFailure(
void FakeConnectionDelegate::OnConnection( void FakeConnectionDelegate::OnConnection(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
channel_.Bind(std::move(channel)); channel_.Bind(std::move(channel));
message_receiver_request_ = std::move(message_receiver_request); message_receiver_receiver_ = std::move(message_receiver_receiver);
if (closure_for_next_delegate_callback_) if (closure_for_next_delegate_callback_)
std::move(closure_for_next_delegate_callback_).Run(); std::move(closure_for_next_delegate_callback_).Run();
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#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_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
...@@ -35,18 +36,18 @@ class FakeConnectionDelegate : public mojom::ConnectionDelegate { ...@@ -35,18 +36,18 @@ class FakeConnectionDelegate : public mojom::ConnectionDelegate {
const mojo::Remote<mojom::Channel>& channel() const { return channel_; } const mojo::Remote<mojom::Channel>& channel() const { return channel_; }
const base::Optional<mojom::MessageReceiverRequest>& const mojo::PendingReceiver<mojom::MessageReceiver>&
message_receiver_request() const { message_receiver_receiver() const {
return message_receiver_request_; return message_receiver_receiver_;
} }
private: private:
// mojom::ConnectionDelegate: // mojom::ConnectionDelegate:
void OnConnectionAttemptFailure( void OnConnectionAttemptFailure(
mojom::ConnectionAttemptFailureReason reason) override; mojom::ConnectionAttemptFailureReason reason) override;
void OnConnection( void OnConnection(mojo::PendingRemote<mojom::Channel> channel,
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingReceiver<mojom::MessageReceiver>
mojom::MessageReceiverRequest message_receiver_request) override; message_receiver_receiver) override;
void OnChannelDisconnected(uint32_t disconnection_reason, void OnChannelDisconnected(uint32_t disconnection_reason,
const std::string& disconnection_description); const std::string& disconnection_description);
...@@ -57,7 +58,7 @@ class FakeConnectionDelegate : public mojom::ConnectionDelegate { ...@@ -57,7 +58,7 @@ class FakeConnectionDelegate : public mojom::ConnectionDelegate {
base::Optional<mojom::ConnectionAttemptFailureReason> base::Optional<mojom::ConnectionAttemptFailureReason>
connection_attempt_failure_reason_; connection_attempt_failure_reason_;
mojo::Remote<mojom::Channel> channel_; mojo::Remote<mojom::Channel> channel_;
base::Optional<mojom::MessageReceiverRequest> message_receiver_request_; mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver_;
DISALLOW_COPY_AND_ASSIGN(FakeConnectionDelegate); DISALLOW_COPY_AND_ASSIGN(FakeConnectionDelegate);
}; };
......
...@@ -33,16 +33,16 @@ ClientChannelImpl::Factory::~Factory() = default; ...@@ -33,16 +33,16 @@ ClientChannelImpl::Factory::~Factory() = default;
std::unique_ptr<ClientChannel> ClientChannelImpl::Factory::BuildInstance( std::unique_ptr<ClientChannel> ClientChannelImpl::Factory::BuildInstance(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
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_receiver)));
} }
ClientChannelImpl::ClientChannelImpl( ClientChannelImpl::ClientChannelImpl(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver)
: channel_(std::move(channel)), : channel_(std::move(channel)),
binding_(this, std::move(message_receiver_request)) { receiver_(this, std::move(message_receiver_receiver)) {
channel_.set_disconnect_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()));
...@@ -81,7 +81,7 @@ void ClientChannelImpl::OnChannelDisconnected( ...@@ -81,7 +81,7 @@ void ClientChannelImpl::OnChannelDisconnected(
} }
channel_.reset(); channel_.reset();
binding_.Close(); receiver_.reset();
NotifyDisconnected(); NotifyDisconnected();
} }
......
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#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/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
namespace chromeos { namespace chromeos {
...@@ -27,7 +28,8 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver { ...@@ -27,7 +28,8 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver {
virtual ~Factory(); virtual ~Factory();
virtual std::unique_ptr<ClientChannel> BuildInstance( virtual std::unique_ptr<ClientChannel> BuildInstance(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request); mojo::PendingReceiver<mojom::MessageReceiver>
message_receiver_receiver);
private: private:
static Factory* test_factory_; static Factory* test_factory_;
...@@ -38,8 +40,9 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver { ...@@ -38,8 +40,9 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver {
private: private:
friend class SecureChannelClientChannelImplTest; friend class SecureChannelClientChannelImplTest;
ClientChannelImpl(mojo::PendingRemote<mojom::Channel> channel, ClientChannelImpl(
mojom::MessageReceiverRequest message_receiver_request); mojo::PendingRemote<mojom::Channel> channel,
mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver);
// ClientChannel: // ClientChannel:
void PerformGetConnectionMetadata( void PerformGetConnectionMetadata(
...@@ -60,7 +63,7 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver { ...@@ -60,7 +63,7 @@ class ClientChannelImpl : public ClientChannel, public mojom::MessageReceiver {
void FlushForTesting(); void FlushForTesting();
mojo::Remote<mojom::Channel> channel_; mojo::Remote<mojom::Channel> channel_;
mojo::Binding<mojom::MessageReceiver> binding_; mojo::Receiver<mojom::MessageReceiver> receiver_;
base::WeakPtrFactory<ClientChannelImpl> weak_ptr_factory_{this}; base::WeakPtrFactory<ClientChannelImpl> weak_ptr_factory_{this};
......
...@@ -41,7 +41,7 @@ class SecureChannelClientChannelImplTest : public testing::Test { ...@@ -41,7 +41,7 @@ class SecureChannelClientChannelImplTest : public testing::Test {
client_channel_ = ClientChannelImpl::Factory::Get()->BuildInstance( client_channel_ = ClientChannelImpl::Factory::Get()->BuildInstance(
fake_channel_->GenerateRemote(), fake_channel_->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr_)); message_receiver_remote_.BindNewPipeAndPassReceiver());
fake_observer_ = std::make_unique<FakeClientChannelObserver>(); fake_observer_ = std::make_unique<FakeClientChannelObserver>();
client_channel_->AddObserver(fake_observer_.get()); client_channel_->AddObserver(fake_observer_.get());
...@@ -99,7 +99,7 @@ class SecureChannelClientChannelImplTest : public testing::Test { ...@@ -99,7 +99,7 @@ class SecureChannelClientChannelImplTest : public testing::Test {
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
std::unique_ptr<FakeChannel> fake_channel_; std::unique_ptr<FakeChannel> fake_channel_;
mojom::MessageReceiverPtr message_receiver_ptr_; mojo::Remote<mojom::MessageReceiver> message_receiver_remote_;
std::unique_ptr<FakeClientChannelObserver> fake_observer_; std::unique_ptr<FakeClientChannelObserver> fake_observer_;
mojom::ConnectionMetadataPtr connection_metadata_; mojom::ConnectionMetadataPtr connection_metadata_;
...@@ -159,8 +159,8 @@ TEST_F(SecureChannelClientChannelImplTest, TestSendMessage) { ...@@ -159,8 +159,8 @@ TEST_F(SecureChannelClientChannelImplTest, TestSendMessage) {
} }
TEST_F(SecureChannelClientChannelImplTest, TestReceiveMessage) { TEST_F(SecureChannelClientChannelImplTest, TestReceiveMessage) {
message_receiver_ptr_->OnMessageReceived("payload"); message_receiver_remote_->OnMessageReceived("payload");
message_receiver_ptr_.FlushForTesting(); message_receiver_remote_.FlushForTesting();
EXPECT_EQ(1u, fake_observer_->received_messages().size()); EXPECT_EQ(1u, fake_observer_->received_messages().size());
EXPECT_EQ("payload", fake_observer_->received_messages()[0]); EXPECT_EQ("payload", fake_observer_->received_messages()[0]);
......
...@@ -55,9 +55,9 @@ void ConnectionAttemptImpl::OnConnectionAttemptFailure( ...@@ -55,9 +55,9 @@ void ConnectionAttemptImpl::OnConnectionAttemptFailure(
void ConnectionAttemptImpl::OnConnection( void ConnectionAttemptImpl::OnConnection(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
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_receiver)));
} }
} // namespace secure_channel } // namespace secure_channel
......
...@@ -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_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos { namespace chromeos {
...@@ -40,9 +41,9 @@ class ConnectionAttemptImpl : public ConnectionAttempt, ...@@ -40,9 +41,9 @@ class ConnectionAttemptImpl : public ConnectionAttempt,
// mojom::ConnectionDelegate: // mojom::ConnectionDelegate:
void OnConnectionAttemptFailure( void OnConnectionAttemptFailure(
mojom::ConnectionAttemptFailureReason reason) override; mojom::ConnectionAttemptFailureReason reason) override;
void OnConnection( void OnConnection(mojo::PendingRemote<mojom::Channel> channel,
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingReceiver<mojom::MessageReceiver>
mojom::MessageReceiverRequest message_receiver_request) override; message_receiver_receiver) override;
private: private:
mojo::Binding<mojom::ConnectionDelegate> binding_; mojo::Binding<mojom::ConnectionDelegate> binding_;
......
...@@ -20,9 +20,9 @@ void FakeConnectionAttempt::OnConnectionAttemptFailure( ...@@ -20,9 +20,9 @@ void FakeConnectionAttempt::OnConnectionAttemptFailure(
void FakeConnectionAttempt::OnConnection( void FakeConnectionAttempt::OnConnection(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver) {
ConnectionAttemptImpl::OnConnection(std::move(channel), ConnectionAttemptImpl::OnConnection(std::move(channel),
std::move(message_receiver_request)); std::move(message_receiver_receiver));
std::move(on_connection_callback_).Run(); std::move(on_connection_callback_).Run();
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +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/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos { namespace chromeos {
...@@ -26,9 +27,9 @@ class FakeConnectionAttempt : public ConnectionAttemptImpl { ...@@ -26,9 +27,9 @@ class FakeConnectionAttempt : public ConnectionAttemptImpl {
// ConnectionAttemptImpl: // ConnectionAttemptImpl:
void OnConnectionAttemptFailure( void OnConnectionAttemptFailure(
mojom::ConnectionAttemptFailureReason reason) override; mojom::ConnectionAttemptFailureReason reason) override;
void OnConnection( void OnConnection(mojo::PendingRemote<mojom::Channel> channel,
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingReceiver<mojom::MessageReceiver>
mojom::MessageReceiverRequest message_receiver_request) override; message_receiver_receiver) override;
void set_on_connection_attempt_failure_callback(base::OnceClosure callback) { void set_on_connection_attempt_failure_callback(base::OnceClosure callback) {
on_connection_attempt_failure_callback_ = std::move(callback); on_connection_attempt_failure_callback_ = std::move(callback);
......
...@@ -75,7 +75,8 @@ class FakeClientChannelImplFactory : public ClientChannelImpl::Factory { ...@@ -75,7 +75,8 @@ class FakeClientChannelImplFactory : public ClientChannelImpl::Factory {
// ClientChannelImpl::Factory: // ClientChannelImpl::Factory:
std::unique_ptr<ClientChannel> BuildInstance( std::unique_ptr<ClientChannel> BuildInstance(
mojo::PendingRemote<mojom::Channel> channel, mojo::PendingRemote<mojom::Channel> channel,
mojom::MessageReceiverRequest message_receiver_request) override { mojo::PendingReceiver<mojom::MessageReceiver> message_receiver_receiver)
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();
return client_channel; return client_channel;
...@@ -233,10 +234,11 @@ TEST_F(SecureChannelClientImplTest, TestInitiateConnectionToDevice) { ...@@ -233,10 +234,11 @@ TEST_F(SecureChannelClientImplTest, TestInitiateConnectionToDevice) {
fake_connection_attempt->set_on_connection_callback(run_loop.QuitClosure()); fake_connection_attempt->set_on_connection_callback(run_loop.QuitClosure());
auto fake_channel = std::make_unique<FakeChannel>(); auto fake_channel = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr; mojo::PendingRemote<mojom::MessageReceiver> message_receiver_remote;
fake_secure_channel_->delegate_from_last_initiate_call()->OnConnection( fake_secure_channel_->delegate_from_last_initiate_call()->OnConnection(
fake_channel->GenerateRemote(), mojo::MakeRequest(&message_receiver_ptr)); fake_channel->GenerateRemote(),
message_receiver_remote.InitWithNewPipeAndPassReceiver());
run_loop.Run(); run_loop.Run();
...@@ -275,10 +277,11 @@ TEST_F(SecureChannelClientImplTest, TestListenForConnectionFromDevice) { ...@@ -275,10 +277,11 @@ TEST_F(SecureChannelClientImplTest, TestListenForConnectionFromDevice) {
fake_connection_attempt->set_on_connection_callback(run_loop.QuitClosure()); fake_connection_attempt->set_on_connection_callback(run_loop.QuitClosure());
auto fake_channel = std::make_unique<FakeChannel>(); auto fake_channel = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr; mojo::PendingRemote<mojom::MessageReceiver> message_receiver_remote;
fake_secure_channel_->delegate_from_last_listen_call()->OnConnection( fake_secure_channel_->delegate_from_last_listen_call()->OnConnection(
fake_channel->GenerateRemote(), mojo::MakeRequest(&message_receiver_ptr)); fake_channel->GenerateRemote(),
message_receiver_remote.InitWithNewPipeAndPassReceiver());
run_loop.Run(); run_loop.Run();
...@@ -315,10 +318,10 @@ TEST_F(SecureChannelClientImplTest, TestMultipleConnections) { ...@@ -315,10 +318,10 @@ TEST_F(SecureChannelClientImplTest, TestMultipleConnections) {
fake_connection_attempt_1->set_on_connection_callback( fake_connection_attempt_1->set_on_connection_callback(
run_loop_1.QuitClosure()); run_loop_1.QuitClosure());
auto fake_channel_1 = std::make_unique<FakeChannel>(); auto fake_channel_1 = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr_1; mojo::PendingRemote<mojom::MessageReceiver> message_receiver_remote_1;
fake_secure_channel_->delegate_from_last_initiate_call()->OnConnection( fake_secure_channel_->delegate_from_last_initiate_call()->OnConnection(
fake_channel_1->GenerateRemote(), fake_channel_1->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr_1)); message_receiver_remote_1.InitWithNewPipeAndPassReceiver());
run_loop_1.Run(); run_loop_1.Run();
ClientChannel* client_channel_1 = ClientChannel* client_channel_1 =
...@@ -333,10 +336,10 @@ TEST_F(SecureChannelClientImplTest, TestMultipleConnections) { ...@@ -333,10 +336,10 @@ TEST_F(SecureChannelClientImplTest, TestMultipleConnections) {
fake_connection_attempt_2->set_on_connection_callback( fake_connection_attempt_2->set_on_connection_callback(
run_loop_2.QuitClosure()); run_loop_2.QuitClosure());
auto fake_channel_2 = std::make_unique<FakeChannel>(); auto fake_channel_2 = std::make_unique<FakeChannel>();
mojom::MessageReceiverPtr message_receiver_ptr_2; mojo::PendingRemote<mojom::MessageReceiver> message_receiver_remote_2;
fake_secure_channel_->delegate_from_last_listen_call()->OnConnection( fake_secure_channel_->delegate_from_last_listen_call()->OnConnection(
fake_channel_2->GenerateRemote(), fake_channel_2->GenerateRemote(),
mojo::MakeRequest(&message_receiver_ptr_2)); message_receiver_remote_2.InitWithNewPipeAndPassReceiver());
run_loop_2.Run(); run_loop_2.Run();
ClientChannel* client_channel_2 = ClientChannel* client_channel_2 =
......
...@@ -135,7 +135,7 @@ interface ConnectionDelegate { ...@@ -135,7 +135,7 @@ interface ConnectionDelegate {
// 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(pending_remote<Channel> channel, OnConnection(pending_remote<Channel> channel,
MessageReceiver& message_receiver); pending_receiver<MessageReceiver> message_receiver_receiver);
}; };
// Brokers connections between the current Chromebook and remote devices, // Brokers connections between the current Chromebook and remote devices,
......
...@@ -48,7 +48,8 @@ SingleClientMessageProxyImpl::SingleClientMessageProxyImpl( ...@@ -48,7 +48,8 @@ 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_->GenerateRemote(), mojo::MakeRequest(&message_receiver_ptr_)); channel_->GenerateRemote(),
message_receiver_remote_.BindNewPipeAndPassReceiver());
} }
SingleClientMessageProxyImpl::~SingleClientMessageProxyImpl() = default; SingleClientMessageProxyImpl::~SingleClientMessageProxyImpl() = default;
...@@ -64,7 +65,7 @@ void SingleClientMessageProxyImpl::HandleReceivedMessage( ...@@ -64,7 +65,7 @@ void SingleClientMessageProxyImpl::HandleReceivedMessage(
if (feature != client_connection_parameters_->feature()) if (feature != client_connection_parameters_->feature())
return; return;
message_receiver_ptr_->OnMessageReceived(payload); message_receiver_remote_->OnMessageReceived(payload);
} }
void SingleClientMessageProxyImpl::HandleRemoteDeviceDisconnection() { void SingleClientMessageProxyImpl::HandleRemoteDeviceDisconnection() {
...@@ -88,8 +89,8 @@ void SingleClientMessageProxyImpl::OnClientDisconnected() { ...@@ -88,8 +89,8 @@ void SingleClientMessageProxyImpl::OnClientDisconnected() {
} }
void SingleClientMessageProxyImpl::FlushForTesting() { void SingleClientMessageProxyImpl::FlushForTesting() {
DCHECK(message_receiver_ptr_); DCHECK(message_receiver_remote_);
message_receiver_ptr_.FlushForTesting(); message_receiver_remote_.FlushForTesting();
} }
} // namespace secure_channel } // namespace secure_channel
......
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
#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 "chromeos/services/secure_channel/single_client_message_proxy.h" #include "chromeos/services/secure_channel/single_client_message_proxy.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/remote.h"
namespace chromeos { namespace chromeos {
namespace secure_channel { namespace secure_channel {
// Concrete SingleClientMessageProxy implementation, which utilizes a // Concrete SingleClientMessageProxy implementation, which utilizes a
// ChannelImpl and MessageReceiverPtr to send/receive messages. // ChannelImpl and mojo::Remote<MessageReceiver> to send/receive messages.
class SingleClientMessageProxyImpl : public SingleClientMessageProxy, class SingleClientMessageProxyImpl : public SingleClientMessageProxy,
public ChannelImpl::Delegate { public ChannelImpl::Delegate {
public: public:
...@@ -65,7 +65,7 @@ class SingleClientMessageProxyImpl : public SingleClientMessageProxy, ...@@ -65,7 +65,7 @@ class SingleClientMessageProxyImpl : public SingleClientMessageProxy,
std::unique_ptr<ClientConnectionParameters> client_connection_parameters_; std::unique_ptr<ClientConnectionParameters> client_connection_parameters_;
std::unique_ptr<ChannelImpl> channel_; std::unique_ptr<ChannelImpl> channel_;
mojom::MessageReceiverPtr message_receiver_ptr_; mojo::Remote<mojom::MessageReceiver> message_receiver_remote_;
DISALLOW_COPY_AND_ASSIGN(SingleClientMessageProxyImpl); DISALLOW_COPY_AND_ASSIGN(SingleClientMessageProxyImpl);
}; };
......
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