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

Unified Diff: components/search_engines/template_url.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 engine_type_ to TemplateURL 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
« no previous file with comments | « components/search_engines/template_url.h ('k') | components/search_engines/template_url_prepopulate_data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/search_engines/template_url.cc
diff --git a/components/search_engines/template_url.cc b/components/search_engines/template_url.cc
index 2a1cb2109533d7cead63dc5a25e9faf54a088da7..05fcae344bd8e30ca9c551f0744e11e5ded701fe 100644
--- a/components/search_engines/template_url.cc
+++ b/components/search_engines/template_url.cc
@@ -25,6 +25,7 @@
#include "components/metrics/proto/omnibox_input_type.pb.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_terms_data.h"
+#include "components/search_engines/template_url_prepopulate_data.h"
#include "components/url_formatter/url_formatter.h"
#include "google_apis/google_api_keys.h"
#include "net/base/escape.h"
@@ -1204,7 +1205,8 @@ TemplateURL::TemplateURL(const TemplateURLData& data)
TemplateURLRef::INSTANT),
image_url_ref_(this, TemplateURLRef::IMAGE),
new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
- contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH) {
+ contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH),
+ engine_type_(SEARCH_ENGINE_UNKNOWN) {
ResizeURLRefVector();
SetPrepopulateId(data_.prepopulate_id);
@@ -1332,6 +1334,20 @@ std::string TemplateURL::GetExtensionId() const {
return extension_info_->extension_id;
}
+SearchEngineType TemplateURL::GetEngineType(
+ const SearchTermsData& search_terms_data) const {
+ if (engine_type_ == SEARCH_ENGINE_UNKNOWN) {
+ const GURL url = 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;
+ }
Peter Kasting 2016/06/12 10:42:17 Nit: Shorter: engine_type_ = url.is_valid() ?
Vitaly Baranov 2016/06/13 09:43:35 Done.
+ }
+ return engine_type_;
+}
+
bool TemplateURL::ExtractSearchTermsFromURL(
const GURL& url,
const SearchTermsData& search_terms_data,
@@ -1469,6 +1485,7 @@ void TemplateURL::CopyFrom(const TemplateURL& other) {
void TemplateURL::SetURL(const std::string& url) {
data_.SetURL(url);
+ engine_type_ = SEARCH_ENGINE_UNKNOWN;
url_ref_->InvalidateCachedValues();
}
« no previous file with comments | « components/search_engines/template_url.h ('k') | components/search_engines/template_url_prepopulate_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698