#include "components/feature_engagement/internal/tracker_impl.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/check_is_test.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/clock.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/feature_engagement/internal/availability_model_impl.h"
#include "components/feature_engagement/internal/blocked_iph_features.h"
#include "components/feature_engagement/internal/chrome_variations_configuration.h"
#include "components/feature_engagement/internal/display_lock_controller_impl.h"
#include "components/feature_engagement/internal/editable_configuration.h"
#include "components/feature_engagement/internal/event_model.h"
#include "components/feature_engagement/internal/event_model_impl.h"
#include "components/feature_engagement/internal/feature_config_condition_validator.h"
#include "components/feature_engagement/internal/feature_config_event_storage_validator.h"
#include "components/feature_engagement/internal/in_memory_event_store.h"
#include "components/feature_engagement/internal/init_aware_event_model.h"
#include "components/feature_engagement/internal/never_availability_model.h"
#include "components/feature_engagement/internal/never_event_storage_validator.h"
#include "components/feature_engagement/internal/noop_display_lock_controller.h"
#include "components/feature_engagement/internal/once_condition_validator.h"
#include "components/feature_engagement/internal/persistent_event_store.h"
#include "components/feature_engagement/internal/proto/availability.pb.h"
#include "components/feature_engagement/internal/stats.h"
#include "components/feature_engagement/internal/system_time_provider.h"
#include "components/feature_engagement/internal/testing_clock_time_provider.h"
#include "components/feature_engagement/public/configuration.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/feature_list.h"
#include "components/feature_engagement/public/group_constants.h"
#include "components/feature_engagement/public/group_list.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
namespace feature_engagement {
namespace {
const char kEventDBName[] = …;
const char kAvailabilityDBName[] = …;
#if !BUILDFLAG(IS_ANDROID)
void MaybeGetEventData(Tracker::EventList& result,
const EventConfig& config,
const EventModel& event_model,
uint32_t current_day) { … }
#endif
}
std::unique_ptr<Tracker> CreateDemoModeTracker(
std::string chosen_feature_name) { … }
Tracker* Tracker::Create(
const base::FilePath& storage_dir,
const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
leveldb_proto::ProtoDatabaseProvider* db_provider,
std::unique_ptr<TrackerEventExporter> event_exporter,
const ConfigurationProviderList& configuration_providers,
std::unique_ptr<SessionController> session_controller) { … }
TrackerImpl::TrackerImpl(
std::unique_ptr<EventModel> event_model,
std::unique_ptr<AvailabilityModel> availability_model,
std::unique_ptr<Configuration> configuration,
std::unique_ptr<DisplayLockController> display_lock_controller,
std::unique_ptr<ConditionValidator> condition_validator,
std::unique_ptr<TimeProvider> time_provider,
std::unique_ptr<TrackerEventExporter> event_exporter,
std::unique_ptr<SessionController> session_controller)
: … { … }
TrackerImpl::~TrackerImpl() = default;
void TrackerImpl::NotifyEvent(const std::string& event) { … }
#if !BUILDFLAG(IS_ANDROID)
void TrackerImpl::NotifyUsedEvent(const base::Feature& feature) { … }
void TrackerImpl::ClearEventData(const base::Feature& feature) { … }
Tracker::EventList TrackerImpl::ListEvents(const base::Feature& feature) const { … }
#endif
bool TrackerImpl::ShouldTriggerHelpUI(const base::Feature& feature) { … }
TrackerImpl::TriggerDetails TrackerImpl::ShouldTriggerHelpUIWithSnooze(
const base::Feature& feature) { … }
bool TrackerImpl::WouldTriggerHelpUI(const base::Feature& feature) const { … }
bool TrackerImpl::HasEverTriggered(const base::Feature& feature,
bool from_window) const { … }
Tracker::TriggerState TrackerImpl::GetTriggerState(
const base::Feature& feature) const { … }
void TrackerImpl::Dismissed(const base::Feature& feature) { … }
void TrackerImpl::DismissedWithSnooze(
const base::Feature& feature,
std::optional<SnoozeAction> snooze_action) { … }
std::unique_ptr<DisplayLockHandle> TrackerImpl::AcquireDisplayLock() { … }
void TrackerImpl::SetPriorityNotification(const base::Feature& feature) { … }
std::optional<std::string> TrackerImpl::GetPendingPriorityNotification() { … }
void TrackerImpl::RegisterPriorityNotificationHandler(
const base::Feature& feature,
base::OnceClosure callback) { … }
void TrackerImpl::UnregisterPriorityNotificationHandler(
const base::Feature& feature) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void TrackerImpl::UpdateConfig(const base::Feature& feature,
const ConfigurationProvider* provider) {
CHECK(IsInitialized());
configuration_->UpdateConfig(feature, provider);
}
#endif
const Configuration* TrackerImpl::GetConfigurationForTesting() const { … }
void TrackerImpl::SetClockForTesting(const base::Clock& clock,
base::Time initial_now) { … }
bool TrackerImpl::IsInitialized() const { … }
void TrackerImpl::AddOnInitializedCallback(OnInitializedCallback callback) { … }
void TrackerImpl::OnEventModelInitializationFinished(bool success) { … }
void TrackerImpl::OnAvailabilityModelInitializationFinished(bool success) { … }
bool TrackerImpl::IsInitializationFinished() const { … }
void TrackerImpl::MaybePostInitializedCallbacks() { … }
void TrackerImpl::RecordShownTime(const base::Feature& feature) { … }
void TrackerImpl::OnReceiveExportedEvents(
std::vector<TrackerEventExporter::EventData> events) { … }
void Tracker::PropagateTestStateToChildProcess(
base::CommandLine& command_line) { … }
bool TrackerImpl::IsFeatureBlockedByTest(const base::Feature& feature) { … }
}