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