#include "chrome/browser/download/download_warning_desktop_hats_utils.h"
#include <cstdint>
#include <iterator>
#include <string>
#include <vector>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/version_info/channel.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_item_warning_data.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/hats/hats_service.h"
#include "chrome/browser/ui/hats/hats_service_factory.h"
#include "chrome/browser/ui/hats/survey_config.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/pref_names.h"
#include "components/download/public/common/download_item.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "content/public/browser/download_item_utils.h"
namespace {
constexpr char kNotAvailable[] = …;
constexpr char kNotLoggedNoSafeBrowsing[] = …;
constexpr char kNotLoggedNoEnhancedProtection[] = …;
bool IsDownloadBubbleTrigger(DownloadWarningHatsType type) { … }
bool IsDownloadsPageTrigger(DownloadWarningHatsType type) { … }
std::string GetOutcomeStringData(DownloadWarningHatsType type) { … }
std::string GetSurfaceStringData(DownloadWarningHatsType type) { … }
std::string GetDangerTypeStringData(const DownloadItemModel& model) { … }
std::string GetWarningTypeStringData(const DownloadUIModel& model) { … }
std::string ElapsedTimeToSecondsString(base::TimeDelta elapsed_time) { … }
std::string SafeBrowsingStateToString(
safe_browsing::SafeBrowsingState sb_state) { … }
std::string SerializeWarningActionEvents(
DownloadItemWarningData::WarningSurface warning_first_shown_surface,
const std::vector<DownloadItemWarningData::WarningActionEvent>& events) { … }
}
DownloadWarningHatsProductSpecificData::DownloadWarningHatsProductSpecificData(
DownloadWarningHatsType survey_type)
: … { … }
DownloadWarningHatsProductSpecificData::DownloadWarningHatsProductSpecificData(
const DownloadWarningHatsProductSpecificData&) = default;
DownloadWarningHatsProductSpecificData&
DownloadWarningHatsProductSpecificData::operator=(
const DownloadWarningHatsProductSpecificData&) = default;
DownloadWarningHatsProductSpecificData::DownloadWarningHatsProductSpecificData(
DownloadWarningHatsProductSpecificData&&) = default;
DownloadWarningHatsProductSpecificData&
DownloadWarningHatsProductSpecificData::operator=(
DownloadWarningHatsProductSpecificData&&) = default;
DownloadWarningHatsProductSpecificData::
~DownloadWarningHatsProductSpecificData() = default;
DownloadWarningHatsProductSpecificData
DownloadWarningHatsProductSpecificData::Create(
DownloadWarningHatsType survey_type,
download::DownloadItem* download_item) { … }
void DownloadWarningHatsProductSpecificData::AddNumPageWarnings(int num) { … }
void DownloadWarningHatsProductSpecificData::AddPartialViewInteraction(
bool partial_view_interaction) { … }
std::vector<std::string>
DownloadWarningHatsProductSpecificData::GetBitsDataFields(
DownloadWarningHatsType survey_type) { … }
std::vector<std::string>
DownloadWarningHatsProductSpecificData::GetStringDataFields(
DownloadWarningHatsType survey_type) { … }
DelayedDownloadWarningHatsLauncher::Task::Task(
DelayedDownloadWarningHatsLauncher& hats_launcher,
download::DownloadItem* download,
base::OnceClosure task,
base::TimeDelta delay)
: … { … }
DelayedDownloadWarningHatsLauncher::Task::~Task() = default;
void DelayedDownloadWarningHatsLauncher::Task::RunTask() { … }
DelayedDownloadWarningHatsLauncher::DelayedDownloadWarningHatsLauncher(
Profile* profile,
base::TimeDelta delay,
PsdCompleter psd_completer)
: … { … }
DelayedDownloadWarningHatsLauncher::~DelayedDownloadWarningHatsLauncher() =
default;
void DelayedDownloadWarningHatsLauncher::OnDownloadUpdated(
download::DownloadItem* download) { … }
void DelayedDownloadWarningHatsLauncher::OnDownloadDestroyed(
download::DownloadItem* download) { … }
void DelayedDownloadWarningHatsLauncher::RecordBrowserActivity() { … }
bool DelayedDownloadWarningHatsLauncher::TryScheduleTask(
DownloadWarningHatsType survey_type,
download::DownloadItem* download) { … }
void DelayedDownloadWarningHatsLauncher::RemoveTaskIfAny(
download::DownloadItem* download) { … }
DelayedDownloadWarningHatsLauncher::TaskKey
DelayedDownloadWarningHatsLauncher::GetTaskKey(
download::DownloadItem* download) { … }
void DelayedDownloadWarningHatsLauncher::RemoveTaskByKeyIfAny(TaskKey key) { … }
void DelayedDownloadWarningHatsLauncher::MaybeLaunchSurveyNow(
DownloadWarningHatsType survey_type,
download::DownloadItem* download) { … }
base::OnceClosure DelayedDownloadWarningHatsLauncher::MakeSurveyDoneCallback(
download::DownloadItem* download) { … }
bool DelayedDownloadWarningHatsLauncher::WasUserActive() const { … }
bool CanShowDownloadWarningHatsSurvey(download::DownloadItem* download) { … }
std::optional<std::string> MaybeGetDownloadWarningHatsTrigger(
DownloadWarningHatsType survey_type) { … }
base::TimeDelta GetIgnoreDownloadBubbleWarningDelay() { … }
void MaybeLaunchDownloadWarningHatsSurvey(
Profile* profile,
const DownloadWarningHatsProductSpecificData& psd,
base::OnceClosure success_callback,
base::OnceClosure failure_callback) { … }