Commit bd9703f6 authored by Yue Li's avatar Yue Li Committed by Commit Bot

Merge Assistant preferences logic into AssistantState

Merge the current Assistant prefs controller logic into the
AssistantStateBase. Will also merge the logic of
VoiceInteractionController into this controller in the next change.

Bug: b/110211045
Test: Run existing tests
Change-Id: I1d3a8388fd66217baad44d7c7043ffd75830e42d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1727733
Commit-Queue: Yue Li <updowndota@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684455}
parent c8c12cbb
......@@ -238,8 +238,10 @@ void AssistantPageView::OnUiVisibilityChanged(
return;
}
const bool prefer_voice = assistant_view_delegate_->IsTabletMode() ||
assistant_view_delegate_->IsLaunchWithMicOpen();
const bool prefer_voice =
assistant_view_delegate_->IsTabletMode() ||
assistant_view_delegate_->GetState()->launch_with_mic_open().value_or(
false);
if (!ash::assistant::util::IsVoiceEntryPoint(entry_point.value(),
prefer_voice)) {
NotifyAccessibilityEvent(ax::mojom::Event::kAlert, true);
......
......@@ -119,8 +119,8 @@ void AssistantController::SendAssistantFeedback(
}
void AssistantController::StartSpeakerIdEnrollmentFlow() {
if (prefs_controller()->prefs()->GetInteger(
chromeos::assistant::prefs::kAssistantConsentStatus) ==
if (state()->consent_status().value_or(
chromeos::assistant::prefs::ConsentStatus::kUnknown) ==
chromeos::assistant::prefs::ConsentStatus::kActivityControlAccepted) {
// If activity control has been accepted, launch the enrollment flow.
setup_controller()->StartOnboarding(false /* relaunch */,
......
......@@ -115,6 +115,8 @@ class ASH_EXPORT AssistantController
void GetNavigableContentsFactory(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver);
AssistantStateBase* state() { return &assistant_prefs_controller_; }
AssistantAlarmTimerController* alarm_timer_controller() {
return &assistant_alarm_timer_controller_;
}
......@@ -131,10 +133,6 @@ class ASH_EXPORT AssistantController
return &assistant_notification_controller_;
}
AssistantPrefsController* prefs_controller() {
return &assistant_prefs_controller_;
}
AssistantScreenContextController* screen_context_controller() {
return &assistant_screen_context_controller_;
}
......
......@@ -701,8 +701,7 @@ void AssistantInteractionController::OnUiVisible(
assistant_controller_->ui_controller()->model()->visibility());
const bool launch_with_mic_open =
assistant_controller_->prefs_controller()->prefs()->GetBoolean(
chromeos::assistant::prefs::kAssistantLaunchWithMicOpen);
assistant_controller_->state()->launch_with_mic_open().value_or(false);
const bool prefer_voice = launch_with_mic_open || IsTabletMode();
// We don't explicitly start a new voice interaction if the entry point
......
......@@ -205,8 +205,7 @@ void AssistantNotificationController::SetQuietMode(bool enabled) {
void AssistantNotificationController::OnNotificationAdded(
const AssistantNotification* notification) {
// Do not show system notifications if the setting is disabled.
if (!assistant_controller_->prefs_controller()->prefs()->GetBoolean(
chromeos::assistant::prefs::kAssistantNotificationEnabled)) {
if (!assistant_controller_->state()->notification_enabled().value_or(true)) {
return;
}
......@@ -221,8 +220,7 @@ void AssistantNotificationController::OnNotificationAdded(
void AssistantNotificationController::OnNotificationUpdated(
const AssistantNotification* notification) {
// Do not show system notifications if the setting is disabled.
if (!assistant_controller_->prefs_controller()->prefs()->GetBoolean(
chromeos::assistant::prefs::kAssistantNotificationEnabled)) {
if (!assistant_controller_->state()->notification_enabled().value_or(true)) {
return;
}
......
......@@ -6,6 +6,8 @@
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/system/update/update_notification_controller.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_registry_simple.h"
......@@ -16,67 +18,92 @@ AssistantPrefsController::AssistantPrefsController()
AssistantPrefsController::~AssistantPrefsController() = default;
void AssistantPrefsController::AddObserver(AssistantPrefsObserver* observer) {
InitObserver(observer);
observers_.AddObserver(observer);
void AssistantPrefsController::InitializeObserver(
AssistantStateObserver* observer) {
if (consent_status_.has_value())
observer->OnAssistantConsentStatusChanged(consent_status_.value());
}
void AssistantPrefsController::RemoveObserver(
AssistantPrefsObserver* observer) {
observers_.RemoveObserver(observer);
}
void AssistantPrefsController::InitObserver(AssistantPrefsObserver* observer) {
PrefService* primary_user_prefs =
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
PrefService* active_prefs =
Shell::Get()->session_controller()->GetActivePrefService();
if (primary_user_prefs && primary_user_prefs == active_prefs) {
observer->OnAssistantConsentStatusUpdated(active_prefs->GetInteger(
chromeos::assistant::prefs::kAssistantConsentStatus));
}
}
PrefService* AssistantPrefsController::prefs() {
PrefService* primary_user_prefs =
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
PrefService* active_prefs =
Shell::Get()->session_controller()->GetActivePrefService();
DCHECK_EQ(primary_user_prefs, active_prefs);
return primary_user_prefs;
void AssistantPrefsController::UpdateState() {
UpdateConsentStatus();
UpdateHotwordAlwaysOn();
UpdateLaunchWithMicOpen();
UpdateNotificationEnabled();
}
void AssistantPrefsController::OnActiveUserPrefServiceChanged(
PrefService* pref_service) {
pref_change_registrar_.reset();
// If primary user is active, register pref change listeners.
// Skip for non-primary user prefs.
PrefService* primary_user_prefs =
Shell::Get()->session_controller()->GetPrimaryUserPrefService();
if (primary_user_prefs && primary_user_prefs == pref_service) {
for (auto& observer : observers_)
InitObserver(&observer);
if (!primary_user_prefs || primary_user_prefs != pref_service)
return;
// Register preference changes.
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(pref_service);
pref_change_registrar_->Add(
chromeos::assistant::prefs::kAssistantConsentStatus,
base::BindRepeating(&AssistantPrefsController::UpdateConsentStatus,
base::Unretained(this)));
pref_change_registrar_->Add(
chromeos::assistant::prefs::kAssistantHotwordAlwaysOn,
base::BindRepeating(&AssistantPrefsController::UpdateHotwordAlwaysOn,
base::Unretained(this)));
pref_change_registrar_->Add(
chromeos::assistant::prefs::kAssistantLaunchWithMicOpen,
base::BindRepeating(&AssistantPrefsController::UpdateLaunchWithMicOpen,
base::Unretained(this)));
pref_change_registrar_->Add(
chromeos::assistant::prefs::kAssistantNotificationEnabled,
base::BindRepeating(&AssistantPrefsController::UpdateNotificationEnabled,
base::Unretained(this)));
UpdateState();
}
void AssistantPrefsController::UpdateConsentStatus() {
auto consent_status = pref_change_registrar_->prefs()->GetInteger(
chromeos::assistant::prefs::kAssistantConsentStatus);
if (consent_status_.has_value() &&
consent_status_.value() == consent_status) {
return;
}
consent_status_ = consent_status;
for (auto& observer : observers_)
observer.OnAssistantConsentStatusChanged(consent_status_.value());
}
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(pref_service);
void AssistantPrefsController::UpdateHotwordAlwaysOn() {
auto hotword_always_on = pref_change_registrar_->prefs()->GetBoolean(
chromeos::assistant::prefs::kAssistantHotwordAlwaysOn);
if (hotword_always_on_.has_value() &&
hotword_always_on_.value() == hotword_always_on) {
return;
}
hotword_always_on_ = hotword_always_on;
}
pref_change_registrar_->Add(
chromeos::assistant::prefs::kAssistantConsentStatus,
base::BindRepeating(&AssistantPrefsController::NotifyConsentStatus,
base::Unretained(this)));
void AssistantPrefsController::UpdateLaunchWithMicOpen() {
auto launch_with_mic_open = pref_change_registrar_->prefs()->GetBoolean(
chromeos::assistant::prefs::kAssistantLaunchWithMicOpen);
if (launch_with_mic_open_.has_value() &&
launch_with_mic_open_.value() == launch_with_mic_open) {
return;
}
launch_with_mic_open_ = launch_with_mic_open;
}
void AssistantPrefsController::NotifyConsentStatus() {
for (auto& observer : observers_) {
observer.OnAssistantConsentStatusUpdated(
Shell::Get()
->session_controller()
->GetPrimaryUserPrefService()
->GetInteger(chromeos::assistant::prefs::kAssistantConsentStatus));
void AssistantPrefsController::UpdateNotificationEnabled() {
auto notification_enabled = pref_change_registrar_->prefs()->GetBoolean(
chromeos::assistant::prefs::kAssistantNotificationEnabled);
if (notification_enabled_.has_value() &&
notification_enabled_.value() == notification_enabled) {
return;
}
notification_enabled_ = notification_enabled;
}
} // namespace ash
......@@ -6,6 +6,7 @@
#define ASH_ASSISTANT_ASSISTANT_PREFS_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/public/cpp/assistant/assistant_state_base.h"
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
......@@ -14,43 +15,36 @@ class PrefChangeRegistrar;
namespace ash {
// A checked observer which receives Assistant prefs change.
class ASH_EXPORT AssistantPrefsObserver : public base::CheckedObserver {
public:
AssistantPrefsObserver() = default;
~AssistantPrefsObserver() override = default;
virtual void OnAssistantConsentStatusUpdated(int consent_status) {}
private:
DISALLOW_COPY_AND_ASSIGN(AssistantPrefsObserver);
};
class ASH_EXPORT AssistantPrefsController : public SessionObserver {
// Provide access of Assistant related preferences to clients in ash.
class ASH_EXPORT AssistantPrefsController : public SessionObserver,
public AssistantStateBase {
public:
AssistantPrefsController();
~AssistantPrefsController() override;
void AddObserver(AssistantPrefsObserver* observer);
void RemoveObserver(AssistantPrefsObserver* observer);
void InitObserver(AssistantPrefsObserver* observer);
PrefService* prefs();
// AssistantStateBase:
void InitializeObserver(AssistantStateObserver* observer) override;
private:
// Update pref cache and notify observers when primary user prefs becomes
// active.
void UpdateState();
// SessionObserver:
void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
// Called when the consent status is obtained from the pref service.
void NotifyConsentStatus();
// Called when the related preferences are obtained from the pref service.
void UpdateConsentStatus();
void UpdateHotwordAlwaysOn();
void UpdateLaunchWithMicOpen();
void UpdateNotificationEnabled();
// TODO(b/138679823): Move related logics into AssistantStateBase.
// Observes user profile prefs for the Assistant.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
ScopedSessionObserver session_observer_;
base::ObserverList<AssistantPrefsObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(AssistantPrefsController);
};
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "ash/assistant/assistant_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/macros.h"
......@@ -16,13 +17,13 @@
namespace ash {
class TestAssistantPrefsObserver : public AssistantPrefsObserver {
class TestAssistantPrefsObserver : public AssistantStateObserver {
public:
TestAssistantPrefsObserver() = default;
~TestAssistantPrefsObserver() override = default;
// AssistantPrefsObserver:
void OnAssistantConsentStatusUpdated(int consent_status) override {
void OnAssistantConsentStatusChanged(int consent_status) override {
consent_status_ = consent_status;
}
......@@ -46,7 +47,7 @@ class AssistantPrefsControllerTest : public AshTestBase {
AshTestBase::SetUp();
prefs_ = Shell::Get()->assistant_controller()->prefs_controller()->prefs();
prefs_ = Shell::Get()->session_controller()->GetPrimaryUserPrefService();
DCHECK(prefs_);
observer_ = std::make_unique<TestAssistantPrefsObserver>();
......@@ -72,15 +73,13 @@ TEST_F(AssistantPrefsControllerTest, InitObserver) {
// The observer class should get an instant notification about the current
// pref value.
Shell::Get()->assistant_controller()->prefs_controller()->AddObserver(
observer());
Shell::Get()->assistant_controller()->state()->AddObserver(observer());
EXPECT_EQ(chromeos::assistant::prefs::ConsentStatus::kActivityControlAccepted,
observer()->consent_status());
}
TEST_F(AssistantPrefsControllerTest, NotifyConsentStatus) {
Shell::Get()->assistant_controller()->prefs_controller()->AddObserver(
observer());
Shell::Get()->assistant_controller()->state()->AddObserver(observer());
prefs()->SetInteger(chromeos::assistant::prefs::kAssistantConsentStatus,
chromeos::assistant::prefs::ConsentStatus::kUnauthorized);
......
......@@ -58,8 +58,8 @@ void AssistantSetupController::OnDeepLinkReceived(
}
void AssistantSetupController::OnOptInButtonPressed() {
if (assistant_controller_->prefs_controller()->prefs()->GetInteger(
chromeos::assistant::prefs::kAssistantConsentStatus) ==
if (assistant_controller_->state()->consent_status().value_or(
chromeos::assistant::prefs::ConsentStatus::kUnknown) ==
chromeos::assistant::prefs::ConsentStatus::kUnauthorized) {
assistant_controller_->OpenUrl(assistant::util::CreateLocalizedGURL(
kGSuiteAdministratorInstructionsUrl));
......
......@@ -81,6 +81,16 @@ void AssistantViewDelegateImpl::RemoveNotificationModelObserver(
observer);
}
void AssistantViewDelegateImpl::AddStateObserver(
AssistantStateObserver* observer) {
assistant_controller_->state()->AddObserver(observer);
}
void AssistantViewDelegateImpl::RemoveStateObserver(
AssistantStateObserver* observer) {
assistant_controller_->state()->RemoveObserver(observer);
}
void AssistantViewDelegateImpl::AddUiModelObserver(
AssistantUiModelObserver* observer) {
assistant_controller_->ui_controller()->AddModelObserver(observer);
......@@ -91,16 +101,6 @@ void AssistantViewDelegateImpl::RemoveUiModelObserver(
assistant_controller_->ui_controller()->RemoveModelObserver(observer);
}
void AssistantViewDelegateImpl::AddAssistantPrefsObserver(
AssistantPrefsObserver* observer) {
assistant_controller_->prefs_controller()->AddObserver(observer);
}
void AssistantViewDelegateImpl::RemoveAssistantPrefsObserver(
AssistantPrefsObserver* observer) {
assistant_controller_->prefs_controller()->RemoveObserver(observer);
}
CaptionBarDelegate* AssistantViewDelegateImpl::GetCaptionBarDelegate() {
return assistant_controller_->ui_controller();
}
......@@ -111,9 +111,8 @@ void AssistantViewDelegateImpl::DownloadImage(
assistant_controller_->DownloadImage(url, std::move(callback));
}
int AssistantViewDelegateImpl::GetConsentStatus() const {
return assistant_controller_->prefs_controller()->prefs()->GetInteger(
chromeos::assistant::prefs::kAssistantConsentStatus);
AssistantStateBase* AssistantViewDelegateImpl::GetState() const {
return assistant_controller_->state();
}
::wm::CursorManager* AssistantViewDelegateImpl::GetCursorManager() {
......@@ -129,11 +128,6 @@ aura::Window* AssistantViewDelegateImpl::GetRootWindowForNewWindows() {
return Shell::Get()->GetRootWindowForNewWindows();
}
bool AssistantViewDelegateImpl::IsLaunchWithMicOpen() const {
return assistant_controller_->prefs_controller()->prefs()->GetBoolean(
chromeos::assistant::prefs::kAssistantLaunchWithMicOpen);
}
bool AssistantViewDelegateImpl::IsTabletMode() const {
return Shell::Get()->tablet_mode_controller()->InTabletMode();
}
......
......@@ -39,21 +39,20 @@ class AssistantViewDelegateImpl : public AssistantViewDelegate {
AssistantNotificationModelObserver* observer) override;
void RemoveNotificationModelObserver(
AssistantNotificationModelObserver* observer) override;
void AddStateObserver(AssistantStateObserver* observer) override;
void RemoveStateObserver(AssistantStateObserver* observer) override;
void AddUiModelObserver(AssistantUiModelObserver* observer) override;
void RemoveUiModelObserver(AssistantUiModelObserver* observer) override;
void AddAssistantPrefsObserver(AssistantPrefsObserver* observer) override;
void RemoveAssistantPrefsObserver(AssistantPrefsObserver* observer) override;
CaptionBarDelegate* GetCaptionBarDelegate() override;
void DownloadImage(
const GURL& url,
AssistantImageDownloader::DownloadCallback callback) override;
int GetConsentStatus() const override;
AssistantStateBase* GetState() const override;
::wm::CursorManager* GetCursorManager() override;
void GetNavigableContentsFactoryForView(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver)
override;
aura::Window* GetRootWindowForNewWindows() override;
bool IsLaunchWithMicOpen() const override;
bool IsTabletMode() const override;
void OnDialogPlateButtonPressed(AssistantButtonId id) override;
void OnDialogPlateContentsCommitted(const std::string& text) override;
......
......@@ -113,11 +113,9 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate {
virtual void AddUiModelObserver(AssistantUiModelObserver* observer) = 0;
virtual void RemoveUiModelObserver(AssistantUiModelObserver* observer) = 0;
// Adds/removes the Assistant prefs observer associated with the view
// delegate.
virtual void AddAssistantPrefsObserver(AssistantPrefsObserver* observer) = 0;
virtual void RemoveAssistantPrefsObserver(
AssistantPrefsObserver* observer) = 0;
// Adds/removes the state observer associated with the view delegate.
virtual void AddStateObserver(AssistantStateObserver* observer) = 0;
virtual void RemoveStateObserver(AssistantStateObserver* observer) = 0;
// Gets the caption bar delegate associated with the view delegate.
virtual CaptionBarDelegate* GetCaptionBarDelegate() = 0;
......@@ -129,8 +127,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate {
const GURL& url,
AssistantImageDownloader::DownloadCallback callback) = 0;
// Returns the status of the user's consent.
virtual int GetConsentStatus() const = 0;
virtual AssistantStateBase* GetState() const = 0;
// Returns the cursor_manager.
virtual ::wm::CursorManager* GetCursorManager() = 0;
......@@ -144,9 +141,6 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate {
// Returns the root window that newly created windows should be added to.
virtual aura::Window* GetRootWindowForNewWindows() = 0;
// Returns true if user prefers to start with voice interaction.
virtual bool IsLaunchWithMicOpen() const = 0;
// Returns true if in tablet mode.
virtual bool IsTabletMode() const = 0;
......
......@@ -45,11 +45,11 @@ AssistantFooterView::AssistantFooterView(AssistantViewDelegate* delegate)
&AssistantFooterView::OnAnimationEnded,
base::Unretained(this)))) {
InitLayout();
delegate_->AddAssistantPrefsObserver(this);
delegate_->AddStateObserver(this);
}
AssistantFooterView::~AssistantFooterView() {
delegate_->RemoveAssistantPrefsObserver(this);
delegate_->RemoveStateObserver(this);
}
const char* AssistantFooterView::GetClassName() const {
......@@ -69,7 +69,8 @@ void AssistantFooterView::InitLayout() {
// Initial view state is based on user consent state.
const bool consent_given =
delegate_->GetConsentStatus() ==
delegate_->GetState()->consent_status().value_or(
chromeos::assistant::prefs::ConsentStatus::kUnknown) ==
chromeos::assistant::prefs::ConsentStatus::kActivityControlAccepted;
// Suggestion container.
......@@ -97,7 +98,7 @@ void AssistantFooterView::InitLayout() {
AddChildView(opt_in_view_);
}
void AssistantFooterView::OnAssistantConsentStatusUpdated(int consent_status) {
void AssistantFooterView::OnAssistantConsentStatusChanged(int consent_status) {
using assistant::util::CreateLayerAnimationSequence;
using assistant::util::CreateOpacityElement;
using assistant::util::StartLayerAnimationSequence;
......@@ -152,7 +153,8 @@ void AssistantFooterView::OnAnimationStarted(
bool AssistantFooterView::OnAnimationEnded(
const ui::CallbackLayerAnimationObserver& observer) {
const bool consent_given =
delegate_->GetConsentStatus() ==
delegate_->GetState()->consent_status().value_or(
chromeos::assistant::prefs::ConsentStatus::kUnknown) ==
chromeos::assistant::prefs::ConsentStatus::kActivityControlAccepted;
// Only the view relevant to our consent state should process events.
......
......@@ -25,7 +25,7 @@ class SuggestionContainerView;
class COMPONENT_EXPORT(ASSISTANT_UI) AssistantFooterView
: public views::View,
public AssistantPrefsObserver {
public AssistantStateObserver {
public:
explicit AssistantFooterView(AssistantViewDelegate* delegate);
~AssistantFooterView() override;
......@@ -35,8 +35,8 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantFooterView
gfx::Size CalculatePreferredSize() const override;
int GetHeightForWidth(int width) const override;
// AssistantPrefsObserver:
void OnAssistantConsentStatusUpdated(int consent_status) override;
// AssistantStateObserver:
void OnAssistantConsentStatusChanged(int consent_status) override;
private:
void InitLayout();
......
......@@ -90,11 +90,11 @@ class AssistantOptInContainer : public views::Button {
AssistantOptInView::AssistantOptInView(AssistantViewDelegate* delegate)
: delegate_(delegate) {
InitLayout();
delegate_->AddAssistantPrefsObserver(this);
delegate_->AddStateObserver(this);
}
AssistantOptInView::~AssistantOptInView() {
delegate_->RemoveAssistantPrefsObserver(this);
delegate_->RemoveStateObserver(this);
}
const char* AssistantOptInView::GetClassName() const {
......@@ -114,7 +114,7 @@ void AssistantOptInView::ButtonPressed(views::Button* sender,
delegate_->OnOptInButtonPressed();
}
void AssistantOptInView::OnAssistantConsentStatusUpdated(int consent_status) {
void AssistantOptInView::OnAssistantConsentStatusChanged(int consent_status) {
UpdateLabel(consent_status);
}
......@@ -152,7 +152,8 @@ void AssistantOptInView::InitLayout() {
container_->AddChildView(label_);
container_->SetFocusForPlatform();
UpdateLabel(delegate_->GetConsentStatus());
UpdateLabel(delegate_->GetState()->consent_status().value_or(
chromeos::assistant::prefs::ConsentStatus::kUnknown));
}
void AssistantOptInView::UpdateLabel(int consent_status) {
......
......@@ -23,7 +23,7 @@ class AssistantViewDelegate;
class COMPONENT_EXPORT(ASSISTANT_UI) AssistantOptInView
: public views::View,
public views::ButtonListener,
public AssistantPrefsObserver {
public AssistantStateObserver {
public:
explicit AssistantOptInView(AssistantViewDelegate* delegate_);
~AssistantOptInView() override;
......@@ -36,8 +36,8 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantOptInView
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// AssistantPrefsObserver:
void OnAssistantConsentStatusUpdated(int consent_status) override;
// AssistantStateObserver:
void OnAssistantConsentStatusChanged(int consent_status) override;
private:
void InitLayout();
......
......@@ -44,4 +44,13 @@ std::string AssistantStateBase::ToString() const {
return result.str();
}
void AssistantStateBase::AddObserver(AssistantStateObserver* observer) {
observers_.AddObserver(observer);
InitializeObserver(observer);
}
void AssistantStateBase::RemoveObserver(AssistantStateObserver* observer) {
observers_.RemoveObserver(observer);
}
} // namespace ash
......@@ -13,6 +13,18 @@
namespace ash {
// A checked observer which receives Assistant state change.
class ASH_PUBLIC_EXPORT AssistantStateObserver : public base::CheckedObserver {
public:
AssistantStateObserver() = default;
~AssistantStateObserver() override = default;
virtual void OnAssistantConsentStatusChanged(int consent_status) {}
private:
DISALLOW_COPY_AND_ASSIGN(AssistantStateObserver);
};
// Plain data class that holds Assistant related prefs and states. This is
// shared by both the controller that controlls these values and client proxy
// that caches these values locally. Please do not use this object directly,
......@@ -31,6 +43,8 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
return settings_enabled_;
}
const base::Optional<int>& consent_status() const { return consent_status_; }
const base::Optional<bool>& context_enabled() const {
return context_enabled_;
}
......@@ -39,6 +53,18 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
return hotword_enabled_;
}
const base::Optional<bool>& hotword_always_on() const {
return hotword_always_on_;
}
const base::Optional<bool>& launch_with_mic_open() const {
return launch_with_mic_open_;
}
const base::Optional<bool>& notification_enabled() const {
return notification_enabled_;
}
const base::Optional<mojom::AssistantAllowedState>& allowed_state() const {
return allowed_state_;
}
......@@ -55,13 +81,21 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
std::string ToString() const;
void AddObserver(AssistantStateObserver* observer);
void RemoveObserver(AssistantStateObserver* observer);
virtual void InitializeObserver(AssistantStateObserver* observer) {}
protected:
base::Optional<mojom::VoiceInteractionState> voice_interaction_state_;
// TODO(b/138679823): Maybe remove Optional for preference values.
// Whether voice interaction is enabled in system settings. nullopt if the
// data is not available yet.
base::Optional<bool> settings_enabled_;
// The status of the user's consent. nullopt if the data is not available yet.
base::Optional<int> consent_status_;
// Whether screen context is enabled. nullopt if the data is not available
// yet.
base::Optional<bool> context_enabled_;
......@@ -69,6 +103,16 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
// Whether hotword listening is enabled.
base::Optional<bool> hotword_enabled_;
// Whether hotword listening is always on/only with power source. nullopt
// if the data is not available yet.
base::Optional<bool> hotword_always_on_;
// Whether the Assistant should launch with mic open;
base::Optional<bool> launch_with_mic_open_;
// Whether notification is enabled.
base::Optional<bool> notification_enabled_;
// Whether voice interaction feature is allowed or disallowed for what reason.
// nullopt if the data is not available yet.
base::Optional<mojom::AssistantAllowedState> allowed_state_;
......@@ -82,6 +126,8 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
// available yet.
base::Optional<bool> locked_full_screen_enabled_;
base::ObserverList<AssistantStateObserver> observers_;
private:
DISALLOW_COPY_AND_ASSIGN(AssistantStateBase);
};
......
......@@ -17,6 +17,7 @@
namespace ash {
// TODO(b/138679823): Merge this with AssistantPrefsController.
class ASH_PUBLIC_EXPORT VoiceInteractionController
: public mojom::VoiceInteractionController,
public AssistantStateBase {
......
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