#include "chrome/browser/engagement/important_sites_util.h"
#include <algorithm>
#include <map>
#include <memory>
#include <set>
#include <string_view>
#include <unordered_set>
#include <utility>
#include "base/containers/contains.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/browser/webapps/installable/installable_utils.h"
#include "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/url_and_title.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/site_engagement/content/site_engagement_score.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "components/site_engagement/core/mojom/site_engagement_details.mojom.h"
#include "components/webapps/browser/banners/app_banner_settings_helper.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_util.h"
#if !BUILDFLAG(IS_ANDROID)
#include "components/webapps/common/web_app_id.h"
#endif
namespace site_engagement {
namespace {
BookmarkModel;
UrlAndTitle;
ImportantDomainInfo;
ImportantReason;
static const char kTimeLastIgnored[] = …;
static const int kSuppressionExpirationTimeDays = …;
static const char kNumTimesIgnoredName[] = …;
static const int kTimesIgnoredForSuppression = …;
static const int kMaxBookmarks = …;
#define RECORD_UMA_FOR_IMPORTANT_REASON(uma_name, uma_count_name, \
reason_bitfield) …
void RecordIgnore(base::Value::Dict& dict) { … }
bool ShouldSuppressItem(base::Value::Dict& dict) { … }
void MaybePopulateImportantInfoForReason(
const GURL& origin,
std::set<GURL>* visited_origins,
ImportantReason reason,
std::optional<std::string> app_name,
std::map<std::string, ImportantDomainInfo>* output) { … }
int GetScoreForReason(ImportantReason reason) { … }
int GetScoreForReasonsBitfield(int32_t reason_bitfield) { … }
bool CompareDescendingImportantInfo(
const std::pair<std::string, ImportantDomainInfo>& a,
const std::pair<std::string, ImportantDomainInfo>& b) { … }
std::unordered_set<std::string> GetSuppressedImportantDomains(
Profile* profile) { … }
void PopulateInfoMapWithEngagement(
Profile* profile,
blink::mojom::EngagementLevel minimum_engagement,
std::map<GURL, double>* engagement_map,
std::map<std::string, ImportantDomainInfo>* output) { … }
void PopulateInfoMapWithContentTypeAllowed(
Profile* profile,
ContentSettingsType content_type,
ImportantReason reason,
std::map<std::string, ImportantDomainInfo>* output) { … }
void PopulateInfoMapWithBookmarks(
Profile* profile,
const std::map<GURL, double>& engagement_map,
std::map<std::string, ImportantDomainInfo>* output) { … }
}
ImportantDomainInfo::ImportantDomainInfo() = default;
ImportantDomainInfo::~ImportantDomainInfo() = default;
ImportantDomainInfo::ImportantDomainInfo(ImportantDomainInfo&&) = default;
ImportantDomainInfo& ImportantDomainInfo::operator=(ImportantDomainInfo&&) =
default;
std::string ImportantSitesUtil::GetRegisterableDomainOrIP(const GURL& url) { … }
std::string ImportantSitesUtil::GetRegisterableDomainOrIPFromHost(
std::string_view host) { … }
bool ImportantSitesUtil::IsDialogDisabled(Profile* profile) { … }
void ImportantSitesUtil::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
std::set<std::string> ImportantSitesUtil::GetInstalledRegisterableDomains(
Profile* profile) { … }
std::vector<ImportantDomainInfo>
ImportantSitesUtil::GetImportantRegisterableDomains(Profile* profile,
size_t max_results) { … }
void ImportantSitesUtil::RecordExcludedAndIgnoredImportantSites(
Profile* profile,
const std::vector<std::string>& excluded_sites,
const std::vector<int32_t>& excluded_sites_reason_bitfield,
const std::vector<std::string>& ignored_sites,
const std::vector<int32_t>& ignored_sites_reason_bitfield) { … }
void ImportantSitesUtil::MarkOriginAsImportantForTesting(Profile* profile,
const GURL& origin) { … }
}