Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/search_engines/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2034 DCHECK_NE(existing_keyword_turl, template_url.get()); | 2034 DCHECK_NE(existing_keyword_turl, template_url.get()); |
| 2035 // Only replace one of the TemplateURLs if they are either both extensions, | 2035 // Only replace one of the TemplateURLs if they are either both extensions, |
| 2036 // or both not extensions. | 2036 // or both not extensions. |
| 2037 bool are_same_type = IsCreatedByExtension(existing_keyword_turl) == | 2037 bool are_same_type = IsCreatedByExtension(existing_keyword_turl) == |
| 2038 IsCreatedByExtension(template_url.get()); | 2038 IsCreatedByExtension(template_url.get()); |
| 2039 if (CanReplace(existing_keyword_turl) && are_same_type) { | 2039 if (CanReplace(existing_keyword_turl) && are_same_type) { |
| 2040 RemoveNoNotify(existing_keyword_turl); | 2040 RemoveNoNotify(existing_keyword_turl); |
| 2041 } else if (CanReplace(template_url.get()) && are_same_type) { | 2041 } else if (CanReplace(template_url.get()) && are_same_type) { |
| 2042 return nullptr; | 2042 return nullptr; |
| 2043 } else { | 2043 } else { |
| 2044 // Resolve keyword conflicts for engines that can not be replaced. | |
| 2045 // Use following priority while resolving keyword conflicts: | |
| 2046 // extension default search -> extension search -> normal engines. | |
| 2047 // By extension we mean NORMAL_CONTROLLED_BY_EXTENSION type of engine, not | |
| 2048 // 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
| |
| 2049 bool new_engine_is_default_extension = | |
| 2050 IsCreatedByExtension(template_url.get()) && | |
| 2051 template_url->extension_info_->wants_to_be_default_engine; | |
| 2052 | |
| 2053 bool old_engine_is_default_extension = | |
| 2054 IsCreatedByExtension(existing_keyword_turl) && | |
| 2055 existing_keyword_turl->extension_info_->wants_to_be_default_engine; | |
| 2056 | |
| 2057 // The only way we allow old engine to hold its keyword, is if it was | |
| 2058 // extension installed default engine and new engine is not. And the | |
| 2059 // second case is if new added engine is normal and old was from | |
| 2060 // extension. | |
| 2061 bool new_engine_lose = (old_engine_is_default_extension && | |
| 2062 !new_engine_is_default_extension) || | |
| 2063 (IsCreatedByExtension(existing_keyword_turl) && | |
| 2064 !IsCreatedByExtension(template_url.get())); | |
| 2065 | |
| 2044 base::string16 new_keyword = | 2066 base::string16 new_keyword = |
| 2045 UniquifyKeyword(*existing_keyword_turl, false); | 2067 UniquifyKeyword(*existing_keyword_turl, false); |
| 2046 ResetTemplateURLNoNotify(existing_keyword_turl, | 2068 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 :
| |
| 2047 existing_keyword_turl->short_name(), new_keyword, | 2069 // Replace keyword for added search engine. |
| 2048 existing_keyword_turl->url()); | 2070 template_url->data_.SetKeyword(new_keyword); |
| 2071 } else { | |
| 2072 // Replace keyword for existing engine. | |
| 2073 ResetTemplateURLNoNotify(existing_keyword_turl, | |
| 2074 existing_keyword_turl->short_name(), | |
| 2075 new_keyword, existing_keyword_turl->url()); | |
| 2076 } | |
| 2049 } | 2077 } |
| 2050 } | 2078 } |
| 2051 TemplateURL* template_url_ptr = template_url.get(); | 2079 TemplateURL* template_url_ptr = template_url.get(); |
| 2052 template_urls_.push_back(std::move(template_url)); | 2080 template_urls_.push_back(std::move(template_url)); |
| 2053 AddToMaps(template_url_ptr); | 2081 AddToMaps(template_url_ptr); |
| 2054 | 2082 |
| 2055 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) { | 2083 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) { |
| 2056 if (web_data_service_.get()) | 2084 if (web_data_service_.get()) |
| 2057 web_data_service_->AddKeyword(template_url_ptr->data()); | 2085 web_data_service_->AddKeyword(template_url_ptr->data()); |
| 2058 | 2086 |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2477 | 2505 |
| 2478 if (most_recently_intalled_default) { | 2506 if (most_recently_intalled_default) { |
| 2479 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2507 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2480 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2508 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2481 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2509 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2482 most_recently_intalled_default->data()); | 2510 most_recently_intalled_default->data()); |
| 2483 } else { | 2511 } else { |
| 2484 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2512 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2485 } | 2513 } |
| 2486 } | 2514 } |
| OLD | NEW |