#include "components/search_engines/util.h"
#include <stddef.h>
#include <stdint.h>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "base/check_is_test.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/time/time.h"
#include "components/country_codes/country_codes.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/keyword_web_data_service.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.h"
#include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_starter_pack_data.h"
namespace {
struct MergeEngineRequirements { … };
MergeEngineRequirements ComputeMergeEnginesRequirements(
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service,
const WDKeywordsResult::Metadata& keywords_metadata) { … }
}
std::u16string GetDefaultSearchEngineName(TemplateURLService* service) { … }
GURL GetDefaultSearchURLForSearchTerms(TemplateURLService* service,
const std::u16string& terms) { … }
void RemoveDuplicatePrepopulateIDs(
KeywordWebDataService* service,
const std::vector<std::unique_ptr<TemplateURLData>>& prepopulated_urls,
TemplateURL* default_search_provider,
TemplateURLService::OwnedTemplateURLVector* template_urls,
const SearchTermsData& search_terms_data,
std::set<std::string>* removed_keyword_guids) { … }
TemplateURL* GetTemplateURLByID(
const TemplateURLService::TemplateURLVector& template_urls,
int64_t id) { … }
TemplateURL* FindURLByPrepopulateID(
const TemplateURLService::TemplateURLVector& template_urls,
int prepopulate_id) { … }
void MergeIntoEngineData(const TemplateURL* original_turl,
TemplateURLData* url_to_update,
TemplateURLMergeOption merge_option) { … }
ActionsFromCurrentData::ActionsFromCurrentData() = default;
ActionsFromCurrentData::ActionsFromCurrentData(
const ActionsFromCurrentData& other) = default;
ActionsFromCurrentData::~ActionsFromCurrentData() = default;
void MergeEnginesFromPrepopulateData(
KeywordWebDataService* service,
std::vector<std::unique_ptr<TemplateURLData>>* prepopulated_urls,
TemplateURLService::OwnedTemplateURLVector* template_urls,
TemplateURL* default_search_provider,
std::set<std::string>* removed_keyword_guids) { … }
ActionsFromCurrentData CreateActionsFromCurrentPrepopulateData(
std::vector<std::unique_ptr<TemplateURLData>>* prepopulated_urls,
const TemplateURLService::OwnedTemplateURLVector& existing_urls,
const TemplateURL* default_search_provider) { … }
const std::string& GetDefaultSearchProviderGuidFromPrefs(PrefService& prefs) { … }
void SetDefaultSearchProviderGuidToPrefs(PrefService& prefs,
const std::string& value) { … }
void MergeEnginesFromStarterPackData(
KeywordWebDataService* service,
TemplateURLService::OwnedTemplateURLVector* template_urls,
TemplateURL* default_search_provider,
std::set<std::string>* removed_keyword_guids,
TemplateURLMergeOption merge_option) { … }
ActionsFromCurrentData CreateActionsFromCurrentStarterPackData(
std::vector<std::unique_ptr<TemplateURLData>>* starter_pack_urls,
const TemplateURLService::OwnedTemplateURLVector& existing_urls,
TemplateURLMergeOption merge_option) { … }
void ApplyActionsFromCurrentData(
ActionsFromCurrentData actions,
KeywordWebDataService* service,
TemplateURLService::OwnedTemplateURLVector* template_urls,
TemplateURL* default_search_provider,
std::set<std::string>* removed_keyword_guids) { … }
void GetSearchProvidersUsingKeywordResult(
const WDTypedResult& result,
KeywordWebDataService* service,
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service,
TemplateURLService::OwnedTemplateURLVector* template_urls,
TemplateURL* default_search_provider,
const SearchTermsData& search_terms_data,
WDKeywordsResult::Metadata& out_updated_keywords_metadata,
std::set<std::string>* removed_keyword_guids) { … }
void GetSearchProvidersUsingLoadedEngines(
KeywordWebDataService* service,
PrefService* prefs,
search_engines::SearchEngineChoiceService* search_engine_choice_service,
TemplateURLService::OwnedTemplateURLVector* template_urls,
TemplateURL* default_search_provider,
const SearchTermsData& search_terms_data,
WDKeywordsResult::Metadata& in_out_keywords_metadata,
std::set<std::string>* removed_keyword_guids) { … }
bool DeDupeEncodings(std::vector<std::string>* encodings) { … }
TemplateURLService::OwnedTemplateURLVector::iterator FindTemplateURL(
TemplateURLService::OwnedTemplateURLVector* urls,
const TemplateURL* url) { … }