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

Side by Side Diff: components/search_engines/template_url_service.cc

Issue 2682453002: Changed keywords conflicts resolution for extensions search engines. (Closed)
Patch Set: Updated after review, round 3 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 unified diff | Download patch
OLDNEW
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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // The meaningful keyword length is the length of any portion before the 181 // The meaningful keyword length is the length of any portion before the
182 // registry ("co.uk") and its preceding dot. 182 // registry ("co.uk") and its preceding dot.
183 return keyword.length() - (registry_length ? (registry_length + 1) : 0); 183 return keyword.length() - (registry_length ? (registry_length + 1) : 0);
184 } 184 }
185 185
186 bool Contains(TemplateURLService::OwnedTemplateURLVector* template_urls, 186 bool Contains(TemplateURLService::OwnedTemplateURLVector* template_urls,
187 TemplateURL* turl) { 187 TemplateURL* turl) {
188 return FindTemplateURL(template_urls, turl) != template_urls->end(); 188 return FindTemplateURL(template_urls, turl) != template_urls->end();
189 } 189 }
190 190
191 bool IsCreatedByExtension(TemplateURL* template_url) { 191 bool IsCreatedByExtension(const TemplateURL* template_url) {
192 return template_url->type() == 192 return template_url->type() ==
193 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION || 193 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION ||
194 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; 194 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
195 } 195 }
196 196
197 } // namespace 197 } // namespace
198 198
199 // TemplateURLService::LessWithPrefix ----------------------------------------- 199 // TemplateURLService::LessWithPrefix -----------------------------------------
200 200
201 class TemplateURLService::LessWithPrefix { 201 class TemplateURLService::LessWithPrefix {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 should_notify = true; 523 should_notify = true;
524 } else { 524 } else {
525 ++i; 525 ++i;
526 } 526 }
527 } 527 }
528 if (should_notify) 528 if (should_notify)
529 NotifyObservers(); 529 NotifyObservers();
530 } 530 }
531 531
532 void TemplateURLService::RegisterOmniboxKeyword( 532 void TemplateURLService::RegisterOmniboxKeyword(
533 const std::string& extension_id, 533 const std::string& extension_id,
534 const std::string& extension_name, 534 const std::string& extension_name,
535 const std::string& keyword, 535 const std::string& keyword,
536 const std::string& template_url_string) { 536 const std::string& template_url_string,
537 const base::Time& extension_install_time) {
537 DCHECK(loaded_); 538 DCHECK(loaded_);
538 539
539 if (FindTemplateURLForExtension(extension_id, 540 if (FindTemplateURLForExtension(extension_id,
540 TemplateURL::OMNIBOX_API_EXTENSION)) 541 TemplateURL::OMNIBOX_API_EXTENSION))
541 return; 542 return;
542 543
543 TemplateURLData data; 544 TemplateURLData data;
544 data.SetShortName(base::UTF8ToUTF16(extension_name)); 545 data.SetShortName(base::UTF8ToUTF16(extension_name));
545 data.SetKeyword(base::UTF8ToUTF16(keyword)); 546 data.SetKeyword(base::UTF8ToUTF16(keyword));
546 data.SetURL(template_url_string); 547 data.SetURL(template_url_string);
547 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info( 548 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info(
548 new TemplateURL::AssociatedExtensionInfo(extension_id)); 549 new TemplateURL::AssociatedExtensionInfo(extension_id));
550 info->install_time = extension_install_time;
549 AddExtensionControlledTURL( 551 AddExtensionControlledTURL(
550 base::MakeUnique<TemplateURL>(data, TemplateURL::OMNIBOX_API_EXTENSION), 552 base::MakeUnique<TemplateURL>(data, TemplateURL::OMNIBOX_API_EXTENSION),
551 std::move(info)); 553 std::move(info));
552 } 554 }
553 555
554 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { 556 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() {
555 TemplateURLVector result; 557 TemplateURLVector result;
556 for (const auto& turl : template_urls_) 558 for (const auto& turl : template_urls_)
557 result.push_back(turl.get()); 559 result.push_back(turl.get());
558 return result; 560 return result;
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 if (i == 0) 1438 if (i == 0)
1437 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); 1439 default_search_manager_.SetUserSelectedDefaultSearchEngine(data);
1438 } 1440 }
1439 } 1441 }
1440 1442
1441 // Request a server check for the correct Google URL if Google is the 1443 // Request a server check for the correct Google URL if Google is the
1442 // default search engine. 1444 // default search engine.
1443 RequestGoogleURLTrackerServerCheckIfNecessary(); 1445 RequestGoogleURLTrackerServerCheckIfNecessary();
1444 } 1446 }
1445 1447
1448 TemplateURL* TemplateURLService::BestEngineForKeyword(TemplateURL* engine1,
1449 TemplateURL* engine2) {
1450 DCHECK(engine1 || engine2);
1451 // If one is nullptr other is better alternative.
1452 if (!engine1)
1453 return engine2;
1454 if (!engine2)
1455 return engine1;
1456
1457 DCHECK_EQ(engine1->keyword(), engine2->keyword());
1458 // We should only have overlapping keywords when at least one comes from
1459 // an extension.
1460 DCHECK(IsCreatedByExtension(engine1) || IsCreatedByExtension(engine2));
1461
1462 // Following ranking is implemented:
1463 // omnibox api keyword > extension search engine > normal engine.
1464 // If both extensions are of same type, latest installed wins.
1465 if (engine2->type() == engine1->type())
vasilii 2017/02/21 13:17:51 Add {}, same below for the multiline statements
Alexander Yashkin 2017/02/21 14:02:21 Done.
1466 return engine1->extension_info_->install_time >
1467 engine2->extension_info_->install_time
1468 ? engine1
1469 : engine2;
1470 // Extension search engine loses to omnibox api keyword but wins on normal
1471 // engine.
1472 if (engine2->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)
1473 return engine1->type() == TemplateURL::OMNIBOX_API_EXTENSION ? engine1
1474 : engine2;
1475 // Omnibox api keyword always wins. Normal engine loses to any extensions
1476 // keywords.
1477 return engine2->type() == TemplateURL::OMNIBOX_API_EXTENSION ? engine2
1478 : engine1;
1479 }
1480
1446 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) { 1481 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
1447 const base::string16& keyword = template_url->keyword(); 1482 const base::string16& keyword = template_url->keyword();
1448 DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword)); 1483 DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword));
1449 if (keyword_to_turl_and_length_[keyword].first == template_url) { 1484 if (keyword_to_turl_and_length_[keyword].first == template_url) {
1450 // We need to check whether the keyword can now be provided by another 1485 // We need to check whether the keyword can now be provided by another
1451 // TemplateURL. See the comments in AddToMaps() for more information on 1486 // TemplateURL. See the comments in AddToMaps() for more information on
1452 // extension keywords and how they can coexist with non-extension keywords. 1487 // extension keywords and how they can coexist with non-extension keywords.
1453 // In the case of more than one extension, we use the most recently 1488 // In the case of more than one extension, we use the most recently
1454 // installed (which will be the most recently added, which will have the 1489 // installed (which will be the most recently added, which will have the
1455 // highest ID). 1490 // highest ID).
1456 TemplateURL* best_fallback = nullptr; 1491 TemplateURL* best_fallback = nullptr;
1457 for (const auto& turl : template_urls_) { 1492 for (const auto& turl : template_urls_) {
1458 // This next statement relies on the fact that there can only be one 1493 if ((turl.get() != template_url) && (turl->keyword() == keyword))
1459 // non-Omnibox API TemplateURL with a given keyword. 1494 best_fallback = BestEngineForKeyword(best_fallback, turl.get());
1460 if ((turl.get() != template_url) && (turl->keyword() == keyword) &&
1461 (!best_fallback ||
1462 (best_fallback->type() != TemplateURL::OMNIBOX_API_EXTENSION) ||
1463 ((turl->type() == TemplateURL::OMNIBOX_API_EXTENSION) &&
1464 (turl->id() > best_fallback->id()))))
1465 best_fallback = turl.get();
1466 } 1495 }
1467 RemoveFromDomainMap(template_url); 1496 RemoveFromDomainMap(template_url);
1468 if (best_fallback) { 1497 if (best_fallback) {
1469 AddToMap(best_fallback); 1498 AddToMap(best_fallback);
1470 AddToDomainMap(best_fallback); 1499 AddToDomainMap(best_fallback);
1471 } else { 1500 } else {
1472 keyword_to_turl_and_length_.erase(keyword); 1501 keyword_to_turl_and_length_.erase(keyword);
1473 } 1502 }
1474 } 1503 }
1475 1504
(...skipping 11 matching lines...) Expand all
1487 void TemplateURLService::AddToMaps(TemplateURL* template_url) { 1516 void TemplateURLService::AddToMaps(TemplateURL* template_url) {
1488 bool template_url_is_omnibox_api = 1517 bool template_url_is_omnibox_api =
1489 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; 1518 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
1490 const base::string16& keyword = template_url->keyword(); 1519 const base::string16& keyword = template_url->keyword();
1491 KeywordToTURLAndMeaningfulLength::const_iterator i = 1520 KeywordToTURLAndMeaningfulLength::const_iterator i =
1492 keyword_to_turl_and_length_.find(keyword); 1521 keyword_to_turl_and_length_.find(keyword);
1493 if (i == keyword_to_turl_and_length_.end()) { 1522 if (i == keyword_to_turl_and_length_.end()) {
1494 AddToMap(template_url); 1523 AddToMap(template_url);
1495 AddToDomainMap(template_url); 1524 AddToDomainMap(template_url);
1496 } else { 1525 } else {
1497 const TemplateURL* existing_url = i->second.first; 1526 TemplateURL* existing_url = i->second.first;
1498 // We should only have overlapping keywords when at least one comes from 1527 if (BestEngineForKeyword(existing_url, template_url) != existing_url) {
1499 // an extension. In that case, the ranking order is:
1500 // Manually-modified keywords > extension keywords > replaceable keywords
1501 // When there are multiple extensions, the last-added wins.
1502 bool existing_url_is_omnibox_api =
1503 existing_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
1504 DCHECK(existing_url_is_omnibox_api || template_url_is_omnibox_api);
1505 if (existing_url_is_omnibox_api ?
1506 !CanReplace(template_url) : CanReplace(existing_url)) {
1507 RemoveFromDomainMap(existing_url); 1528 RemoveFromDomainMap(existing_url);
1508 AddToMap(template_url); 1529 AddToMap(template_url);
1509 AddToDomainMap(template_url); 1530 AddToDomainMap(template_url);
1510 } 1531 }
1511 } 1532 }
1512 1533
1513 if (template_url_is_omnibox_api) 1534 if (template_url_is_omnibox_api)
1514 return; 1535 return;
1515 1536
1516 if (!template_url->sync_guid().empty()) 1537 if (!template_url->sync_guid().empty())
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1665 }
1645 return nullptr; 1666 return nullptr;
1646 } 1667 }
1647 1668
1648 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, 1669 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
1649 const TemplateURL& new_values) { 1670 const TemplateURL& new_values) {
1650 DCHECK(existing_turl); 1671 DCHECK(existing_turl);
1651 if (!Contains(&template_urls_, existing_turl)) 1672 if (!Contains(&template_urls_, existing_turl))
1652 return false; 1673 return false;
1653 1674
1654 DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->type()); 1675 DCHECK(!IsCreatedByExtension(existing_turl));
1655 1676
1656 base::string16 old_keyword(existing_turl->keyword()); 1677 base::string16 old_keyword(existing_turl->keyword());
1657 keyword_to_turl_and_length_.erase(old_keyword); 1678 keyword_to_turl_and_length_.erase(old_keyword);
1658 RemoveFromDomainMap(existing_turl); 1679 RemoveFromDomainMap(existing_turl);
1659 if (!existing_turl->sync_guid().empty()) 1680 if (!existing_turl->sync_guid().empty())
1660 guid_to_turl_.erase(existing_turl->sync_guid()); 1681 guid_to_turl_.erase(existing_turl->sync_guid());
1661 1682
1662 // |provider_map_| is only initialized after loading has completed. 1683 // |provider_map_| is only initialized after loading has completed.
1663 if (loaded_) 1684 if (loaded_)
1664 provider_map_->Remove(existing_turl); 1685 provider_map_->Remove(existing_turl);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 } 1976 }
1956 1977
1957 // |default_search_provider_source_| must be set before calling 1978 // |default_search_provider_source_| must be set before calling
1958 // UpdateNoNotify(), since that function needs to know the source of the 1979 // UpdateNoNotify(), since that function needs to know the source of the
1959 // update in question. 1980 // update in question.
1960 default_search_provider_source_ = source; 1981 default_search_provider_source_ = source;
1961 1982
1962 if (!data) { 1983 if (!data) {
1963 default_search_provider_ = nullptr; 1984 default_search_provider_ = nullptr;
1964 } else if (source == DefaultSearchManager::FROM_EXTENSION) { 1985 } else if (source == DefaultSearchManager::FROM_EXTENSION) {
1965 default_search_provider_ = FindMatchingExtensionTemplateURL( 1986 default_search_provider_ = FindMatchingDefaultExtensionTemplateURL(*data);
1966 *data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1967 } else if (source == DefaultSearchManager::FROM_FALLBACK) { 1987 } else if (source == DefaultSearchManager::FROM_FALLBACK) {
1968 default_search_provider_ = 1988 default_search_provider_ =
1969 FindPrepopulatedTemplateURL(data->prepopulate_id); 1989 FindPrepopulatedTemplateURL(data->prepopulate_id);
1970 if (default_search_provider_) { 1990 if (default_search_provider_) {
1971 TemplateURLData update_data(*data); 1991 TemplateURLData update_data(*data);
1972 update_data.sync_guid = default_search_provider_->sync_guid(); 1992 update_data.sync_guid = default_search_provider_->sync_guid();
1973 if (!default_search_provider_->safe_for_autoreplace()) { 1993 if (!default_search_provider_->safe_for_autoreplace()) {
1974 update_data.safe_for_autoreplace = false; 1994 update_data.safe_for_autoreplace = false;
1975 update_data.SetKeyword(default_search_provider_->keyword()); 1995 update_data.SetKeyword(default_search_provider_->keyword());
1976 update_data.SetShortName(default_search_provider_->short_name()); 1996 update_data.SetShortName(default_search_provider_->short_name());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 bool newly_adding) { 2045 bool newly_adding) {
2026 DCHECK(template_url); 2046 DCHECK(template_url);
2027 2047
2028 if (newly_adding) { 2048 if (newly_adding) {
2029 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); 2049 DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
2030 DCHECK(!Contains(&template_urls_, template_url.get())); 2050 DCHECK(!Contains(&template_urls_, template_url.get()));
2031 template_url->data_.id = ++next_id_; 2051 template_url->data_.id = ++next_id_;
2032 } 2052 }
2033 2053
2034 template_url->ResetKeywordIfNecessary(search_terms_data(), false); 2054 template_url->ResetKeywordIfNecessary(search_terms_data(), false);
2035 // Check whether |template_url|'s keyword conflicts with any already in the
2036 // model.
2037 TemplateURL* existing_keyword_turl =
2038 GetTemplateURLForKeyword(template_url->keyword());
2039 2055
2040 // Check whether |template_url|'s keyword conflicts with any already in the 2056 // Check for conflicts between non extension engines keywords.
2041 // model. Note that we can reach here during the loading phase while 2057 if (!IsCreatedByExtension(template_url.get())) {
2042 // processing the template URLs from the web data service. In this case, 2058 // Check whether |template_url|'s keyword conflicts with any already in the
2043 // GetTemplateURLForKeyword() will look not only at what's already in the 2059 // model.
2044 // model, but at the |initial_default_search_provider_|. Since this engine 2060 TemplateURL* existing_turl =
2045 // will presumably also be present in the web data, we need to double-check 2061 FindNonExtensionTemplateURLForKeyword(template_url->keyword());
2046 // that any "pre-existing" entries we find are actually coming from 2062
2047 // |template_urls_|, lest we detect a "conflict" between the 2063 // Check whether |template_url|'s keyword conflicts with any already in the
2048 // |initial_default_search_provider_| and the web data version of itself. 2064 // model. Note that we can reach here during the loading phase while
2049 if (template_url->type() != TemplateURL::OMNIBOX_API_EXTENSION && 2065 // processing the template URLs from the web data service. In this case,
2050 existing_keyword_turl && 2066 // GetTemplateURLForKeyword() will look not only at what's already in the
2051 existing_keyword_turl->type() != TemplateURL::OMNIBOX_API_EXTENSION && 2067 // model, but at the |initial_default_search_provider_|. Since this engine
2052 Contains(&template_urls_, existing_keyword_turl)) { 2068 // will presumably also be present in the web data, we need to double-check
2053 DCHECK_NE(existing_keyword_turl, template_url.get()); 2069 // that any "pre-existing" entries we find are actually coming from
2054 // Only replace one of the TemplateURLs if they are either both extensions, 2070 // |template_urls_|, lest we detect a "conflict" between the
2055 // or both not extensions. 2071 // |initial_default_search_provider_| and the web data version of itself.
2056 bool are_same_type = IsCreatedByExtension(existing_keyword_turl) == 2072 if (existing_turl && Contains(&template_urls_, existing_turl)) {
2057 IsCreatedByExtension(template_url.get()); 2073 DCHECK_NE(existing_turl, template_url.get());
2058 if (CanReplace(existing_keyword_turl) && are_same_type) { 2074 if (CanReplace(existing_turl)) {
2059 RemoveNoNotify(existing_keyword_turl); 2075 RemoveNoNotify(existing_turl);
2060 } else if (CanReplace(template_url.get()) && are_same_type) { 2076 } else if (CanReplace(template_url.get())) {
2061 return nullptr; 2077 return nullptr;
2062 } else { 2078 } else {
2063 base::string16 new_keyword = 2079 base::string16 new_keyword = UniquifyKeyword(*existing_turl, false);
2064 UniquifyKeyword(*existing_keyword_turl, false); 2080 // Resolve keyword conflicts for engines that can not be replaced.
2065 ResetTemplateURLNoNotify(existing_keyword_turl, 2081 // Replace keyword for existing engine.
2066 existing_keyword_turl->short_name(), new_keyword, 2082 ResetTemplateURLNoNotify(existing_turl, existing_turl->short_name(),
2067 existing_keyword_turl->url()); 2083 new_keyword, existing_turl->url());
2084 }
2068 } 2085 }
2069 } 2086 }
2070 TemplateURL* template_url_ptr = template_url.get(); 2087 TemplateURL* template_url_ptr = template_url.get();
2071 template_urls_.push_back(std::move(template_url)); 2088 template_urls_.push_back(std::move(template_url));
2072 AddToMaps(template_url_ptr); 2089 AddToMaps(template_url_ptr);
2073 2090
2074 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) { 2091 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) {
2075 if (web_data_service_.get()) 2092 if (web_data_service_.get())
2076 web_data_service_->AddKeyword(template_url_ptr->data()); 2093 web_data_service_->AddKeyword(template_url_ptr->data());
2077 2094
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 DCHECK(loaded_); 2218 DCHECK(loaded_);
2202 DCHECK(!guid.empty()); 2219 DCHECK(!guid.empty());
2203 2220
2204 TemplateURLData data(url->data()); 2221 TemplateURLData data(url->data());
2205 data.sync_guid = guid; 2222 data.sync_guid = guid;
2206 UpdateNoNotify(url, TemplateURL(data)); 2223 UpdateNoNotify(url, TemplateURL(data));
2207 } 2224 }
2208 2225
2209 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl, 2226 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl,
2210 bool force) { 2227 bool force) {
2228 DCHECK(!IsCreatedByExtension(&turl));
2211 if (!force) { 2229 if (!force) {
2212 // Already unique. 2230 // Already unique.
2213 if (!GetTemplateURLForKeyword(turl.keyword())) 2231 if (!GetTemplateURLForKeyword(turl.keyword()))
2214 return turl.keyword(); 2232 return turl.keyword();
2215 2233
2216 // First, try to return the generated keyword for the TemplateURL (except 2234 // First, try to return the generated keyword for the TemplateURL (except
2217 // for extensions, as their keywords are not associated with their URLs). 2235 // for extensions, as their keywords are not associated with their URLs).
2218 GURL gurl(turl.url()); 2236 GURL gurl(turl.url());
2219 if (gurl.is_valid() && 2237 if (gurl.is_valid()) {
2220 (turl.type() != TemplateURL::OMNIBOX_API_EXTENSION)) {
2221 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl); 2238 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl);
2222 if (!GetTemplateURLForKeyword(keyword_candidate)) 2239 if (!GetTemplateURLForKeyword(keyword_candidate))
2223 return keyword_candidate; 2240 return keyword_candidate;
2224 } 2241 }
2225 } 2242 }
2226 2243
2227 // We try to uniquify the keyword by appending a special character to the end. 2244 // We try to uniquify the keyword by appending a special character to the end.
2228 // This is a best-effort approach where we try to preserve the original 2245 // This is a best-effort approach where we try to preserve the original
2229 // keyword and let the user do what they will after our attempt. 2246 // keyword and let the user do what they will after our attempt.
2230 base::string16 keyword_candidate(turl.keyword()); 2247 base::string16 keyword_candidate(turl.keyword());
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 const std::string& extension_id, 2480 const std::string& extension_id,
2464 TemplateURL::Type type) { 2481 TemplateURL::Type type) {
2465 DCHECK_NE(TemplateURL::NORMAL, type); 2482 DCHECK_NE(TemplateURL::NORMAL, type);
2466 for (const auto& turl : template_urls_) { 2483 for (const auto& turl : template_urls_) {
2467 if (turl->type() == type && turl->GetExtensionId() == extension_id) 2484 if (turl->type() == type && turl->GetExtensionId() == extension_id)
2468 return turl.get(); 2485 return turl.get();
2469 } 2486 }
2470 return nullptr; 2487 return nullptr;
2471 } 2488 }
2472 2489
2473 TemplateURL* TemplateURLService::FindMatchingExtensionTemplateURL( 2490 TemplateURL* TemplateURLService::FindMatchingDefaultExtensionTemplateURL(
2474 const TemplateURLData& data, 2491 const TemplateURLData& data) {
2475 TemplateURL::Type type) {
2476 DCHECK_NE(TemplateURL::NORMAL, type);
2477 for (const auto& turl : template_urls_) { 2492 for (const auto& turl : template_urls_) {
2478 if (turl->type() == type && 2493 if (turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION &&
2494 turl->extension_info_->wants_to_be_default_engine &&
2479 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) 2495 TemplateURL::MatchesData(turl.get(), &data, search_terms_data()))
2480 return turl.get(); 2496 return turl.get();
2481 } 2497 }
2482 return nullptr; 2498 return nullptr;
2483 } 2499 }
2484 2500
2485 void TemplateURLService::UpdateExtensionDefaultSearchEngine() { 2501 void TemplateURLService::UpdateExtensionDefaultSearchEngine() {
2486 TemplateURL* most_recently_intalled_default = nullptr; 2502 TemplateURL* most_recently_intalled_default = nullptr;
2487 for (const auto& turl : template_urls_) { 2503 for (const auto& turl : template_urls_) {
2488 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) && 2504 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) &&
2489 turl->extension_info_->wants_to_be_default_engine && 2505 turl->extension_info_->wants_to_be_default_engine &&
2490 turl->SupportsReplacement(search_terms_data()) && 2506 turl->SupportsReplacement(search_terms_data()) &&
2491 (!most_recently_intalled_default || 2507 (!most_recently_intalled_default ||
2492 (most_recently_intalled_default->extension_info_->install_time < 2508 (most_recently_intalled_default->extension_info_->install_time <
2493 turl->extension_info_->install_time))) 2509 turl->extension_info_->install_time)))
2494 most_recently_intalled_default = turl.get(); 2510 most_recently_intalled_default = turl.get();
2495 } 2511 }
2496 2512
2497 if (most_recently_intalled_default) { 2513 if (most_recently_intalled_default) {
2498 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2514 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2499 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2515 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2500 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2516 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2501 most_recently_intalled_default->data()); 2517 most_recently_intalled_default->data());
2502 } else { 2518 } else {
2503 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2519 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2504 } 2520 }
2505 } 2521 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698