chromium/components/ntp_tiles/popular_sites_impl.cc

// Copyright 2015 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/popular_sites_impl.h"

#include <stddef.h>

#include <map>
#include <memory>
#include <string>
#include <utility>

#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/types/expected_macros.h"
#include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/google/core/common/google_util.h"
#include "components/ntp_tiles/features.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_engines/search_engine_type.h"
#include "components/search_engines/template_url_service.h"
#include "components/variations/service/variations_service.h"
#include "components/variations/variations_associated_data.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
#include "base/json/json_reader.h"
#include "components/grit/components_resources.h"
#include "ui/base/resource/resource_bundle.h"
#endif

#if BUILDFLAG(IS_IOS)
#include "components/ntp_tiles/country_code_ios.h"
#endif

VariationsService;

namespace ntp_tiles {

namespace {

const char kPopularSitesURLFormat[] =;
const char kPopularSitesDefaultDirectory[] =;
const char kPopularSitesDefaultCountryCode[] =;
const char kPopularSitesDefaultVersion[] =;
const int kSitesExplorationStartVersion =;
const int kPopularSitesRedownloadIntervalHours =;
#if BUILDFLAG(IS_IOS)
const char kIOSDefaultPopularSitesLocaleUS[] =
    "https://www.gstatic.com/chrome/ntp/ios/"
    "suggested_sites_US_2023q1_mvt_experiment_with_popular_sites.json";
#endif

GURL GetPopularSitesURL(const std::string& directory,
                        const std::string& country,
                        const std::string& version) {}

// Extract the country from the default search engine if the default search
// engine is Google.
std::string GetDefaultSearchEngineCountryCode(
    const TemplateURLService* template_url_service) {}

std::string GetVariationCountry() {}

std::string GetVariationVersion() {}

std::string GetVariationDirectory() {}

PopularSites::SitesVector ParseSiteList(const base::Value::List& list) {}

std::map<SectionType, PopularSites::SitesVector> ParseVersion5(
    const base::Value::List& list) {}

std::map<SectionType, PopularSites::SitesVector> ParseVersion6OrAbove(
    const base::Value::List& list) {}

std::map<SectionType, PopularSites::SitesVector> ParseSites(
    const base::Value::List& list,
    int version) {}

#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && \
    (BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS))
void SetDefaultResourceForSite(size_t index,
                               int resource_id,
                               base::Value::List& sites) {
  if (index >= sites.size() || !sites[index].is_dict()) {
    return;
  }

  sites[index].GetDict().Set("default_icon_resource", resource_id);
}
#endif

// Creates the list of popular sites based on a snapshot available for mobile.
base::Value::List DefaultPopularSites(std::optional<std::string> country) {}

}  // namespace

PopularSites::Site::Site(const std::u16string& title,
                         const GURL& url,
                         const GURL& favicon_url,
                         const GURL& large_icon_url,
                         TileTitleSource title_source)
    :{}

PopularSites::Site::Site(const Site& other) = default;

PopularSites::Site::~Site() = default;

PopularSitesImpl::PopularSitesImpl(
    PrefService* prefs,
    const TemplateURLService* template_url_service,
    VariationsService* variations_service,
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
    :{}

PopularSitesImpl::~PopularSitesImpl() = default;

bool PopularSitesImpl::MaybeStartFetch(bool force_download,
                                       FinishedCallback callback) {}

const std::map<SectionType, PopularSitesImpl::SitesVector>&
PopularSitesImpl::sections() const {}

GURL PopularSitesImpl::GetURLToFetch() {}

std::string PopularSitesImpl::GetDirectoryToFetch() {}

// Determine the country code to use. In order of precedence:
// - The explicit "override country" pref set by the user.
// - The country code from the field trial config (variation parameter).
// - The Google country code if Google is the default search engine (and the
//   "--enable-ntp-search-engine-country-detection" switch is present).
// - The country provided by the VariationsService.
// - A default fallback.
std::string PopularSitesImpl::GetCountryToFetch() {}

// Determine the version to use. In order of precedence:
// - The explicit "override version" pref set by the user.
// - The version from the field trial config (variation parameter).
// - A default fallback.
std::string PopularSitesImpl::GetVersionToFetch() {}

const base::Value::List& PopularSitesImpl::GetCachedJson() {}

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

void PopularSitesImpl::FetchPopularSites() {}

void PopularSitesImpl::OnSimpleLoaderComplete(
    std::unique_ptr<std::string> response_body) {}

void PopularSitesImpl::OnJsonParsed(
    data_decoder::DataDecoder::ValueOrError result) {}

void PopularSitesImpl::OnDownloadFailed() {}

}  // namespace ntp_tiles