Commit 59429ce2 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Migrate assistant_state_controller.mojom to the new Mojo types

Convert the implementation and all users of the
ash::mojom::AssistantStateObserver and AssistantStateController
interfaces.

Bug: 955171
Change-Id: I8af0d30eb182849b5feea16bdb199a1fe6856781
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790444
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695965}
parent 9063d39b
......@@ -362,7 +362,7 @@ void AssistantController::BindScreenContextController(
void AssistantController::BindStateController(
mojo::PendingReceiver<mojom::AssistantStateController> receiver) {
assistant_state_controller_.BindRequest(std::move(receiver));
assistant_state_controller_.BindReceiver(std::move(receiver));
}
void AssistantController::BindVolumeControl(
......
......@@ -6,6 +6,13 @@
#include <ostream>
#include <sstream>
#include <utility>
#include "ash/public/mojom/assistant_state_controller.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
namespace ash {
namespace {
......@@ -29,9 +36,9 @@ AssistantState::~AssistantState() {
g_assistant_state = nullptr;
}
void AssistantState::BindRequest(
mojom::AssistantStateControllerRequest request) {
bindings_.AddBinding(this, std::move(request));
void AssistantState::BindReceiver(
mojo::PendingReceiver<mojom::AssistantStateController> receiver) {
receivers_.Add(this, std::move(receiver));
}
void AssistantState::NotifyStatusChanged(mojom::AssistantState state) {
......@@ -39,8 +46,8 @@ void AssistantState::NotifyStatusChanged(mojom::AssistantState state) {
return;
UpdateAssistantStatus(state);
remote_observers_.ForAllPtrs(
[state](auto* observer) { observer->OnAssistantStatusChanged(state); });
for (auto& observer : remote_observers_)
observer->OnAssistantStatusChanged(state);
}
void AssistantState::NotifyFeatureAllowed(mojom::AssistantAllowedState state) {
......@@ -48,9 +55,8 @@ void AssistantState::NotifyFeatureAllowed(mojom::AssistantAllowedState state) {
return;
UpdateFeatureAllowedState(state);
remote_observers_.ForAllPtrs([state](auto* observer) {
for (auto& observer : remote_observers_)
observer->OnAssistantFeatureAllowedChanged(state);
});
}
void AssistantState::NotifyLocaleChanged(const std::string& locale) {
......@@ -58,8 +64,8 @@ void AssistantState::NotifyLocaleChanged(const std::string& locale) {
return;
UpdateLocale(locale);
remote_observers_.ForAllPtrs(
[locale](auto* observer) { observer->OnLocaleChanged(locale); });
for (auto& observer : remote_observers_)
observer->OnLocaleChanged(locale);
}
void AssistantState::NotifyArcPlayStoreEnabledChanged(bool enabled) {
......@@ -67,9 +73,8 @@ void AssistantState::NotifyArcPlayStoreEnabledChanged(bool enabled) {
return;
UpdateArcPlayStoreEnabled(enabled);
remote_observers_.ForAllPtrs([enabled](auto* observer) {
for (auto& observer : remote_observers_)
observer->OnArcPlayStoreEnabledChanged(enabled);
});
}
void AssistantState::NotifyLockedFullScreenStateChanged(bool enabled) {
......@@ -77,16 +82,17 @@ void AssistantState::NotifyLockedFullScreenStateChanged(bool enabled) {
return;
UpdateLockedFullScreenState(enabled);
remote_observers_.ForAllPtrs([enabled](auto* observer) {
for (auto& observer : remote_observers_)
observer->OnLockedFullScreenStateChanged(enabled);
});
}
void AssistantState::AddMojomObserver(
mojom::AssistantStateObserverPtr observer) {
auto* observer_ptr = observer.get();
remote_observers_.AddPtr(std::move(observer));
InitializeObserverMojom(observer_ptr);
mojo::PendingRemote<mojom::AssistantStateObserver> pending_observer) {
auto remote =
mojo::Remote<mojom::AssistantStateObserver>(std::move(pending_observer));
mojom::AssistantStateObserver* observer = remote.get();
remote_observers_.Add(std::move(remote));
InitializeObserverMojom(observer);
}
} // namespace ash
......@@ -10,8 +10,10 @@
#include "ash/public/cpp/assistant/assistant_state_base.h"
#include "ash/public/mojom/assistant_state_controller.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
namespace ash {
......@@ -25,7 +27,8 @@ class ASH_PUBLIC_EXPORT AssistantState
AssistantState();
~AssistantState() override;
void BindRequest(mojom::AssistantStateControllerRequest request);
void BindReceiver(
mojo::PendingReceiver<mojom::AssistantStateController> receiver);
void NotifyStatusChanged(mojom::AssistantState state);
void NotifyFeatureAllowed(mojom::AssistantAllowedState state);
void NotifyLocaleChanged(const std::string& locale);
......@@ -33,12 +36,13 @@ class ASH_PUBLIC_EXPORT AssistantState
void NotifyLockedFullScreenStateChanged(bool enabled);
// ash::mojom::AssistantStateController:
void AddMojomObserver(mojom::AssistantStateObserverPtr observer) override;
void AddMojomObserver(mojo::PendingRemote<mojom::AssistantStateObserver>
pending_observer) override;
private:
mojo::BindingSet<mojom::AssistantStateController> bindings_;
mojo::ReceiverSet<mojom::AssistantStateController> receivers_;
mojo::InterfacePtrSet<mojom::AssistantStateObserver> remote_observers_;
mojo::RemoteSet<mojom::AssistantStateObserver> remote_observers_;
DISALLOW_COPY_AND_ASSIGN(AssistantState);
};
......
......@@ -62,5 +62,5 @@ interface AssistantStateObserver {
// which notifies changes of Assistant status and settings.
interface AssistantStateController {
// Add an observer.
AddMojomObserver(AssistantStateObserver observer);
AddMojomObserver(pending_remote<AssistantStateObserver> observer);
};
......@@ -7,14 +7,16 @@
#include <algorithm>
#include <utility>
#include "ash/public/mojom/assistant_state_controller.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/service_manager/public/cpp/connector.h"
namespace chromeos {
namespace assistant {
AssistantStateProxy::AssistantStateProxy()
: assistant_state_observer_binding_(this),
pref_connection_delegate_(std::make_unique<PrefConnectionDelegate>()) {}
: pref_connection_delegate_(std::make_unique<PrefConnectionDelegate>()) {}
AssistantStateProxy::~AssistantStateProxy() {
// Reset pref change registar.
......@@ -28,9 +30,10 @@ void AssistantStateProxy::Init(mojom::ClientProxy* client) {
remote_controller.InitWithNewPipeAndPassReceiver());
assistant_state_controller_.Bind(std::move(remote_controller));
ash::mojom::AssistantStateObserverPtr ptr;
assistant_state_observer_binding_.Bind(mojo::MakeRequest(&ptr));
assistant_state_controller_->AddMojomObserver(std::move(ptr));
mojo::PendingRemote<ash::mojom::AssistantStateObserver> observer;
assistant_state_observer_receiver_.Bind(
observer.InitWithNewPipeAndPassReceiver());
assistant_state_controller_->AddMojomObserver(std::move(observer));
// Connect to pref service.
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
......
......@@ -15,8 +15,8 @@
#include "base/observer_list.h"
#include "chromeos/services/assistant/pref_connection_delegate.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
namespace assistant {
......@@ -49,9 +49,10 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AssistantStateProxy
void OnPrefServiceConnected(std::unique_ptr<::PrefService> pref_service);
ash::mojom::AssistantStateControllerPtr assistant_state_controller_;
mojo::Binding<ash::mojom::AssistantStateObserver>
assistant_state_observer_binding_;
mojo::Remote<ash::mojom::AssistantStateController>
assistant_state_controller_;
mojo::Receiver<ash::mojom::AssistantStateObserver>
assistant_state_observer_receiver_{this};
std::unique_ptr<PrefService> pref_service_;
......
......@@ -144,7 +144,7 @@ class FakeAssistantClient : public FakeClient {
void RequestAssistantStateController(
mojo::PendingReceiver<ash::mojom::AssistantStateController> receiver)
override {
assistant_state_->BindRequest(std::move(receiver));
assistant_state_->BindReceiver(std::move(receiver));
}
ash::AssistantState* const assistant_state_;
......
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