#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/webapps/browser/banners/app_banner_settings_helper.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/json/values_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/permissions/permissions_client.h"
#include "components/webapps/browser/banners/app_banner_manager.h"
#include "components/webapps/browser/banners/app_banner_metrics.h"
#include "components/webapps/browser/banners/install_banner_config.h"
#include "components/webapps/browser/features.h"
#include "components/webapps/common/switches.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "url/gurl.h"
namespace webapps {
namespace {
const size_t kMaxAppsPerSite = …;
constexpr const char* kBannerEventKeys[] = …;
double gTotalEngagementToTrigger = …;
unsigned int gDaysAfterDismissedToShow = …;
unsigned int gDaysAfterIgnoredToShow = …;
base::Value::Dict GetOriginAppBannerData(HostContentSettingsMap* settings,
const GURL& origin_url) { … }
class AppPrefs { … };
void UpdateDaysBetweenShowing() { … }
void UpdateSiteEngagementToTrigger() { … }
std::optional<bool> WasEventWithinPeriod(
AppBannerSettingsHelper::AppBannerEvent event,
base::TimeDelta period,
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
base::Time now) { … }
constexpr char kNextInstallTextAnimation[] = …;
constexpr char kLastShownKey[] = …;
constexpr char kDelayKey[] = …;
struct NextInstallTextAnimation { … };
std::optional<NextInstallTextAnimation> NextInstallTextAnimation::Get(
content::WebContents* web_contents,
const GURL& scope) { … }
void NextInstallTextAnimation::RecordToPrefs(content::WebContents* web_contents,
const GURL& scope) const { … }
}
const char AppBannerSettingsHelper::kInstantAppsKey[] = …;
void AppBannerSettingsHelper::ClearHistoryForURLs(
content::BrowserContext* browser_context,
const std::set<GURL>& origin_urls) { … }
void AppBannerSettingsHelper::RecordBannerInstallEvent(
content::WebContents* web_contents,
const std::string& package_name_or_start_url) { … }
void AppBannerSettingsHelper::RecordBannerDismissEvent(
content::WebContents* web_contents,
const std::string& package_name_or_start_url) { … }
void AppBannerSettingsHelper::RecordBannerEvent(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
AppBannerEvent event,
base::Time time) { … }
void AppBannerSettingsHelper::RecordBannerEvent(
content::WebContents* web_contents,
const InstallBannerConfig& install_config,
AppBannerEvent event,
base::Time time) { … }
bool AppBannerSettingsHelper::WasBannerRecentlyBlocked(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
base::Time now) { … }
bool AppBannerSettingsHelper::WasBannerRecentlyIgnored(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
base::Time now) { … }
std::optional<base::Time> AppBannerSettingsHelper::GetSingleBannerEvent(
content::WebContents* web_contents,
const GURL& origin_url,
const std::string& package_name_or_start_url,
AppBannerEvent event) { … }
bool AppBannerSettingsHelper::HasSufficientEngagement(double total_engagement) { … }
void AppBannerSettingsHelper::SetDaysAfterDismissAndIgnoreToTrigger(
unsigned int dismiss_days,
unsigned int ignore_days) { … }
void AppBannerSettingsHelper::SetTotalEngagementToTrigger(
double total_engagement) { … }
base::AutoReset<double> AppBannerSettingsHelper::ScopeTotalEngagementForTesting(
double total_engagement) { … }
void AppBannerSettingsHelper::UpdateFromFieldTrial() { … }
bool AppBannerSettingsHelper::CanShowInstallTextAnimation(
content::WebContents* web_contents,
const GURL& scope) { … }
void AppBannerSettingsHelper::RecordInstallTextAnimationShown(
content::WebContents* web_contents,
const GURL& scope) { … }
AppBannerSettingsHelper::ScopedTriggerSettings::ScopedTriggerSettings(
unsigned int dismiss_days,
unsigned int ignore_days) { … }
AppBannerSettingsHelper::ScopedTriggerSettings::~ScopedTriggerSettings() { … }
}