// Copyright 2024 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_WARNING_DESKTOP_HATS_UTILS_H_ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_WARNING_DESKTOP_HATS_UTILS_H_ #include <map> #include <optional> #include <string> #include <vector> #include "base/functional/callback.h" #include "base/memory/weak_ptr.h" #include "base/scoped_observation.h" #include "chrome/browser/ui/hats/hats_service.h" #include "components/download/public/common/download_item.h" // Type of survey (corresponding to a trigger condition) that should be shown. // Do not renumber. enum class DownloadWarningHatsType { … }; // Stores the PSD for the download warning HaTS survey. class DownloadWarningHatsProductSpecificData { … }; // A class that manages delayed download warning HaTS survey tasks. It can be // given a DownloadItem to launch a survey for in the future after some delay, // and these tasks can be canceled explicitly or automatically (in case of // the DownloadItem getting destroyed or becoming ineligible for a HaTS survey). // It also records the last time the user interacted with the browser, and the // survey is withheld if the user was (presumably) idle for the entire period of // the delay. (Client should inform this object of browser activity.) // Note: Currently this is only used for download bubble ignore triggers. class DelayedDownloadWarningHatsLauncher : public download::DownloadItem::Observer { … }; // Returns if the download item is dangerous and not-done. bool CanShowDownloadWarningHatsSurvey(download::DownloadItem* download); // Returns the HaTS trigger string for the survey_type, if the user is eligible // for that type of survey (according to the fieldtrial config). If the user // is not eligible, or there is a configuration error, this returns nullopt. std::optional<std::string> MaybeGetDownloadWarningHatsTrigger( DownloadWarningHatsType survey_type); // Returns the time delay used for kDownloadBubbleIgnore triggers. base::TimeDelta GetIgnoreDownloadBubbleWarningDelay(); // Launches a HaTS survey using the desktop HaTS service, if all preconditions // are met. The `psd` object encapsulates the data for the survey, including the // triggering survey type. `profile` is the profile for which the survey should // be launched. Note that it is potentially different from the profile under // which the download was made (in the case of OTR profiles which may care about // downloads made in their original profile), so it needs to be passed and // cannot be derived from the DownloadItem. However, when `profile` is OTR and // differs from the DownloadItem's Profile, a HaTS survey won't be shown anyway // because HaTS surveys are not shown for OTR profiles, so everything is fine // as long as we pass the correct `profile` for which we are attempting to // launch the survey. void MaybeLaunchDownloadWarningHatsSurvey( Profile* profile, const DownloadWarningHatsProductSpecificData& psd, base::OnceClosure success_callback = base::DoNothing(), base::OnceClosure failure_callback = base::DoNothing()); #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_WARNING_DESKTOP_HATS_UTILS_H_