#include "components/user_education/common/feature_promo_controller.h"
#include <optional>
#include <string>
#include "base/auto_reset.h"
#include "base/callback_list.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/notimplemented.h"
#include "build/build_config.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/strings/grit/components_strings.h"
#include "components/user_education/common/feature_promo_data.h"
#include "components/user_education/common/feature_promo_lifecycle.h"
#include "components/user_education/common/feature_promo_registry.h"
#include "components/user_education/common/feature_promo_result.h"
#include "components/user_education/common/feature_promo_session_policy.h"
#include "components/user_education/common/feature_promo_specification.h"
#include "components/user_education/common/feature_promo_storage_service.h"
#include "components/user_education/common/help_bubble_factory_registry.h"
#include "components/user_education/common/help_bubble_params.h"
#include "components/user_education/common/product_messaging_controller.h"
#include "components/user_education/common/tutorial.h"
#include "components/user_education/common/tutorial_service.h"
#include "ui/accessibility/ax_mode.h"
#include "ui/accessibility/platform/ax_platform.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/l10n/l10n_util.h"
namespace user_education {
namespace {
DEFINE_LOCAL_REQUIRED_NOTICE_IDENTIFIER(…);
}
FeaturePromoController::FeaturePromoController() = default;
FeaturePromoController::~FeaturePromoController() = default;
struct FeaturePromoControllerCommon::ShowPromoBubbleParams { … };
struct FeaturePromoControllerCommon::QueuedPromoData { … };
FeaturePromoControllerCommon::FeaturePromoControllerCommon(
feature_engagement::Tracker* feature_engagement_tracker,
FeaturePromoRegistry* registry,
HelpBubbleFactoryRegistry* help_bubble_registry,
FeaturePromoStorageService* storage_service,
FeaturePromoSessionPolicy* session_policy,
TutorialService* tutorial_service,
ProductMessagingController* messaging_controller)
: … { … }
FeaturePromoControllerCommon::~FeaturePromoControllerCommon() { … }
FeaturePromoResult FeaturePromoControllerCommon::CanShowPromo(
const FeaturePromoParams& params) const { … }
FeaturePromoResult FeaturePromoControllerCommon::MaybeShowPromo(
FeaturePromoParams params) { … }
bool FeaturePromoControllerCommon::MaybeShowStartupPromo(
FeaturePromoParams params) { … }
FeaturePromoResult FeaturePromoControllerCommon::MaybeShowPromoForDemoPage(
FeaturePromoParams params) { … }
FeaturePromoResult FeaturePromoControllerCommon::MaybeShowPromoImpl(
FeaturePromoParams params,
ShowSource source) { … }
FeaturePromoResult FeaturePromoControllerCommon::MaybeShowPromoCommon(
FeaturePromoParams params,
ShowSource source) { … }
std::unique_ptr<HelpBubble> FeaturePromoControllerCommon::ShowCriticalPromo(
const FeaturePromoSpecification& spec,
ui::TrackedElement* anchor_element,
FeaturePromoSpecification::FormatParameters body_params,
FeaturePromoSpecification::FormatParameters title_params) { … }
FeaturePromoStatus FeaturePromoControllerCommon::GetPromoStatus(
const base::Feature& iph_feature) const { … }
const FeaturePromoSpecification*
FeaturePromoControllerCommon::GetCurrentPromoSpecificationForAnchor(
ui::ElementIdentifier menu_element_id) const { … }
bool FeaturePromoControllerCommon::HasPromoBeenDismissed(
const FeaturePromoParams& params,
FeaturePromoClosedReason* last_close_reason) const { … }
bool FeaturePromoControllerCommon::EndPromo(
const base::Feature& iph_feature,
EndFeaturePromoReason end_promo_reason) { … }
bool FeaturePromoControllerCommon::EndPromo(
const base::Feature& iph_feature,
FeaturePromoClosedReason close_reason) { … }
void FeaturePromoControllerCommon::RecordPromoEnded(
FeaturePromoClosedReason close_reason,
bool continue_after_close) { … }
bool FeaturePromoControllerCommon::DismissNonCriticalBubbleInRegion(
const gfx::Rect& screen_bounds) { … }
#if !BUILDFLAG(IS_ANDROID)
void FeaturePromoControllerCommon::NotifyFeatureUsedIfValid(
const base::Feature& feature) { … }
#endif
FeaturePromoHandle FeaturePromoControllerCommon::CloseBubbleAndContinuePromo(
const base::Feature& iph_feature) { … }
FeaturePromoHandle
FeaturePromoControllerCommon::CloseBubbleAndContinuePromoWithReason(
const base::Feature& iph_feature,
FeaturePromoClosedReason close_reason) { … }
base::WeakPtr<FeaturePromoController>
FeaturePromoControllerCommon::GetAsWeakPtr() { … }
bool FeaturePromoControllerCommon::CheckScreenReaderPromptAvailable(
bool for_demo) const { … }
void FeaturePromoControllerCommon::OnFeatureEngagementTrackerInitialized(
bool tracker_initialized_successfully) { … }
void FeaturePromoControllerCommon::MaybeRequestMessagePriority() { … }
void FeaturePromoControllerCommon::OnMessagePriority(
RequiredNoticePriorityHandle notice_handle) { … }
FeaturePromoControllerCommon::QueuedPromos::iterator
FeaturePromoControllerCommon::GetNextQueuedPromo() { … }
const FeaturePromoControllerCommon::QueuedPromoData*
FeaturePromoControllerCommon::GetNextQueuedPromo() const { … }
void FeaturePromoControllerCommon::MaybeShowQueuedPromo() { … }
bool FeaturePromoControllerCommon::IsPromoQueued(
const base::Feature& iph_feature) const { … }
FeaturePromoControllerCommon::QueuedPromos::iterator
FeaturePromoControllerCommon::FindQueuedPromo(
const base::Feature& iph_feature) { … }
void FeaturePromoControllerCommon::FailQueuedPromos() { … }
FeaturePromoResult FeaturePromoControllerCommon::CanShowPromoCommon(
const FeaturePromoParams& params,
ShowSource source,
const FeaturePromoSpecification** primary_spec_out,
const FeaturePromoSpecification** display_spec_out,
std::unique_ptr<FeaturePromoLifecycle>* lifecycle_out,
ui::TrackedElement** anchor_element_out) const { … }
std::unique_ptr<HelpBubble> FeaturePromoControllerCommon::ShowPromoBubbleImpl(
ShowPromoBubbleParams params) { … }
void FeaturePromoControllerCommon::FinishContinuedPromo(
const base::Feature& iph_feature) { … }
void FeaturePromoControllerCommon::OnHelpBubbleClosed(
HelpBubble* bubble,
HelpBubble::CloseReason reason) { … }
void FeaturePromoControllerCommon::OnHelpBubbleTimedOut(
const base::Feature* feature) { … }
void FeaturePromoControllerCommon::OnHelpBubbleSnoozed(
const base::Feature* feature) { … }
void FeaturePromoControllerCommon::OnHelpBubbleDismissed(
const base::Feature* feature,
bool via_action_button) { … }
void FeaturePromoControllerCommon::OnHelpBubbleTimeout(
const base::Feature* feature) { … }
void FeaturePromoControllerCommon::OnCustomAction(
const base::Feature* feature,
FeaturePromoSpecification::CustomActionCallback callback) { … }
void FeaturePromoControllerCommon::OnTutorialHelpBubbleSnoozed(
const base::Feature* iph_feature,
TutorialIdentifier tutorial_id) { … }
void FeaturePromoControllerCommon::OnTutorialHelpBubbleDismissed(
const base::Feature* iph_feature,
TutorialIdentifier tutorial_id) { … }
void FeaturePromoControllerCommon::OnTutorialStarted(
const base::Feature* iph_feature,
TutorialIdentifier tutorial_id) { … }
void FeaturePromoControllerCommon::OnTutorialComplete(
const base::Feature* iph_feature) { … }
void FeaturePromoControllerCommon::OnTutorialAborted(
const base::Feature* iph_feature) { … }
std::vector<HelpBubbleButtonParams>
FeaturePromoControllerCommon::CreateRotatingToastButtons(
const base::Feature& feature) { … }
std::vector<HelpBubbleButtonParams>
FeaturePromoControllerCommon::CreateSnoozeButtons(const base::Feature& feature,
bool can_snooze) { … }
std::vector<HelpBubbleButtonParams>
FeaturePromoControllerCommon::CreateCustomActionButtons(
const base::Feature& feature,
const std::u16string& custom_action_caption,
FeaturePromoSpecification::CustomActionCallback custom_action_callback,
bool custom_action_is_default,
int custom_action_dismiss_string_id) { … }
std::vector<HelpBubbleButtonParams>
FeaturePromoControllerCommon::CreateTutorialButtons(
const base::Feature& feature,
bool can_snooze,
TutorialIdentifier tutorial_id) { … }
const base::Feature* FeaturePromoControllerCommon::GetCurrentPromoFeature()
const { … }
void FeaturePromoControllerCommon::RecordPromoNotShown(
const char* feature_name,
FeaturePromoResult::Failure failure) const { … }
bool FeaturePromoControllerCommon::active_window_check_blocked_ = …;
FeaturePromoControllerCommon::TestLock
FeaturePromoControllerCommon::BlockActiveWindowCheckForTesting() { … }
FeaturePromoParams::FeaturePromoParams(const base::Feature& iph_feature,
const std::string& promo_key)
: … { … }
FeaturePromoParams::FeaturePromoParams(FeaturePromoParams&& other) noexcept =
default;
FeaturePromoParams::~FeaturePromoParams() = default;
std::ostream& operator<<(std::ostream& os, FeaturePromoStatus status) { … }
}