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

Convert CarrierPortalHandler to new Mojo types

This CL converts CarrierPortalHandler to new Mojo types
using PendingRemote, ReceiverSet, and Remote.

Bug: 955171
Change-Id: I5ac9e2b0c40a7e0020af8cd2265bb64ece4b9c14
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1871878Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#708860}
parent 2811b95e
...@@ -36,7 +36,7 @@ void CellularSetupImpl::StartActivation( ...@@ -36,7 +36,7 @@ void CellularSetupImpl::StartActivation(
network_handler->network_connection_handler(), network_handler->network_connection_handler(),
network_handler->network_activation_handler()); network_handler->network_activation_handler());
std::move(callback).Run(ota_activator->GenerateInterfacePtr()); std::move(callback).Run(ota_activator->GenerateRemote());
// Store the OtaActivator instance in a map indexed by request ID; once the // Store the OtaActivator instance in a map indexed by request ID; once the
// attempt has finished, the map entry will be deleted in // attempt has finished, the map entry will be deleted in
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chromeos/services/cellular_setup/fake_ota_activator.h" #include "chromeos/services/cellular_setup/fake_ota_activator.h"
#include "chromeos/services/cellular_setup/ota_activator_impl.h" #include "chromeos/services/cellular_setup/ota_activator_impl.h"
#include "chromeos/services/cellular_setup/public/cpp/fake_activation_delegate.h" #include "chromeos/services/cellular_setup/public/cpp/fake_activation_delegate.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos { namespace chromeos {
...@@ -108,7 +109,7 @@ class CellularSetupImplTest : public testing::Test { ...@@ -108,7 +109,7 @@ class CellularSetupImplTest : public testing::Test {
private: private:
void OnCarrierPortalHandlerReceived( void OnCarrierPortalHandlerReceived(
base::OnceClosure quit_closure, base::OnceClosure quit_closure,
mojom::CarrierPortalHandlerPtr carrier_portal_handler) { mojo::PendingRemote<mojom::CarrierPortalHandler> carrier_portal_handler) {
++num_carrier_portal_handlers_received_; ++num_carrier_portal_handlers_received_;
std::move(quit_closure).Run(); std::move(quit_closure).Run();
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "chromeos/services/cellular_setup/public/cpp/fake_carrier_portal_handler.h" #include "chromeos/services/cellular_setup/public/cpp/fake_carrier_portal_handler.h"
#include "chromeos/services/cellular_setup/public/cpp/fake_cellular_setup.h" #include "chromeos/services/cellular_setup/public/cpp/fake_cellular_setup.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"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos { namespace chromeos {
...@@ -24,7 +26,8 @@ namespace cellular_setup { ...@@ -24,7 +26,8 @@ namespace cellular_setup {
namespace { namespace {
using CarrierPortalHandlerPair = using CarrierPortalHandlerPair =
std::pair<mojom::CarrierPortalHandlerPtr, FakeCarrierPortalHandler*>; std::pair<mojo::Remote<mojom::CarrierPortalHandler>,
FakeCarrierPortalHandler*>;
const char kTestPaymentUrl[] = "testPaymentUrl"; const char kTestPaymentUrl[] = "testPaymentUrl";
const char kTestPaymentPostData[] = "testPaymentPostData"; const char kTestPaymentPostData[] = "testPaymentPostData";
...@@ -48,7 +51,7 @@ class CellularSetupServiceTest : public testing::Test { ...@@ -48,7 +51,7 @@ class CellularSetupServiceTest : public testing::Test {
} }
// Calls StartActivation() and returns the fake CarrierPortalHandler and its // Calls StartActivation() and returns the fake CarrierPortalHandler and its
// associated InterfacePtr. // associated mojo::Remote<>.
CarrierPortalHandlerPair CallStartActivation( CarrierPortalHandlerPair CallStartActivation(
FakeActivationDelegate* fake_activation_delegate) { FakeActivationDelegate* fake_activation_delegate) {
std::vector<std::unique_ptr<FakeCellularSetup::StartActivationInvocation>>& std::vector<std::unique_ptr<FakeCellularSetup::StartActivationInvocation>>&
...@@ -73,9 +76,8 @@ class CellularSetupServiceTest : public testing::Test { ...@@ -73,9 +76,8 @@ class CellularSetupServiceTest : public testing::Test {
run_loop.RunUntilIdle(); run_loop.RunUntilIdle();
EXPECT_TRUE(last_carrier_portal_observer_); EXPECT_TRUE(last_carrier_portal_observer_);
CarrierPortalHandlerPair observer_pair = CarrierPortalHandlerPair observer_pair = std::make_pair(
std::make_pair(std::move(*last_carrier_portal_observer_), std::move(last_carrier_portal_observer_), fake_carrier_portal_observer);
fake_carrier_portal_observer);
last_carrier_portal_observer_.reset(); last_carrier_portal_observer_.reset();
return observer_pair; return observer_pair;
...@@ -141,11 +143,11 @@ class CellularSetupServiceTest : public testing::Test { ...@@ -141,11 +143,11 @@ class CellularSetupServiceTest : public testing::Test {
} }
private: private:
void OnStartActivationResult( void OnStartActivationResult(base::OnceClosure quit_closure,
base::OnceClosure quit_closure, mojo::PendingRemote<mojom::CarrierPortalHandler>
mojom::CarrierPortalHandlerPtr carrier_portal_observer) { carrier_portal_observer) {
EXPECT_FALSE(last_carrier_portal_observer_); EXPECT_FALSE(last_carrier_portal_observer_);
last_carrier_portal_observer_ = std::move(carrier_portal_observer); last_carrier_portal_observer_.Bind(std::move(carrier_portal_observer));
std::move(quit_closure).Run(); std::move(quit_closure).Run();
} }
...@@ -162,7 +164,7 @@ class CellularSetupServiceTest : public testing::Test { ...@@ -162,7 +164,7 @@ class CellularSetupServiceTest : public testing::Test {
std::unique_ptr<FakeCellularSetup> service_; std::unique_ptr<FakeCellularSetup> service_;
base::Optional<mojom::CarrierPortalHandlerPtr> last_carrier_portal_observer_; mojo::Remote<mojom::CarrierPortalHandler> last_carrier_portal_observer_;
mojom::CellularSetupPtr cellular_setup_ptr_; mojom::CellularSetupPtr cellular_setup_ptr_;
......
...@@ -11,17 +11,15 @@ namespace chromeos { ...@@ -11,17 +11,15 @@ namespace chromeos {
namespace cellular_setup { namespace cellular_setup {
OtaActivator::OtaActivator(base::OnceClosure on_finished_callback) OtaActivator::OtaActivator(base::OnceClosure on_finished_callback)
: on_finished_callback_(std::move(on_finished_callback)), binding_(this) {} : on_finished_callback_(std::move(on_finished_callback)) {}
OtaActivator::~OtaActivator() = default; OtaActivator::~OtaActivator() = default;
mojom::CarrierPortalHandlerPtr OtaActivator::GenerateInterfacePtr() { mojo::PendingRemote<mojom::CarrierPortalHandler>
// Only one InterfacePtr should be created per instance. OtaActivator::GenerateRemote() {
DCHECK(!binding_); // Only one mojo::PendingRemote<> should be created per instance.
DCHECK(!receiver_.is_bound());
mojom::CarrierPortalHandlerPtr interface_ptr; return receiver_.BindNewPipeAndPassRemote();
binding_.Bind(mojo::MakeRequest(&interface_ptr));
return interface_ptr;
} }
void OtaActivator::InvokeOnFinishedCallback() { void OtaActivator::InvokeOnFinishedCallback() {
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "base/callback.h" #include "base/callback.h"
#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.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace chromeos { namespace chromeos {
...@@ -23,10 +24,10 @@ class OtaActivator : public mojom::CarrierPortalHandler { ...@@ -23,10 +24,10 @@ class OtaActivator : public mojom::CarrierPortalHandler {
public: public:
~OtaActivator() override; ~OtaActivator() override;
// Generates an InterfacePtr bound to this instance. Only one InterfacePtr may // Generates a mojo::PendingRemote<> bound to this instance. Only one
// be bound to a single OtaActivator instance, so this function can only be // mojo::PendingRemote<> may be bound to a single OtaActivator instance, so
// called once. // this function can only be called once.
mojom::CarrierPortalHandlerPtr GenerateInterfacePtr(); mojo::PendingRemote<mojom::CarrierPortalHandler> GenerateRemote();
protected: protected:
explicit OtaActivator(base::OnceClosure on_finished_callback); explicit OtaActivator(base::OnceClosure on_finished_callback);
...@@ -34,7 +35,7 @@ class OtaActivator : public mojom::CarrierPortalHandler { ...@@ -34,7 +35,7 @@ class OtaActivator : public mojom::CarrierPortalHandler {
void InvokeOnFinishedCallback(); void InvokeOnFinishedCallback();
base::OnceClosure on_finished_callback_; base::OnceClosure on_finished_callback_;
mojo::Binding<mojom::CarrierPortalHandler> binding_; mojo::Receiver<mojom::CarrierPortalHandler> receiver_{this};
DISALLOW_COPY_AND_ASSIGN(OtaActivator); DISALLOW_COPY_AND_ASSIGN(OtaActivator);
}; };
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_test_helper.h" #include "chromeos/network/network_state_test_helper.h"
#include "chromeos/services/cellular_setup/public/cpp/fake_activation_delegate.h" #include "chromeos/services/cellular_setup/public/cpp/fake_activation_delegate.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h" #include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
...@@ -67,7 +68,7 @@ class CellularSetupOtaActivatorImplTest : public testing::Test { ...@@ -67,7 +68,7 @@ class CellularSetupOtaActivatorImplTest : public testing::Test {
fake_network_connection_handler_.get(), fake_network_connection_handler_.get(),
fake_network_activation_handler_.get(), test_task_runner); fake_network_activation_handler_.get(), test_task_runner);
test_task_runner->RunUntilIdle(); test_task_runner->RunUntilIdle();
carrier_portal_handler_ptr_ = ota_activator_->GenerateInterfacePtr(); carrier_portal_handler_remote_.Bind(ota_activator_->GenerateRemote());
} }
void AddCellularDevice(bool has_valid_sim) { void AddCellularDevice(bool has_valid_sim) {
...@@ -159,9 +160,9 @@ class CellularSetupOtaActivatorImplTest : public testing::Test { ...@@ -159,9 +160,9 @@ class CellularSetupOtaActivatorImplTest : public testing::Test {
void UpdateCarrierPortalState( void UpdateCarrierPortalState(
mojom::CarrierPortalStatus carrier_portal_status) { mojom::CarrierPortalStatus carrier_portal_status) {
carrier_portal_handler_ptr_->OnCarrierPortalStatusChange( carrier_portal_handler_remote_->OnCarrierPortalStatusChange(
carrier_portal_status); carrier_portal_status);
carrier_portal_handler_ptr_.FlushForTesting(); carrier_portal_handler_remote_.FlushForTesting();
} }
void ConnectCellularNetwork() { void ConnectCellularNetwork() {
...@@ -224,7 +225,7 @@ class CellularSetupOtaActivatorImplTest : public testing::Test { ...@@ -224,7 +225,7 @@ class CellularSetupOtaActivatorImplTest : public testing::Test {
fake_network_activation_handler_; fake_network_activation_handler_;
std::unique_ptr<OtaActivator> ota_activator_; std::unique_ptr<OtaActivator> ota_activator_;
mojom::CarrierPortalHandlerPtr carrier_portal_handler_ptr_; mojo::Remote<mojom::CarrierPortalHandler> carrier_portal_handler_remote_;
bool is_finished_ = false; bool is_finished_ = false;
......
...@@ -12,11 +12,11 @@ FakeCarrierPortalHandler::FakeCarrierPortalHandler() = default; ...@@ -12,11 +12,11 @@ FakeCarrierPortalHandler::FakeCarrierPortalHandler() = default;
FakeCarrierPortalHandler::~FakeCarrierPortalHandler() = default; FakeCarrierPortalHandler::~FakeCarrierPortalHandler() = default;
mojom::CarrierPortalHandlerPtr mojo::PendingRemote<mojom::CarrierPortalHandler>
FakeCarrierPortalHandler::GenerateInterfacePtr() { FakeCarrierPortalHandler::GenerateRemote() {
mojom::CarrierPortalHandlerPtr interface_ptr; mojo::PendingRemote<mojom::CarrierPortalHandler> remote;
bindings_.AddBinding(this, mojo::MakeRequest(&interface_ptr)); receivers_.Add(this, remote.InitWithNewPipeAndPassReceiver());
return interface_ptr; return remote;
} }
void FakeCarrierPortalHandler::OnCarrierPortalStatusChange( void FakeCarrierPortalHandler::OnCarrierPortalStatusChange(
......
...@@ -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,7 +22,7 @@ class FakeCarrierPortalHandler : public mojom::CarrierPortalHandler { ...@@ -21,7 +22,7 @@ class FakeCarrierPortalHandler : public mojom::CarrierPortalHandler {
FakeCarrierPortalHandler(); FakeCarrierPortalHandler();
~FakeCarrierPortalHandler() override; ~FakeCarrierPortalHandler() override;
mojom::CarrierPortalHandlerPtr GenerateInterfacePtr(); mojo::PendingRemote<mojom::CarrierPortalHandler> GenerateRemote();
const std::vector<mojom::CarrierPortalStatus>& status_updates() const { const std::vector<mojom::CarrierPortalStatus>& status_updates() const {
return status_updates_; return status_updates_;
...@@ -33,7 +34,7 @@ class FakeCarrierPortalHandler : public mojom::CarrierPortalHandler { ...@@ -33,7 +34,7 @@ class FakeCarrierPortalHandler : public mojom::CarrierPortalHandler {
private: private:
std::vector<mojom::CarrierPortalStatus> status_updates_; std::vector<mojom::CarrierPortalStatus> status_updates_;
mojo::BindingSet<mojom::CarrierPortalHandler> bindings_; mojo::ReceiverSet<mojom::CarrierPortalHandler> receivers_;
DISALLOW_COPY_AND_ASSIGN(FakeCarrierPortalHandler); DISALLOW_COPY_AND_ASSIGN(FakeCarrierPortalHandler);
}; };
......
...@@ -27,8 +27,7 @@ FakeCellularSetup::StartActivationInvocation::ExecuteCallback() { ...@@ -27,8 +27,7 @@ FakeCellularSetup::StartActivationInvocation::ExecuteCallback() {
DCHECK(!fake_carrier_portal_observer_); DCHECK(!fake_carrier_portal_observer_);
fake_carrier_portal_observer_ = std::make_unique<FakeCarrierPortalHandler>(); fake_carrier_portal_observer_ = std::make_unique<FakeCarrierPortalHandler>();
std::move(callback_).Run( std::move(callback_).Run(fake_carrier_portal_observer_->GenerateRemote());
fake_carrier_portal_observer_->GenerateInterfacePtr());
return fake_carrier_portal_observer_.get(); return fake_carrier_portal_observer_.get();
} }
......
...@@ -83,5 +83,5 @@ interface CellularSetup { ...@@ -83,5 +83,5 @@ 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(ActivationDelegate delegate)
=> (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