#include "ash/user_education/user_education_tutorial_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/user_education/user_education_delegate.h"
#include "ash/user_education/user_education_private_api_key.h"
#include "ash/user_education/user_education_util.h"
#include "base/check_op.h"
#include "components/account_id/account_id.h"
#include "components/user_education/common/tutorial/tutorial_description.h"
namespace ash {
namespace {
UserEducationTutorialController* g_instance = nullptr;
AccountId GetActiveAccountId() {
return Shell::Get()->session_controller()->GetActiveAccountId();
}
}
UserEducationTutorialController::UserEducationTutorialController(
UserEducationDelegate* delegate)
: delegate_(std::move(delegate)) {
CHECK_EQ(g_instance, nullptr);
g_instance = this;
}
UserEducationTutorialController::~UserEducationTutorialController() {
CHECK_EQ(g_instance, this);
g_instance = nullptr;
}
UserEducationTutorialController* UserEducationTutorialController::Get() {
return g_instance;
}
bool UserEducationTutorialController::IsTutorialRegistered(
TutorialId tutorial_id) const {
const AccountId account_id = GetActiveAccountId();
CHECK(user_education_util::IsPrimaryAccountId(account_id));
return delegate_->IsTutorialRegistered(account_id, tutorial_id);
}
void UserEducationTutorialController::RegisterTutorial(
UserEducationPrivateApiKey,
TutorialId tutorial_id,
user_education::TutorialDescription tutorial_description) {
const AccountId account_id = GetActiveAccountId();
CHECK(user_education_util::IsPrimaryAccountId(account_id));
delegate_->RegisterTutorial(account_id, tutorial_id,
std::move(tutorial_description));
}
void UserEducationTutorialController::StartTutorial(
UserEducationPrivateApiKey,
TutorialId tutorial_id,
ui::ElementContext element_context,
base::OnceClosure completed_callback,
base::OnceClosure aborted_callback) {
const AccountId account_id = GetActiveAccountId();
CHECK(user_education_util::IsPrimaryAccountId(account_id));
delegate_->StartTutorial(account_id, tutorial_id, element_context,
std::move(completed_callback),
std::move(aborted_callback));
}
void UserEducationTutorialController::AbortTutorial(
UserEducationPrivateApiKey,
std::optional<TutorialId> tutorial_id) {
const AccountId account_id = GetActiveAccountId();
CHECK(user_education_util::IsPrimaryAccountId(account_id));
delegate_->AbortTutorial(account_id, tutorial_id);
}
}