#include "components/history/core/browser/top_sites_impl.h"
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/hash/md5.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.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/task/single_thread_task_runner.h"
#include "base/task/task_runner.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/history/core/browser/features.h"
#include "components/history/core/browser/history_backend.h"
#include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/keyword_search_term.h"
#include "components/history/core/browser/keyword_search_term_util.h"
#include "components/history/core/browser/page_usage_data.h"
#include "components/history/core/browser/top_sites_observer.h"
#include "components/history/core/browser/url_database.h"
#include "components/history/core/browser/url_utils.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "url/gurl.h"
namespace history {
namespace {
void RunOrPostGetMostVisitedURLsCallback(
base::SequencedTaskRunner* task_runner,
TopSitesImpl::GetMostVisitedURLsCallback callback,
const MostVisitedURLList& urls) { … }
bool DoTitlesDiffer(const MostVisitedURLList& old_list,
const MostVisitedURLList& new_list) { … }
double GetNumberInNewRange(double number,
double max,
double min,
double new_max,
double new_min) { … }
constexpr base::TimeDelta kFirstDelayAtStartup = …;
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
constexpr base::TimeDelta kDelayForUpdates = base::Minutes(5);
#else
constexpr base::TimeDelta kDelayForUpdates = …;
#endif
const char kBlockedUrlsPrefsKey[] = …;
void LogMostVisitedScores(const MostVisitedURLList& sites) { … }
}
struct SitesAndQueriesRequest
: public base::RefCounted<SitesAndQueriesRequest> { … };
TopSitesImpl::TopSitesImpl(PrefService* pref_service,
HistoryService* history_service,
TemplateURLService* template_url_service,
const PrepopulatedPageList& prepopulated_pages,
const CanAddURLToHistoryFn& can_add_url_to_history)
: … { … }
void TopSitesImpl::Init(const base::FilePath& db_name) { … }
void TopSitesImpl::GetMostVisitedURLs(GetMostVisitedURLsCallback callback) { … }
void TopSitesImpl::SyncWithHistory() { … }
bool TopSitesImpl::HasBlockedUrls() const { … }
void TopSitesImpl::AddBlockedUrl(const GURL& url) { … }
void TopSitesImpl::RemoveBlockedUrl(const GURL& url) { … }
bool TopSitesImpl::IsBlocked(const GURL& url) { … }
void TopSitesImpl::ClearBlockedUrls() { … }
bool TopSitesImpl::IsFull() { … }
PrepopulatedPageList TopSitesImpl::GetPrepopulatedPages() { … }
bool TopSitesImpl::loaded() const { … }
void TopSitesImpl::OnNavigationCommitted(const GURL& url) { … }
void TopSitesImpl::ShutdownOnUIThread() { … }
void TopSitesImpl::RegisterPrefs(PrefRegistrySimple* registry) { … }
TopSitesImpl::~TopSitesImpl() = default;
void TopSitesImpl::StartQueryForMostVisited() { … }
void TopSitesImpl::DiffMostVisited(const MostVisitedURLList& old_list,
const MostVisitedURLList& new_list,
TopSitesDelta* delta) { … }
bool TopSitesImpl::AddPrepopulatedPages(MostVisitedURLList* urls) const { … }
MostVisitedURLList TopSitesImpl::ApplyBlockedUrls(
const MostVisitedURLList& urls) { … }
std::string TopSitesImpl::GetURLHash(const GURL& url) { … }
void TopSitesImpl::SetTopSites(MostVisitedURLList top_sites,
const CallLocation location) { … }
int TopSitesImpl::num_results_to_request_from_history() const { … }
void TopSitesImpl::MoveStateToLoaded() { … }
void TopSitesImpl::ResetThreadSafeCache() { … }
void TopSitesImpl::ScheduleUpdateTimer() { … }
void TopSitesImpl::OnGotMostVisitedURLs(MostVisitedURLList sites) { … }
void TopSitesImpl::OnGotMostVisitedURLsFromHistory(
scoped_refptr<SitesAndQueriesRequest> request,
MostVisitedURLList sites) { … }
void TopSitesImpl::OnGotMostRepeatedQueriesFromHistory(
scoped_refptr<SitesAndQueriesRequest> request,
KeywordSearchTermVisitList queries) { … }
void TopSitesImpl::SetTopSitesFromHistory(
scoped_refptr<SitesAndQueriesRequest> request) { … }
void TopSitesImpl::OnHistoryDeletions(HistoryService* history_service,
const DeletionInfo& deletion_info) { … }
}