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

Unified Diff: components/search_engines/template_url_service.cc

Issue 2682453002: Changed keywords conflicts resolution for extensions search engines. (Closed)
Patch Set: 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
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..6d19120cd5b746ed0116fcc0831d43be94129530 100644
--- a/components/search_engines/template_url_service.cc
+++ b/components/search_engines/template_url_service.cc
@@ -2041,11 +2041,39 @@ TemplateURL* TemplateURLService::AddNoNotify(
} else if (CanReplace(template_url.get()) && are_same_type) {
return nullptr;
} else {
+ // Resolve keyword conflicts for engines that can not be replaced.
+ // Use following priority while resolving keyword conflicts:
+ // extension default search -> extension search -> normal engines.
+ // By extension we mean NORMAL_CONTROLLED_BY_EXTENSION type of engine, not
+ // the OMNIBOX_API_EXTENSION.
Peter Kasting 2017/02/07 00:42:45 Nit: Might want to say "for engines of the same pr
Alexander Yashkin 2017/02/07 08:09:20 Done
+ bool new_engine_is_default_extension =
+ IsCreatedByExtension(template_url.get()) &&
+ template_url->extension_info_->wants_to_be_default_engine;
+
+ bool old_engine_is_default_extension =
+ IsCreatedByExtension(existing_keyword_turl) &&
+ existing_keyword_turl->extension_info_->wants_to_be_default_engine;
+
+ // The only way we allow old engine to hold its keyword, is if it was
+ // extension installed default engine and new engine is not. And the
+ // second case is if new added engine is normal and old was from
+ // extension.
+ bool new_engine_lose = (old_engine_is_default_extension &&
+ !new_engine_is_default_extension) ||
+ (IsCreatedByExtension(existing_keyword_turl) &&
+ !IsCreatedByExtension(template_url.get()));
+
base::string16 new_keyword =
UniquifyKeyword(*existing_keyword_turl, false);
- ResetTemplateURLNoNotify(existing_keyword_turl,
- existing_keyword_turl->short_name(), new_keyword,
- existing_keyword_turl->url());
+ if (new_engine_lose) {
Peter Kasting 2017/02/07 00:42:45 Nit: If we just do this here: if (IsCreated
Alexander Yashkin 2017/02/07 08:09:20 Done, hope it would be clear to next generations :
+ // Replace keyword for added search engine.
+ template_url->data_.SetKeyword(new_keyword);
+ } else {
+ // Replace keyword for existing engine.
+ ResetTemplateURLNoNotify(existing_keyword_turl,
+ existing_keyword_turl->short_name(),
+ new_keyword, existing_keyword_turl->url());
+ }
}
}
TemplateURL* template_url_ptr = template_url.get();

Powered by Google App Engine
This is Rietveld 408576698