| 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..345fbfce260c84e50bc1512a50a8ac069412c7ec 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,21 @@ 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)
|
| + return engine_type_;
|
| + if (data_.engine_type != SEARCH_ENGINE_UNKNOWN) {
|
| + engine_type_ = data_.engine_type;
|
| + return engine_type_;
|
| + }
|
| + const GURL url = GenerateSearchURL(search_terms_data);
|
| + engine_type_ = url.is_valid() ?
|
| + TemplateURLPrepopulateData::GetEngineType(url) : SEARCH_ENGINE_OTHER;
|
| + DCHECK_NE(SEARCH_ENGINE_UNKNOWN, engine_type_);
|
| + return engine_type_;
|
| +}
|
| +
|
| bool TemplateURL::ExtractSearchTermsFromURL(
|
| const GURL& url,
|
| const SearchTermsData& search_terms_data,
|
| @@ -1469,7 +1486,9 @@ void TemplateURL::CopyFrom(const TemplateURL& other) {
|
|
|
| void TemplateURL::SetURL(const std::string& url) {
|
| data_.SetURL(url);
|
| + data_.engine_type = SEARCH_ENGINE_UNKNOWN;
|
| url_ref_->InvalidateCachedValues();
|
| + engine_type_ = SEARCH_ENGINE_UNKNOWN;
|
| }
|
|
|
| void TemplateURL::SetPrepopulateId(int id) {
|
| @@ -1499,6 +1518,7 @@ void TemplateURL::InvalidateCachedValues() const {
|
| image_url_ref_.InvalidateCachedValues();
|
| new_tab_url_ref_.InvalidateCachedValues();
|
| contextual_search_url_ref_.InvalidateCachedValues();
|
| + engine_type_ = SEARCH_ENGINE_UNKNOWN;
|
| }
|
|
|
| void TemplateURL::ResizeURLRefVector() {
|
|
|