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

Unified Diff: components/search_engines/template_url_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: Move calculation to TemplateURLData Created 4 years, 6 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_data.cc
diff --git a/components/search_engines/template_url_data.cc b/components/search_engines/template_url_data.cc
index f415c7719fcc8e13855f6aa3d8fe43bb305971d7..5e6894f39ef1da3d97778df57bb973d04777f448 100644
--- a/components/search_engines/template_url_data.cc
+++ b/components/search_engines/template_url_data.cc
@@ -9,6 +9,8 @@
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_prepopulate_data.h"
TemplateURLData::TemplateURLData()
: show_in_default_list(false),
@@ -18,6 +20,7 @@ TemplateURLData::TemplateURLData()
last_modified(base::Time::Now()),
created_by_policy(false),
usage_count(0),
+ engine_type_(SEARCH_ENGINE_UNKNOWN),
prepopulate_id(0),
sync_guid(base::GenerateGUID()),
keyword_(base::ASCIIToUTF16("dummy")),
@@ -48,4 +51,25 @@ void TemplateURLData::SetKeyword(const base::string16& keyword) {
void TemplateURLData::SetURL(const std::string& url) {
DCHECK(!url.empty());
url_ = url;
+ engine_type_ = SEARCH_ENGINE_UNKNOWN;
+}
+
+SearchEngineType TemplateURLData::GetEngineType(
+ const SearchTermsData& search_terms_data,
+ const TemplateURL* template_url_hint) const {
+ if (engine_type_ == SEARCH_ENGINE_UNKNOWN) {
+ std::unique_ptr<TemplateURL> temp_template_url;
+ if (!template_url_hint || (&template_url_hint->data() != this)) {
+ temp_template_url.reset(new TemplateURL(*this));
+ template_url_hint = temp_template_url.get();
+ }
+ const GURL url = template_url_hint->GenerateSearchURL(search_terms_data);
+ if (url.is_valid()) {
+ engine_type_ = TemplateURLPrepopulateData::GetEngineType(url);
+ DCHECK_NE(SEARCH_ENGINE_UNKNOWN, engine_type_);
+ } else {
+ engine_type_ = SEARCH_ENGINE_OTHER;
+ }
+ }
+ return engine_type_;
}

Powered by Google App Engine
This is Rietveld 408576698