Commit 6f9a2349 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert ActivationDelegate to new Mojo types

This CL converts ActivationDelegate from cellular_setup.mojom
to new Mojo types using PendingRemote, ReceiverSet, and Remote.

Bug: 955171
Change-Id: I95085ca9a9d9759bf71366be043adb7223a9a32b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872093
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708881}
parent 5764e0dc
......@@ -21,7 +21,7 @@ CellularSetupImpl::CellularSetupImpl() = default;
CellularSetupImpl::~CellularSetupImpl() = default;
void CellularSetupImpl::StartActivation(
mojom::ActivationDelegatePtr delegate,
mojo::PendingRemote<mojom::ActivationDelegate> delegate,
StartActivationCallback callback) {
size_t request_id = next_request_id_;
++next_request_id_;
......
......@@ -10,6 +10,7 @@
#include "base/containers/id_map.h"
#include "base/macros.h"
#include "chromeos/services/cellular_setup/cellular_setup_base.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos {
......@@ -27,7 +28,7 @@ class CellularSetupImpl : public CellularSetupBase {
private:
// mojom::CellularSetup:
void StartActivation(mojom::ActivationDelegatePtr delegate,
void StartActivation(mojo::PendingRemote<mojom::ActivationDelegate> delegate,
StartActivationCallback callback) override;
void OnActivationAttemptFinished(size_t request_id);
......
......@@ -39,7 +39,7 @@ class FakeOtaActivatorFactory : public OtaActivatorImpl::Factory {
private:
// OtaActivatorImpl::Factory:
std::unique_ptr<OtaActivator> BuildInstance(
mojom::ActivationDelegatePtr activation_delegate,
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
base::OnceClosure on_finished_callback,
NetworkStateHandler* network_state_handler,
NetworkConnectionHandler* network_connection_handler,
......@@ -93,7 +93,7 @@ class CellularSetupImplTest : public testing::Test {
base::RunLoop run_loop;
cellular_setup_->StartActivation(
fake_activation_delegate->GenerateInterfacePtr(),
fake_activation_delegate->GenerateRemote(),
base::BindOnce(&CellularSetupImplTest::OnCarrierPortalHandlerReceived,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
......
......@@ -62,7 +62,7 @@ class CellularSetupServiceTest : public testing::Test {
// Make StartActivation() call and propagate it to the service.
cellular_setup_ptr_->StartActivation(
fake_activation_delegate->GenerateInterfacePtr(),
fake_activation_delegate->GenerateRemote(),
base::BindOnce(&CellularSetupServiceTest::OnStartActivationResult,
base::Unretained(this), run_loop.QuitClosure()));
cellular_setup_ptr_.FlushForTesting();
......@@ -153,7 +153,7 @@ class CellularSetupServiceTest : public testing::Test {
FakeCellularSetup* fake_cellular_setup() { return service_.get(); }
mojom::ActivationDelegatePtr& GetLastActivationDelegate() {
mojo::Remote<mojom::ActivationDelegate>& GetLastActivationDelegate() {
return fake_cellular_setup()
->start_activation_invocations()
.back()
......
......@@ -47,7 +47,7 @@ void OnNetworkConnectionError(
// static
std::unique_ptr<OtaActivator> OtaActivatorImpl::Factory::Create(
mojom::ActivationDelegatePtr activation_delegate,
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
base::OnceClosure on_finished_callback,
NetworkStateHandler* network_state_handler,
NetworkConnectionHandler* network_connection_handler,
......@@ -74,7 +74,7 @@ void OtaActivatorImpl::Factory::SetFactoryForTesting(Factory* test_factory) {
OtaActivatorImpl::Factory::~Factory() = default;
OtaActivatorImpl::OtaActivatorImpl(
mojom::ActivationDelegatePtr activation_delegate,
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
base::OnceClosure on_finished_callback,
NetworkStateHandler* network_state_handler,
NetworkConnectionHandler* network_connection_handler,
......@@ -151,7 +151,7 @@ void OtaActivatorImpl::StartActivation() {
// If |activation_delegate_| becomes disconnected, the activation request is
// considered canceled.
activation_delegate_.set_connection_error_handler(base::BindOnce(
activation_delegate_.set_disconnect_handler(base::BindOnce(
&OtaActivatorImpl::FinishActivationAttempt, base::Unretained(this),
mojom::ActivationResult::kFailedToActivate));
......
......@@ -15,6 +15,8 @@
#include "chromeos/network/network_state_handler_observer.h"
#include "chromeos/services/cellular_setup/ota_activator.h"
#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace base {
class DictionaryValue;
......@@ -48,7 +50,7 @@ class OtaActivatorImpl : public OtaActivator,
class Factory {
public:
static std::unique_ptr<OtaActivator> Create(
mojom::ActivationDelegatePtr activation_delegate,
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
base::OnceClosure on_finished_callback,
NetworkStateHandler* network_state_handler,
NetworkConnectionHandler* network_connection_handler,
......@@ -58,7 +60,7 @@ class OtaActivatorImpl : public OtaActivator,
static void SetFactoryForTesting(Factory* test_factory);
virtual ~Factory();
virtual std::unique_ptr<OtaActivator> BuildInstance(
mojom::ActivationDelegatePtr activation_delegate,
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
base::OnceClosure on_finished_callback,
NetworkStateHandler* network_state_handler,
NetworkConnectionHandler* network_connection_handler,
......@@ -81,7 +83,8 @@ class OtaActivatorImpl : public OtaActivator,
};
friend std::ostream& operator<<(std::ostream& stream, const State& state);
OtaActivatorImpl(mojom::ActivationDelegatePtr activation_delegate,
OtaActivatorImpl(
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
base::OnceClosure on_finished_callback,
NetworkStateHandler* network_state_handler,
NetworkConnectionHandler* network_connection_handler,
......@@ -117,7 +120,7 @@ class OtaActivatorImpl : public OtaActivator,
void FlushForTesting();
mojom::ActivationDelegatePtr activation_delegate_;
mojo::Remote<mojom::ActivationDelegate> activation_delegate_;
NetworkStateHandler* network_state_handler_;
NetworkConnectionHandler* network_connection_handler_;
NetworkActivationHandler* network_activation_handler_;
......
......@@ -61,7 +61,7 @@ class CellularSetupOtaActivatorImplTest : public testing::Test {
void BuildOtaActivator() {
auto test_task_runner = base::MakeRefCounted<base::TestSimpleTaskRunner>();
ota_activator_ = OtaActivatorImpl::Factory::Create(
fake_activation_delegate_->GenerateInterfacePtr(),
fake_activation_delegate_->GenerateRemote(),
base::BindOnce(&CellularSetupOtaActivatorImplTest::OnFinished,
base::Unretained(this)),
test_helper_.network_state_handler(),
......@@ -205,7 +205,9 @@ class CellularSetupOtaActivatorImplTest : public testing::Test {
EXPECT_TRUE(is_finished_);
}
void DisconnectDelegate() { fake_activation_delegate_->DisconnectBindings(); }
void DisconnectDelegate() {
fake_activation_delegate_->DisconnectReceivers();
}
bool is_finished() { return is_finished_; }
......
......@@ -12,14 +12,15 @@ FakeActivationDelegate::FakeActivationDelegate() = default;
FakeActivationDelegate::~FakeActivationDelegate() = default;
mojom::ActivationDelegatePtr FakeActivationDelegate::GenerateInterfacePtr() {
mojom::ActivationDelegatePtr interface_ptr;
bindings_.AddBinding(this, mojo::MakeRequest(&interface_ptr));
return interface_ptr;
mojo::PendingRemote<mojom::ActivationDelegate>
FakeActivationDelegate::GenerateRemote() {
mojo::PendingRemote<mojom::ActivationDelegate> remote;
receivers_.Add(this, remote.InitWithNewPipeAndPassReceiver());
return remote;
}
void FakeActivationDelegate::DisconnectBindings() {
bindings_.CloseAllBindings();
void FakeActivationDelegate::DisconnectReceivers() {
receivers_.Clear();
}
void FakeActivationDelegate::OnActivationStarted(
......
......@@ -9,7 +9,8 @@
#include "base/macros.h"
#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace chromeos {
......@@ -21,8 +22,8 @@ class FakeActivationDelegate : public mojom::ActivationDelegate {
FakeActivationDelegate();
~FakeActivationDelegate() override;
mojom::ActivationDelegatePtr GenerateInterfacePtr();
void DisconnectBindings();
mojo::PendingRemote<mojom::ActivationDelegate> GenerateRemote();
void DisconnectReceivers();
const std::vector<mojom::CellularMetadataPtr>& cellular_metadata_list()
const {
......@@ -42,7 +43,7 @@ class FakeActivationDelegate : public mojom::ActivationDelegate {
std::vector<mojom::CellularMetadataPtr> cellular_metadata_list_;
std::vector<mojom::ActivationResult> activation_results_;
mojo::BindingSet<mojom::ActivationDelegate> bindings_;
mojo::ReceiverSet<mojom::ActivationDelegate> receivers_;
DISALLOW_COPY_AND_ASSIGN(FakeActivationDelegate);
};
......
......@@ -13,7 +13,7 @@ namespace chromeos {
namespace cellular_setup {
FakeCellularSetup::StartActivationInvocation::StartActivationInvocation(
mojom::ActivationDelegatePtr activation_delegate,
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
StartActivationCallback callback)
: activation_delegate_(std::move(activation_delegate)),
callback_(std::move(callback)) {}
......@@ -37,7 +37,7 @@ FakeCellularSetup::FakeCellularSetup() = default;
FakeCellularSetup::~FakeCellularSetup() = default;
void FakeCellularSetup::StartActivation(
mojom::ActivationDelegatePtr activation_delegate,
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
StartActivationCallback callback) {
DCHECK(activation_delegate);
DCHECK(callback);
......
......@@ -11,6 +11,8 @@
#include "base/macros.h"
#include "chromeos/services/cellular_setup/cellular_setup_base.h"
#include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
......@@ -23,11 +25,12 @@ class FakeCellularSetup : public CellularSetupBase {
public:
class StartActivationInvocation {
public:
StartActivationInvocation(mojom::ActivationDelegatePtr activation_delegate,
StartActivationInvocation(
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
StartActivationCallback callback);
~StartActivationInvocation();
mojom::ActivationDelegatePtr& activation_delegate() {
mojo::Remote<mojom::ActivationDelegate>& activation_delegate() {
return activation_delegate_;
}
......@@ -37,7 +40,7 @@ class FakeCellularSetup : public CellularSetupBase {
FakeCarrierPortalHandler* ExecuteCallback();
private:
mojom::ActivationDelegatePtr activation_delegate_;
mojo::Remote<mojom::ActivationDelegate> activation_delegate_;
StartActivationCallback callback_;
// Null until ExecuteCallback() has been invoked.
......@@ -56,7 +59,8 @@ class FakeCellularSetup : public CellularSetupBase {
private:
// mojom::CellularSetup:
void StartActivation(mojom::ActivationDelegatePtr activation_delegate,
void StartActivation(
mojo::PendingRemote<mojom::ActivationDelegate> activation_delegate,
StartActivationCallback callback) override;
std::vector<std::unique_ptr<StartActivationInvocation>>
......
......@@ -82,6 +82,6 @@ interface ActivationDelegate {
interface CellularSetup {
// Entrypoint to the activation flow. If |delegate| becomes disconnected
// during the activation process, activation is cancelled.
StartActivation(ActivationDelegate delegate)
StartActivation(pending_remote<ActivationDelegate> delegate)
=> (pending_remote<CarrierPortalHandler> observer);
};
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