#include <locale.h>
#endif
-#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
#include "chrome/browser/search_engines/search_terms_data.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
// Belgium
const PrepopulatedEngine* engines_BE[] =
- { &google, &bing_nl_BE, &bing_fr_BE, &yahoo_be, &yahoo_fr_be, };
+ { &google, &bing_nl_BE, &bing_fr_BE, &yahoo, &yahoo_fr, };
// Bulgaria
const PrepopulatedEngine* engines_BG[] =
// China
const PrepopulatedEngine* engines_CN[] =
- { &google, &baidu, &sogou, &soso, };
+ { &google, &baidu, &sogou, };
// Colombia
const PrepopulatedEngine* engines_CO[] =
// South Korea
const PrepopulatedEngine* engines_KR[] =
- { &google, &naver, &daum, &nate, };
+ { &google, &naver, &daum, };
// Kazakhstan
const PrepopulatedEngine* engines_KZ[] =
// Turkey
const PrepopulatedEngine* engines_TR[] =
- { &google, &bing_tr_TR, &yahoo_tr, };
+ { &google, &bing_tr_TR, &yahoo_tr, &yandex_tr, };
// Trinidad and Tobago
const PrepopulatedEngine* engines_TT[] =
// South Africa
const PrepopulatedEngine* engines_ZA[] =
- { &google, &bing, &yahoo_za, };
+ { &google, &bing, &yahoo, };
// Zimbabwe
const PrepopulatedEngine* engines_ZW[] =
&bing_fr_FR, &bing_it_IT, &bing_ja_JP, &bing_lv_LV, &bing_nb_NO,
&bing_nl_BE, &bing_pl_PL, &bing_pt_BR, &bing_pt_PT, &bing_ru_RU,
&bing_sv_SE, &bing_tr_TR, &bing_zh_HK, &bing_zh_TW, &daum,
- &google, &kvasir, &mail_ru, &najdi, &nate,
- &naver, &onet, &seznam, &sogou, &soso,
- &vinden, &virgilio, &yahoo, &yahoo_ar, &yahoo_at,
- &yahoo_au, &yahoo_be, &yahoo_br, &yahoo_ca, &yahoo_ch,
- &yahoo_cl, &yahoo_co, &yahoo_de, &yahoo_dk, &yahoo_es,
- &yahoo_fi, &yahoo_fr, &yahoo_fr_be, &yahoo_gr, &yahoo_hk,
- &yahoo_id, &yahoo_in, &yahoo_jp, &yahoo_maktoob, &yahoo_mx,
- &yahoo_my, &yahoo_nl, &yahoo_nz, &yahoo_pe, &yahoo_ph,
- &yahoo_qc, &yahoo_ro, &yahoo_ru, &yahoo_se, &yahoo_sg,
- &yahoo_th, &yahoo_tr, &yahoo_tw, &yahoo_uk, &yahoo_ve,
- &yahoo_vn, &yahoo_za, &yandex_ru, &yandex_ua,
+ &google, &kvasir, &mail_ru, &najdi, &naver,
+ &onet, &seznam, &sogou, &vinden, &virgilio,
+ &yahoo, &yahoo_ar, &yahoo_at, &yahoo_au, &yahoo_br,
+ &yahoo_ca, &yahoo_ch, &yahoo_cl, &yahoo_co, &yahoo_de,
+ &yahoo_dk, &yahoo_es, &yahoo_fi, &yahoo_fr, &yahoo_gr,
+ &yahoo_hk, &yahoo_id, &yahoo_in, &yahoo_jp, &yahoo_maktoob,
+ &yahoo_mx, &yahoo_my, &yahoo_nl, &yahoo_nz, &yahoo_pe,
+ &yahoo_ph, &yahoo_qc, &yahoo_ro, &yahoo_ru, &yahoo_se,
+ &yahoo_sg, &yahoo_th, &yahoo_tr, &yahoo_tw, &yahoo_uk,
+ &yahoo_ve, &yahoo_vn, &yandex_ru, &yandex_tr, &yandex_ua,
// UMA-only engines:
&atlas_cz, &atlas_sk, &avg, &babylon, &conduit,
&neti, &nigma, &ok, &rambler, &sapo,
&search_results, &searchnu, &snapdo, &softonic, &sweetim,
&terra_ar, &terra_es, &tut, &walla, &wp,
- &yandex_tr, &zoznam,
+ &zoznam,
};
const struct LogoURLs {
#endif // OS_*
int GetCountryIDFromPrefs(PrefService* prefs) {
- // See if the user overrode the country on the command line.
- const std::string country(
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kCountry));
- if (country.length() == 2)
- return CountryCharsToCountryIDWithUpdate(country[0], country[1]);
+ if (!prefs)
+ return GetCurrentCountryID();
// Cache first run Country ID value in prefs, and use it afterwards. This
// ensures that just because the user moves around, we won't automatically
// make major changes to their available search providers, which would feel
// surprising.
- if (!prefs)
- return GetCurrentCountryID();
-
- int new_country_id = GetCurrentCountryID();
+ if (!prefs->HasPrefPath(prefs::kCountryIDAtInstall)) {
+ int new_country_id = GetCurrentCountryID();
#if defined(OS_WIN)
- // Migrate the old platform-specific value if it's present.
- if (prefs->HasPrefPath(prefs::kGeoIDAtInstall)) {
- int geo_id = prefs->GetInteger(prefs::kGeoIDAtInstall);
- prefs->ClearPref(prefs::kGeoIDAtInstall);
- new_country_id = GeoIDToCountryID(geo_id);
- }
+ // Migrate the old platform-specific value if it's present.
+ if (prefs->HasPrefPath(prefs::kGeoIDAtInstall)) {
+ int geo_id = prefs->GetInteger(prefs::kGeoIDAtInstall);
+ prefs->ClearPref(prefs::kGeoIDAtInstall);
+ new_country_id = GeoIDToCountryID(geo_id);
+ }
#endif
-
- if (!prefs->HasPrefPath(prefs::kCountryIDAtInstall))
prefs->SetInteger(prefs::kCountryIDAtInstall, new_country_id);
-
+ }
return prefs->GetInteger(prefs::kCountryIDAtInstall);
}
}
}
-TemplateURL* MakePrepopulatedTemplateURL(
- Profile* profile,
- const string16& name,
- const string16& keyword,
+scoped_ptr<TemplateURLData> MakePrepopulatedTemplateURLData(
+ const base::string16& name,
+ const base::string16& keyword,
const base::StringPiece& search_url,
const base::StringPiece& suggest_url,
const base::StringPiece& instant_url,
const base::StringPiece& image_url_post_params,
const base::StringPiece& favicon_url,
const base::StringPiece& encoding,
- const ListValue& alternate_urls,
+ const base::ListValue& alternate_urls,
const base::StringPiece& search_terms_replacement_key,
int id) {
-
- TemplateURLData data;
-
- data.short_name = name;
- data.SetKeyword(keyword);
- data.SetURL(search_url.as_string());
- data.suggestions_url = suggest_url.as_string();
- data.instant_url = instant_url.as_string();
- data.image_url = image_url.as_string();
- data.new_tab_url = new_tab_url.as_string();
- data.search_url_post_params = search_url_post_params.as_string();
- data.suggestions_url_post_params = suggest_url_post_params.as_string();
- data.instant_url_post_params = instant_url_post_params.as_string();
- data.image_url_post_params = image_url_post_params.as_string();
- data.favicon_url = GURL(favicon_url.as_string());
- data.show_in_default_list = true;
- data.safe_for_autoreplace = true;
- data.input_encodings.push_back(encoding.as_string());
- data.date_created = base::Time();
- data.last_modified = base::Time();
- data.prepopulate_id = id;
+ scoped_ptr<TemplateURLData> data(new TemplateURLData);
+
+ data->short_name = name;
+ data->SetKeyword(keyword);
+ data->SetURL(search_url.as_string());
+ data->suggestions_url = suggest_url.as_string();
+ data->instant_url = instant_url.as_string();
+ data->image_url = image_url.as_string();
+ data->new_tab_url = new_tab_url.as_string();
+ data->search_url_post_params = search_url_post_params.as_string();
+ data->suggestions_url_post_params = suggest_url_post_params.as_string();
+ data->instant_url_post_params = instant_url_post_params.as_string();
+ data->image_url_post_params = image_url_post_params.as_string();
+ data->favicon_url = GURL(favicon_url.as_string());
+ data->show_in_default_list = true;
+ data->safe_for_autoreplace = true;
+ data->input_encodings.push_back(encoding.as_string());
+ data->date_created = base::Time();
+ data->last_modified = base::Time();
+ data->prepopulate_id = id;
for (size_t i = 0; i < alternate_urls.GetSize(); ++i) {
std::string alternate_url;
alternate_urls.GetString(i, &alternate_url);
DCHECK(!alternate_url.empty());
- data.alternate_urls.push_back(alternate_url);
+ data->alternate_urls.push_back(alternate_url);
}
- data.search_terms_replacement_key = search_terms_replacement_key.as_string();
- return new TemplateURL(profile, data);
+ data->search_terms_replacement_key = search_terms_replacement_key.as_string();
+ return data.Pass();
}
-ScopedVector<TemplateURL> GetPrepopulatedTemplateFromPrefs(Profile* profile) {
- ScopedVector<TemplateURL> t_urls;
- if (!profile)
+ScopedVector<TemplateURLData> GetPrepopulatedTemplateURLData(
+ PrefService* prefs) {
+ ScopedVector<TemplateURLData> t_urls;
+ if (!prefs)
return t_urls.Pass();
- const ListValue* list =
- profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides);
+ const base::ListValue* list = prefs->GetList(prefs::kSearchProviderOverrides);
if (!list)
return t_urls.Pass();
size_t num_engines = list->GetSize();
for (size_t i = 0; i != num_engines; ++i) {
- const DictionaryValue* engine;
- string16 name;
- string16 keyword;
+ const base::DictionaryValue* engine;
+ base::string16 name;
+ base::string16 keyword;
std::string search_url;
std::string favicon_url;
std::string encoding;
std::string suggest_url_post_params;
std::string instant_url_post_params;
std::string image_url_post_params;
- ListValue empty_list;
- const ListValue* alternate_urls = &empty_list;
+ base::ListValue empty_list;
+ const base::ListValue* alternate_urls = &empty_list;
std::string search_terms_replacement_key;
engine->GetString("suggest_url", &suggest_url);
engine->GetString("instant_url", &instant_url);
engine->GetList("alternate_urls", &alternate_urls);
engine->GetString("search_terms_replacement_key",
&search_terms_replacement_key);
- t_urls.push_back(MakePrepopulatedTemplateURL(profile, name, keyword,
+ t_urls.push_back(MakePrepopulatedTemplateURLData(name, keyword,
search_url, suggest_url, instant_url, image_url, new_tab_url,
search_url_post_params, suggest_url_post_params,
instant_url_post_params, image_url_post_params,
favicon_url, encoding, *alternate_urls, search_terms_replacement_key,
- id));
+ id).release());
}
}
return t_urls.Pass();
}
-// The caller owns the returned TemplateURL.
-TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine(
- Profile* profile,
- const PrepopulatedEngine& engine) {
-
- ListValue alternate_urls;
+scoped_ptr<TemplateURLData>
+ MakePrepopulatedTemplateURLDataFromPrepopulateEngine(
+ const PrepopulatedEngine& engine) {
+ base::ListValue alternate_urls;
if (engine.alternate_urls) {
for (size_t i = 0; i < engine.alternate_urls_size; ++i)
alternate_urls.AppendString(std::string(engine.alternate_urls[i]));
}
- return MakePrepopulatedTemplateURL(profile, WideToUTF16(engine.name),
- WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url,
- engine.instant_url, engine.image_url, engine.new_tab_url,
- engine.search_url_post_params, engine.suggest_url_post_params,
- engine.instant_url_post_params, engine.image_url_post_params,
- engine.favicon_url, engine.encoding, alternate_urls,
- engine.search_terms_replacement_key, engine.id);
+ return MakePrepopulatedTemplateURLData(base::WideToUTF16(engine.name),
+ base::WideToUTF16(engine.keyword),
+ engine.search_url,
+ engine.suggest_url,
+ engine.instant_url,
+ engine.image_url,
+ engine.new_tab_url,
+ engine.search_url_post_params,
+ engine.suggest_url_post_params,
+ engine.instant_url_post_params,
+ engine.image_url_post_params,
+ engine.favicon_url,
+ engine.encoding,
+ alternate_urls,
+ engine.search_terms_replacement_key,
+ engine.id);
}
bool SameDomain(const GURL& given_url, const GURL& prepopulated_url) {
kCurrentDataVersion;
}
-ScopedVector<TemplateURL> GetPrepopulatedEngines(
- Profile* profile, size_t* default_search_provider_index) {
+ScopedVector<TemplateURLData> GetPrepopulatedEngines(
+ PrefService* prefs,
+ size_t* default_search_provider_index) {
// If there is a set of search engines in the preferences file, it overrides
// the built-in set.
*default_search_provider_index = 0;
- ScopedVector<TemplateURL> t_urls = GetPrepopulatedTemplateFromPrefs(profile);
+ ScopedVector<TemplateURLData> t_urls = GetPrepopulatedTemplateURLData(prefs);
if (!t_urls.empty())
return t_urls.Pass();
const PrepopulatedEngine** engines;
size_t num_engines;
- GetPrepopulationSetFromCountryID(profile ? profile->GetPrefs() : NULL,
- &engines, &num_engines);
+ GetPrepopulationSetFromCountryID(prefs, &engines, &num_engines);
for (size_t i = 0; i != num_engines; ++i) {
- t_urls.push_back(
- MakePrepopulatedTemplateURLFromPrepopulateEngine(profile, *engines[i]));
+ t_urls.push_back(MakePrepopulatedTemplateURLDataFromPrepopulateEngine(
+ *engines[i]).release());
}
return t_urls.Pass();
}
-void ClearPrepopulatedEnginesInPrefs(Profile* profile) {
- if (!profile)
+void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) {
+ if (!prefs)
return;
- PrefService* prefs = profile->GetPrefs();
- DCHECK(prefs);
prefs->ClearPref(prefs::kSearchProviderOverrides);
prefs->ClearPref(prefs::kSearchProviderOverridesVersion);
}
-TemplateURL* GetPrepopulatedDefaultSearch(Profile* profile) {
- TemplateURL* default_search_provider = NULL;
+scoped_ptr<TemplateURLData> GetPrepopulatedDefaultSearch(PrefService* prefs) {
+ scoped_ptr<TemplateURLData> default_search_provider;
size_t default_search_index;
// This could be more efficient. We are loading all the URLs to only keep
// the first one.
- ScopedVector<TemplateURL> loaded_urls = GetPrepopulatedEngines(
- profile, &default_search_index);
+ ScopedVector<TemplateURLData> loaded_urls =
+ GetPrepopulatedEngines(prefs, &default_search_index);
if (default_search_index < loaded_urls.size()) {
- default_search_provider = loaded_urls[default_search_index];
+ default_search_provider.reset(loaded_urls[default_search_index]);
loaded_urls.weak_erase(loaded_urls.begin() + default_search_index);
}
- return default_search_provider;
+ return default_search_provider.Pass();
}
SearchEngineType GetEngineType(const TemplateURL& url) {
// can't be directly inspected (e.g. due to containing {google:baseURL}) can
// be converted to GURLs we can look at.
GURL gurl(url.url_ref().ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs(
- ASCIIToUTF16("x"))));
+ base::ASCIIToUTF16("x"))));
return gurl.is_valid() ? GetEngineType(gurl) : SEARCH_ENGINE_OTHER;
}