Commit fbcb7a30 authored by David Black's avatar David Black Committed by Commit Bot

Add onboarding mode to Assistant state.

Onboarding mode will be wired up to the feature in a follow up CL.

Bug: b:157510970
Change-Id: Ifec0007db64361b00c2cb3451cc579a1aa884431
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252926
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarJeroen Dhollander <jeroendh@google.com>
Cr-Commit-Position: refs/heads/master@{#784220}
parent 5708ce2d
...@@ -9,24 +9,49 @@ ...@@ -9,24 +9,49 @@
#include "ash/public/cpp/accelerators.h" #include "ash/public/cpp/accelerators.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece_forward.h" #include "base/strings/string_piece_forward.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
namespace ash { namespace ash {
namespace { namespace {
using chromeos::assistant::AssistantOnboardingMode;
#define PRINT_VALUE(value) PrintValue(&result, #value, value())
template <typename T, std::enable_if_t<std::is_enum<T>::value>* = nullptr>
void PrintValue(std::stringstream* result, const base::Optional<T>& value) {
*result << base::NumberToString(static_cast<int>(value.value()));
}
template <typename T, std::enable_if_t<!std::is_enum<T>::value>* = nullptr>
void PrintValue(std::stringstream* result, const base::Optional<T>& value) {
*result << value.value();
}
template <typename T> template <typename T>
void PrintValue(std::stringstream* result, void PrintValue(std::stringstream* result,
const std::string& name, const std::string& name,
const base::Optional<T>& value) { const base::Optional<T>& value) {
*result << std::endl << " " << name << ": "; *result << std::endl << " " << name << ": ";
if (value.has_value()) if (value.has_value())
*result << value.value(); PrintValue(result, value);
else else
*result << ("(no value)"); *result << ("(no value)");
} }
#define PRINT_VALUE(value) PrintValue(&result, #value, value()) AssistantOnboardingMode ToAssistantOnboardingMode(
const std::string& onboarding_mode) {
if (onboarding_mode == "Education")
return AssistantOnboardingMode::kEducation;
else if (onboarding_mode != "Default")
NOTREACHED();
return AssistantOnboardingMode::kDefault;
}
} // namespace } // namespace
AssistantStateBase::AssistantStateBase() = default; AssistantStateBase::AssistantStateBase() = default;
...@@ -38,7 +63,7 @@ AssistantStateBase::~AssistantStateBase() { ...@@ -38,7 +63,7 @@ AssistantStateBase::~AssistantStateBase() {
std::string AssistantStateBase::ToString() const { std::string AssistantStateBase::ToString() const {
std::stringstream result; std::stringstream result;
result << "AssistantStatus:"; result << "AssistantStatus: ";
result << assistant_status_; result << assistant_status_;
PRINT_VALUE(settings_enabled); PRINT_VALUE(settings_enabled);
PRINT_VALUE(context_enabled); PRINT_VALUE(context_enabled);
...@@ -47,6 +72,7 @@ std::string AssistantStateBase::ToString() const { ...@@ -47,6 +72,7 @@ std::string AssistantStateBase::ToString() const {
PRINT_VALUE(locale); PRINT_VALUE(locale);
PRINT_VALUE(arc_play_store_enabled); PRINT_VALUE(arc_play_store_enabled);
PRINT_VALUE(locked_full_screen_enabled); PRINT_VALUE(locked_full_screen_enabled);
PRINT_VALUE(onboarding_mode);
return result.str(); return result.str();
} }
...@@ -96,6 +122,10 @@ void AssistantStateBase::RegisterPrefChanges(PrefService* pref_service) { ...@@ -96,6 +122,10 @@ void AssistantStateBase::RegisterPrefChanges(PrefService* pref_service) {
chromeos::assistant::prefs::kAssistantNotificationEnabled, chromeos::assistant::prefs::kAssistantNotificationEnabled,
base::BindRepeating(&AssistantStateBase::UpdateNotificationEnabled, base::BindRepeating(&AssistantStateBase::UpdateNotificationEnabled,
base::Unretained(this))); base::Unretained(this)));
pref_change_registrar_->Add(
chromeos::assistant::prefs::kAssistantOnboardingMode,
base::BindRepeating(&AssistantStateBase::UpdateOnboardingMode,
base::Unretained(this)));
pref_change_registrar_->Add( pref_change_registrar_->Add(
chromeos::assistant::prefs::kAssistantQuickAnswersEnabled, chromeos::assistant::prefs::kAssistantQuickAnswersEnabled,
base::BindRepeating(&AssistantStateBase::UpdateQuickAnswersEnabled, base::BindRepeating(&AssistantStateBase::UpdateQuickAnswersEnabled,
...@@ -108,6 +138,7 @@ void AssistantStateBase::RegisterPrefChanges(PrefService* pref_service) { ...@@ -108,6 +138,7 @@ void AssistantStateBase::RegisterPrefChanges(PrefService* pref_service) {
UpdateHotwordEnabled(); UpdateHotwordEnabled();
UpdateLaunchWithMicOpen(); UpdateLaunchWithMicOpen();
UpdateNotificationEnabled(); UpdateNotificationEnabled();
UpdateOnboardingMode();
UpdateQuickAnswersEnabled(); UpdateQuickAnswersEnabled();
} }
...@@ -133,6 +164,8 @@ void AssistantStateBase::InitializeObserver(AssistantStateObserver* observer) { ...@@ -133,6 +164,8 @@ void AssistantStateBase::InitializeObserver(AssistantStateObserver* observer) {
observer->OnAssistantLaunchWithMicOpen(launch_with_mic_open_.value()); observer->OnAssistantLaunchWithMicOpen(launch_with_mic_open_.value());
if (notification_enabled_.has_value()) if (notification_enabled_.has_value())
observer->OnAssistantNotificationEnabled(notification_enabled_.value()); observer->OnAssistantNotificationEnabled(notification_enabled_.value());
if (onboarding_mode_.has_value())
observer->OnAssistantOnboardingModeChanged(onboarding_mode_.value());
if (quick_answers_enabled_.has_value()) if (quick_answers_enabled_.has_value())
observer->OnAssistantQuickAnswersEnabled(quick_answers_enabled_.value()); observer->OnAssistantQuickAnswersEnabled(quick_answers_enabled_.value());
...@@ -229,6 +262,19 @@ void AssistantStateBase::UpdateNotificationEnabled() { ...@@ -229,6 +262,19 @@ void AssistantStateBase::UpdateNotificationEnabled() {
observer.OnAssistantNotificationEnabled(notification_enabled_.value()); observer.OnAssistantNotificationEnabled(notification_enabled_.value());
} }
void AssistantStateBase::UpdateOnboardingMode() {
AssistantOnboardingMode onboarding_mode =
ToAssistantOnboardingMode(pref_change_registrar_->prefs()->GetString(
chromeos::assistant::prefs::kAssistantOnboardingMode));
if (onboarding_mode_ == onboarding_mode)
return;
onboarding_mode_ = onboarding_mode;
for (auto& observer : observers_)
observer.OnAssistantOnboardingModeChanged(onboarding_mode_.value());
}
void AssistantStateBase::UpdateAssistantStatus( void AssistantStateBase::UpdateAssistantStatus(
chromeos::assistant::AssistantStatus status) { chromeos::assistant::AssistantStatus status) {
assistant_status_ = status; assistant_status_ = status;
......
...@@ -34,6 +34,8 @@ class ASH_PUBLIC_EXPORT AssistantStateObserver : public base::CheckedObserver { ...@@ -34,6 +34,8 @@ class ASH_PUBLIC_EXPORT AssistantStateObserver : public base::CheckedObserver {
virtual void OnAssistantHotwordEnabled(bool enabled) {} virtual void OnAssistantHotwordEnabled(bool enabled) {}
virtual void OnAssistantLaunchWithMicOpen(bool launch_with_mic_open) {} virtual void OnAssistantLaunchWithMicOpen(bool launch_with_mic_open) {}
virtual void OnAssistantNotificationEnabled(bool notification_enabled) {} virtual void OnAssistantNotificationEnabled(bool notification_enabled) {}
virtual void OnAssistantOnboardingModeChanged(
chromeos::assistant::AssistantOnboardingMode onboarding_mode) {}
virtual void OnAssistantStateDestroyed() {} virtual void OnAssistantStateDestroyed() {}
virtual void OnAssistantQuickAnswersEnabled(bool quick_answers_enabled) {} virtual void OnAssistantQuickAnswersEnabled(bool quick_answers_enabled) {}
virtual void OnAssistantStatusChanged( virtual void OnAssistantStatusChanged(
...@@ -88,6 +90,11 @@ class ASH_PUBLIC_EXPORT AssistantStateBase { ...@@ -88,6 +90,11 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
return notification_enabled_; return notification_enabled_;
} }
const base::Optional<chromeos::assistant::AssistantOnboardingMode>&
onboarding_mode() const {
return onboarding_mode_;
}
const base::Optional<chromeos::assistant::AssistantAllowedState>& const base::Optional<chromeos::assistant::AssistantAllowedState>&
allowed_state() const { allowed_state() const {
return allowed_state_; return allowed_state_;
...@@ -123,6 +130,7 @@ class ASH_PUBLIC_EXPORT AssistantStateBase { ...@@ -123,6 +130,7 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
void UpdateHotwordEnabled(); void UpdateHotwordEnabled();
void UpdateLaunchWithMicOpen(); void UpdateLaunchWithMicOpen();
void UpdateNotificationEnabled(); void UpdateNotificationEnabled();
void UpdateOnboardingMode();
void UpdateQuickAnswersEnabled(); void UpdateQuickAnswersEnabled();
// Called when new values of the listened states are received. // Called when new values of the listened states are received.
...@@ -161,6 +169,9 @@ class ASH_PUBLIC_EXPORT AssistantStateBase { ...@@ -161,6 +169,9 @@ class ASH_PUBLIC_EXPORT AssistantStateBase {
// Whether notification is enabled. // Whether notification is enabled.
base::Optional<bool> notification_enabled_; base::Optional<bool> notification_enabled_;
// The mode for the Assistant onboarding experience.
base::Optional<chromeos::assistant::AssistantOnboardingMode> onboarding_mode_;
// Whether the Assistant feature is allowed or disallowed for what reason. // Whether the Assistant feature is allowed or disallowed for what reason.
// nullopt if the data is not available yet. // nullopt if the data is not available yet.
base::Optional<chromeos::assistant::AssistantAllowedState> allowed_state_; base::Optional<chromeos::assistant::AssistantAllowedState> allowed_state_;
......
...@@ -42,6 +42,9 @@ enum AssistantAllowedState { ...@@ -42,6 +42,9 @@ enum AssistantAllowedState {
MAX_VALUE = DISALLOWED_BY_KIOSK_MODE, MAX_VALUE = DISALLOWED_BY_KIOSK_MODE,
}; };
// The mode of the Assistant onboarding experience.
enum class AssistantOnboardingMode { kDefault, kEducation };
// Enumeration of possible Assistant query sources. These values are persisted // Enumeration of possible Assistant query sources. These values are persisted
// to logs. Entries should not be renumbered and numeric values should never // to logs. Entries should not be renumbered and numeric values should never
// be reused. Append new values to the end. // be reused. Append new values to the end.
......
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