chromium/components/history/core/browser/top_sites_impl.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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) {}

// Checks if the titles stored in `old_list` and `new_list` have changes.
bool DoTitlesDiffer(const MostVisitedURLList& old_list,
                    const MostVisitedURLList& new_list) {}

// Transforms |number| in the range given by |max| and |min| to a number in the
// range given by |new_max| and |new_min| while maintaining the ratio.
double GetNumberInNewRange(double number,
                           double max,
                           double min,
                           double new_max,
                           double new_min) {}

// The delay for the first HistoryService query at startup.
constexpr base::TimeDelta kFirstDelayAtStartup =;

// The delay for the all HistoryService queries other than the first one.
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
// On mobile, having the max at 60 minutes results in the topsites database
// being not updated often enough since the app isn't usually running for long
// stretches of time.
constexpr base::TimeDelta kDelayForUpdates = base::Minutes(5);
#else
constexpr base::TimeDelta kDelayForUpdates =;
#endif  // BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)

// Key for preference listing the URLs that should not be shown as most visited
// tiles.
// TODO(sky): rename actual value to 'most_visited_blocked_urls.'
const char kBlockedUrlsPrefsKey[] =;

void LogMostVisitedScores(const MostVisitedURLList& sites) {}

}  // namespace

// Stores the most visited sites and the most repeated queries returned from
// the history service. Used to synchronize parallel requests to the history
// service in order to combine the sites and the queries.
struct SitesAndQueriesRequest
    : public base::RefCounted<SitesAndQueriesRequest> {};

// Initially, histogram is not recorded.
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) {}

// WARNING: this function may be invoked on any thread.
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() {}

// static
void TopSitesImpl::RegisterPrefs(PrefRegistrySimple* registry) {}

TopSitesImpl::~TopSitesImpl() = default;

void TopSitesImpl::StartQueryForMostVisited() {}

// static
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) {}

// static
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) {}

}  // namespace history