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_service.cc

Issue 2682453002: Changed keywords conflicts resolution for extensions search engines. (Closed)
Patch Set: Rebase on master Created 3 years, 10 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_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/search_engines/template_url_service.cc
diff --git a/components/search_engines/template_url_service.cc b/components/search_engines/template_url_service.cc
index 0e77d27379f265169564fc3bb4cf7eff964c7a4f..70a97910235e9f646ed44a8c815ade270534ce6c 100644
--- a/components/search_engines/template_url_service.cc
+++ b/components/search_engines/template_url_service.cc
@@ -2015,7 +2015,7 @@ TemplateURL* TemplateURLService::AddNoNotify(
template_url->ResetKeywordIfNecessary(search_terms_data(), false);
// Check whether |template_url|'s keyword conflicts with any already in the
// model.
- TemplateURL* existing_keyword_turl =
+ TemplateURL* existing_turl =
GetTemplateURLForKeyword(template_url->keyword());
// Check whether |template_url|'s keyword conflicts with any already in the
@@ -2028,24 +2028,37 @@ TemplateURL* TemplateURLService::AddNoNotify(
// |template_urls_|, lest we detect a "conflict" between the
// |initial_default_search_provider_| and the web data version of itself.
if (template_url->type() != TemplateURL::OMNIBOX_API_EXTENSION &&
- existing_keyword_turl &&
- existing_keyword_turl->type() != TemplateURL::OMNIBOX_API_EXTENSION &&
- Contains(&template_urls_, existing_keyword_turl)) {
- DCHECK_NE(existing_keyword_turl, template_url.get());
+ existing_turl &&
+ existing_turl->type() != TemplateURL::OMNIBOX_API_EXTENSION &&
+ Contains(&template_urls_, existing_turl)) {
+ DCHECK_NE(existing_turl, template_url.get());
// Only replace one of the TemplateURLs if they are either both extensions,
// or both not extensions.
- bool are_same_type = IsCreatedByExtension(existing_keyword_turl) ==
+ bool are_same_type = IsCreatedByExtension(existing_turl) ==
IsCreatedByExtension(template_url.get());
- if (CanReplace(existing_keyword_turl) && are_same_type) {
- RemoveNoNotify(existing_keyword_turl);
+ if (CanReplace(existing_turl) && are_same_type) {
+ RemoveNoNotify(existing_turl);
} else if (CanReplace(template_url.get()) && are_same_type) {
return nullptr;
} else {
- base::string16 new_keyword =
- UniquifyKeyword(*existing_keyword_turl, false);
- ResetTemplateURLNoNotify(existing_keyword_turl,
- existing_keyword_turl->short_name(), new_keyword,
- existing_keyword_turl->url());
+ // Resolve keyword conflicts for engines that can not be replaced.
+ // Use following priority while resolving keyword conflicts:
+ // extension default search -> extension search -> normal engines.
+ // For engines of the same priority, the newly-added one wins.
+ // By extension we mean NORMAL_CONTROLLED_BY_EXTENSION type of engine, not
+ // the OMNIBOX_API_EXTENSION.
vasilii 2017/02/07 16:27:21 I'm confused by the algorithm because I thought we
Alexander Yashkin 2017/02/07 16:50:11 I have understood differently, especially Peter's
+ base::string16 new_keyword = UniquifyKeyword(*existing_turl, false);
+ if (IsCreatedByExtension(existing_turl) &&
+ (!IsCreatedByExtension(template_url.get()) ||
+ (existing_turl->extension_info_->wants_to_be_default_engine &&
+ !template_url->extension_info_->wants_to_be_default_engine))) {
+ // Replace keyword for added search engine.
+ template_url->data_.SetKeyword(new_keyword);
+ } else {
+ // Replace keyword for existing engine.
+ ResetTemplateURLNoNotify(existing_turl, existing_turl->short_name(),
+ new_keyword, existing_turl->url());
+ }
}
}
TemplateURL* template_url_ptr = template_url.get();
« no previous file with comments | « components/search_engines/template_url_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698