chromium/components/ntp_tiles/most_visited_sites.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/ntp_tiles/most_visited_sites.h"

#include <algorithm>
#include <iterator>
#include <memory>
#include <utility>
#include <vector>

#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/metrics/user_metrics.h"
#include "base/observer_list.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/ntp_tiles/constants.h"
#include "components/ntp_tiles/deleted_tile_type.h"
#include "components/ntp_tiles/features.h"
#include "components/ntp_tiles/icon_cacher.h"
#include "components/ntp_tiles/metrics.h"
#include "components/ntp_tiles/pref_names.h"
#include "components/ntp_tiles/switches.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/search/ntp_features.h"
#include "components/supervised_user/core/common/buildflags.h"
#include "components/webapps/common/constants.h"
#include "extensions/buildflags/buildflags.h"
#include "third_party/re2/src/re2/re2.h"

#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "components/supervised_user/core/browser/supervised_user_capabilities.h"
#include "components/supervised_user/core/browser/supervised_user_service.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
// GN doesn't understand conditional includes, so we need nogncheck here.
#include "extensions/common/constants.h"  // nogncheck
#endif

TopSites;

namespace ntp_tiles {

namespace {

// URL host prefixes. Hosts with these prefixes often redirect to each other, or
// have the same content.
// Popular sites are excluded if the user has visited a page whose host only
// differs by one of these prefixes. Even if the URL does not point to the exact
// same page, the user will have a personalized suggestion that is more likely
// to be of use for them.
// A cleaner way could be checking the history for redirects but this requires
// the page to be visited on the device.
const char* kKnownGenericPagePrefixes[] =;  // The no-www domain matches domains on same level .

// Determine whether we need any tiles from PopularSites to fill up a grid of
// |num_tiles| tiles.
bool NeedPopularSites(const PrefService* prefs, int num_tiles) {}

bool HasHomeTile(const NTPTilesVector& tiles) {}

std::string StripFirstGenericPrefix(const std::string& host) {}

bool ShouldShowPopularSites() {}

// Generate a short title for Most Visited items before they're converted to
// custom links.
std::u16string GenerateShortTitle(const std::u16string& title) {}

}  // namespace

MostVisitedSites::MostVisitedSites(
    PrefService* prefs,
    signin::IdentityManager* identity_manager,
    supervised_user::SupervisedUserService* supervised_user_service,
    scoped_refptr<history::TopSites> top_sites,
    std::unique_ptr<PopularSites> popular_sites,
    std::unique_ptr<CustomLinksManager> custom_links,
    std::unique_ptr<IconCacher> icon_cacher,
    bool is_default_chrome_app_migrated)
    :{}

MostVisitedSites::~MostVisitedSites() {}

// static
bool MostVisitedSites::IsHostOrMobilePageKnown(
    const std::set<std::string>& hosts_to_skip,
    const std::string& host) {}

bool MostVisitedSites::DoesSourceExist(TileSource source) const {}

void MostVisitedSites::SetHomepageClient(
    std::unique_ptr<HomepageClient> client) {}

void MostVisitedSites::AddMostVisitedURLsObserver(Observer* observer,
                                                  size_t max_num_sites) {}

void MostVisitedSites::RemoveMostVisitedURLsObserver(Observer* observer) {}

void MostVisitedSites::Refresh() {}

void MostVisitedSites::RefreshTiles() {}

void MostVisitedSites::InitializeCustomLinks() {}

void MostVisitedSites::UninitializeCustomLinks() {}

bool MostVisitedSites::IsCustomLinksInitialized() {}

void MostVisitedSites::EnableCustomLinks(bool enable) {}

bool MostVisitedSites::IsCustomLinksEnabled() const {}

void MostVisitedSites::SetShortcutsVisible(bool visible) {}

bool MostVisitedSites::IsShortcutsVisible() const {}

bool MostVisitedSites::AddCustomLink(const GURL& url,
                                     const std::u16string& title) {}

bool MostVisitedSites::UpdateCustomLink(const GURL& url,
                                        const GURL& new_url,
                                        const std::u16string& new_title) {}

bool MostVisitedSites::ReorderCustomLink(const GURL& url, size_t new_pos) {}

bool MostVisitedSites::DeleteCustomLink(const GURL& url) {}

void MostVisitedSites::UndoCustomLinkAction() {}

size_t MostVisitedSites::GetCustomLinkNum() {}

void MostVisitedSites::AddOrRemoveBlockedUrl(const GURL& url, bool add_url) {}

void MostVisitedSites::ClearBlockedUrls() {}

#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
void MostVisitedSites::OnURLFilterChanged() {}
#endif

// static
void MostVisitedSites::RegisterProfilePrefs(
    user_prefs::PrefRegistrySyncable* registry) {}

// static
void MostVisitedSites::ResetProfilePrefs(PrefService* prefs) {}

size_t MostVisitedSites::GetMaxNumSites() const {}

void MostVisitedSites::InitiateTopSitesQuery() {}

void MostVisitedSites::OnMostVisitedURLsAvailable(
    const history::MostVisitedURLList& visited_list) {}

void MostVisitedSites::BuildCurrentTiles() {}

std::map<SectionType, NTPTilesVector>
MostVisitedSites::CreatePopularSitesSections(
    const std::set<std::string>& used_hosts,
    size_t num_actual_tiles) {}

NTPTilesVector MostVisitedSites::CreatePopularSitesTiles(
    const PopularSites::SitesVector& sites_vector,
    const std::set<std::string>& hosts_to_skip,
    size_t num_max_tiles) {}

void MostVisitedSites::OnHomepageTitleDetermined(
    NTPTilesVector tiles,
    const std::optional<std::u16string>& title) {}

NTPTilesVector MostVisitedSites::InsertHomeTile(
    NTPTilesVector tiles,
    const std::u16string& title) const {}

void MostVisitedSites::OnCustomLinksChanged() {}

void MostVisitedSites::BuildCustomLinks(
    const std::vector<CustomLinksManager::Link>& links) {}

void MostVisitedSites::InitiateNotificationForNewTiles(
    NTPTilesVector new_tiles) {}

void MostVisitedSites::MergeMostVisitedTiles(NTPTilesVector personal_tiles) {}

void MostVisitedSites::SaveTilesAndNotify(
    NTPTilesVector new_tiles,
    std::map<SectionType, NTPTilesVector> sections) {}

// static
bool MostVisitedSites::IsNtpTileFromPreinstalledApp(GURL url) {}

// static
bool MostVisitedSites::WasNtpAppMigratedToWebApp(PrefService* prefs, GURL url) {}

NTPTilesVector MostVisitedSites::RemoveInvalidPreinstallApps(
    NTPTilesVector new_tiles) {}

NTPTilesVector MostVisitedSites::MergeTiles(NTPTilesVector personal_tiles,
                                            NTPTilesVector popular_tiles) {}

void MostVisitedSites::OnPopularSitesDownloaded(bool success) {}

void MostVisitedSites::OnIconMadeAvailable(const GURL& site_url) {}

void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}

void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
                                       ChangeReason change_reason) {}

bool MostVisitedSites::ShouldAddHomeTile() const {}

void MostVisitedSites::AddToHostsAndTotalCount(const NTPTilesVector& new_tiles,
                                               std::set<std::string>* hosts,
                                               size_t* total_tile_count) const {}

}  // namespace ntp_tiles