Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(793)

Unified Diff: components/search_engines/template_url_prepopulate_data.cc

Issue 1983773002: Cache SearchEngineType of TemplateURL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-extracting-terms-from-template-url
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/search_engines/template_url_prepopulate_data.cc
diff --git a/components/search_engines/template_url_prepopulate_data.cc b/components/search_engines/template_url_prepopulate_data.cc
index 33a72bbb0ab76f9258a47657267250e161dd1b6f..aeb1681e33258fc3465b6bda8ec0743a2b35c96d 100644
--- a/components/search_engines/template_url_prepopulate_data.cc
+++ b/components/search_engines/template_url_prepopulate_data.cc
@@ -21,7 +21,7 @@
#include "components/prefs/pref_service.h"
#include "components/search_engines/prepopulated_engines.h"
#include "components/search_engines/search_engines_pref_names.h"
-#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_data.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
@@ -985,6 +985,7 @@ std::unique_ptr<TemplateURLData> MakePrepopulatedTemplateURLData(
const base::StringPiece& encoding,
const base::ListValue& alternate_urls,
const base::StringPiece& search_terms_replacement_key,
+ SearchEngineType engine_type,
int id) {
std::unique_ptr<TemplateURLData> data(new TemplateURLData);
@@ -1006,6 +1007,7 @@ std::unique_ptr<TemplateURLData> MakePrepopulatedTemplateURLData(
data->input_encodings.push_back(encoding.as_string());
data->date_created = base::Time();
data->last_modified = base::Time();
+ data->engine_type = engine_type;
data->prepopulate_id = id;
for (size_t i = 0; i < alternate_urls.GetSize(); ++i) {
std::string alternate_url;
@@ -1070,12 +1072,13 @@ ScopedVector<TemplateURLData> GetPrepopulatedTemplateURLData(
engine->GetList("alternate_urls", &alternate_urls);
engine->GetString("search_terms_replacement_key",
&search_terms_replacement_key);
+ const SearchEngineType type = SEARCH_ENGINE_UNKNOWN;
Peter Kasting 2016/05/17 04:43:04 Nit: Inline into next statement
Vitaly Baranov 2016/06/03 15:31:45 Done.
t_urls.push_back(MakePrepopulatedTemplateURLData(name, keyword,
search_url, suggest_url, instant_url, image_url, new_tab_url,
contextual_search_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).release());
+ search_terms_replacement_key, type, id).release());
}
}
return t_urls;
@@ -1140,7 +1143,7 @@ std::unique_ptr<TemplateURLData> MakeTemplateURLDataFromPrepopulatedEngine(
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);
+ engine.search_terms_replacement_key, engine.type, engine.id);
}
void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) {
@@ -1166,16 +1169,6 @@ std::unique_ptr<TemplateURLData> GetPrepopulatedDefaultSearch(
return default_search_provider;
}
-SearchEngineType GetEngineType(const TemplateURL& url,
- const SearchTermsData& search_terms_data) {
- // By calling ReplaceSearchTerms, we ensure that even TemplateURLs whose URLs
- // 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(
- base::ASCIIToUTF16("x")), search_terms_data));
- return gurl.is_valid() ? GetEngineType(gurl) : SEARCH_ENGINE_OTHER;
-}
-
SearchEngineType GetEngineType(const GURL& url) {
DCHECK(url.is_valid());

Powered by Google App Engine
This is Rietveld 408576698