#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/search_engines/template_url_prepopulate_data.h"
#include <algorithm>
#include <random>
#include <vector>
#include "base/check_is_test.h"
#include "base/containers/contains.h"
#include "base/containers/to_vector.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "build/build_config.h"
#include "components/country_codes/country_codes.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/eea_countries_ids.h"
#include "components/search_engines/prepopulated_engines.h"
#include "components/search_engines/search_engine_choice/search_engine_choice_service.h"
#include "components/search_engines/search_engine_choice/search_engine_choice_utils.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/template_url_data.h"
#include "components/search_engines/template_url_data_util.h"
#include "components/version_info/version_info.h"
namespace TemplateURLPrepopulateData {
namespace {
#include "components/search_engines/search_engine_countries-inc.cc"
std::vector<std::unique_ptr<TemplateURLData>>
GetPrepopulatedEnginesForEeaRegionCountries(int country_id,
PrefService* prefs) { … }
std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedTemplateURLData(
int country_id,
PrefService* prefs) { … }
enum class SearchProviderOverrideStatus { … };
std::vector<std::unique_ptr<TemplateURLData>> GetOverriddenTemplateURLData(
PrefService* prefs) { … }
std::unique_ptr<TemplateURLData> FindPrepopulatedEngineInternal(
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service,
int prepopulated_id,
bool use_first_as_fallback) { … }
}
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { … }
int GetDataVersion(PrefService* prefs) { … }
std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service) { … }
std::unique_ptr<TemplateURLData> GetPrepopulatedEngine(
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service,
int prepopulated_id) { … }
#if BUILDFLAG(IS_ANDROID)
std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
const std::string& country_code,
PrefService& prefs) {
int country_id = country_codes::CountryStringToCountryID(country_code);
if (country_id == country_codes::kCountryIDUnknown) {
LOG(ERROR) << "Unknown country code specified: " << country_code;
return std::vector<std::unique_ptr<TemplateURLData>>();
}
return GetPrepopulatedTemplateURLData(country_id, &prefs);
}
#endif
std::unique_ptr<TemplateURLData> GetPrepopulatedEngineFromFullList(
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service,
int prepopulated_id) { … }
void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) { … }
std::unique_ptr<TemplateURLData> GetPrepopulatedFallbackSearch(
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service) { … }
std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() { … }
std::vector<std::unique_ptr<TemplateURLData>>
GetAllEeaRegionPrepopulatedEngines() { … }
std::vector<std::unique_ptr<TemplateURLData>> GetDefaultPrepopulatedEngines() { … }
const std::vector<raw_ptr<const PrepopulatedEngine>>
GetPrepopulationSetFromCountryIDForTesting(int country_id) { … }
}