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

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

Issue 2682453002: Changed keywords conflicts resolution for extensions search engines. (Closed)
Patch Set: Fixed auto variable type must not deduce to a raw pointer type 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
« no previous file with comments | « components/search_engines/template_url_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
1451 DCHECK(engine2);
1452 DCHECK_EQ(engine1->keyword(), engine2->keyword());
1453 // We should only have overlapping keywords when at least one comes from
1454 // an extension.
1455 DCHECK(IsCreatedByExtension(engine1) || IsCreatedByExtension(engine2));
1456
1457 if (engine2->type() == engine1->type()) {
1458 return engine1->extension_info_->install_time >
1459 engine2->extension_info_->install_time
1460 ? engine1
1461 : engine2;
1462 }
1463 if (engine2->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) {
1464 return engine1->type() == TemplateURL::OMNIBOX_API_EXTENSION ? engine1
1465 : engine2;
1466 }
1467 return engine2->type() == TemplateURL::OMNIBOX_API_EXTENSION ? engine2
1468 : engine1;
1469 }
1470
1446 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) { 1471 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
1447 const base::string16& keyword = template_url->keyword(); 1472 const base::string16& keyword = template_url->keyword();
1448 DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword)); 1473 DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword));
1449 if (keyword_to_turl_and_length_[keyword].first == template_url) { 1474 if (keyword_to_turl_and_length_[keyword].first == template_url) {
1450 // We need to check whether the keyword can now be provided by another 1475 // We need to check whether the keyword can now be provided by another
1451 // TemplateURL. See the comments in AddToMaps() for more information on 1476 // TemplateURL. See the comments in AddToMaps() for more information on
1452 // extension keywords and how they can coexist with non-extension keywords. 1477 // 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 1478 // 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 1479 // installed (which will be the most recently added, which will have the
1455 // highest ID). 1480 // highest ID).
1456 TemplateURL* best_fallback = nullptr; 1481 TemplateURL* best_fallback = nullptr;
1457 for (const auto& turl : template_urls_) { 1482 for (const auto& turl : template_urls_) {
1458 // This next statement relies on the fact that there can only be one 1483 if ((turl.get() != template_url) && (turl->keyword() == keyword)) {
1459 // non-Omnibox API TemplateURL with a given keyword. 1484 if (best_fallback)
1460 if ((turl.get() != template_url) && (turl->keyword() == keyword) && 1485 best_fallback = BestEngineForKeyword(best_fallback, turl.get());
1461 (!best_fallback || 1486 else
1462 (best_fallback->type() != TemplateURL::OMNIBOX_API_EXTENSION) || 1487 best_fallback = turl.get();
1463 ((turl->type() == TemplateURL::OMNIBOX_API_EXTENSION) && 1488 }
1464 (turl->id() > best_fallback->id()))))
1465 best_fallback = turl.get();
1466 } 1489 }
1467 RemoveFromDomainMap(template_url); 1490 RemoveFromDomainMap(template_url);
1468 if (best_fallback) { 1491 if (best_fallback) {
1469 AddToMap(best_fallback); 1492 AddToMap(best_fallback);
1470 AddToDomainMap(best_fallback); 1493 AddToDomainMap(best_fallback);
1471 } else { 1494 } else {
1472 keyword_to_turl_and_length_.erase(keyword); 1495 keyword_to_turl_and_length_.erase(keyword);
1473 } 1496 }
1474 } 1497 }
1475 1498
(...skipping 11 matching lines...) Expand all
1487 void TemplateURLService::AddToMaps(TemplateURL* template_url) { 1510 void TemplateURLService::AddToMaps(TemplateURL* template_url) {
1488 bool template_url_is_omnibox_api = 1511 bool template_url_is_omnibox_api =
1489 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; 1512 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
1490 const base::string16& keyword = template_url->keyword(); 1513 const base::string16& keyword = template_url->keyword();
1491 KeywordToTURLAndMeaningfulLength::const_iterator i = 1514 KeywordToTURLAndMeaningfulLength::const_iterator i =
1492 keyword_to_turl_and_length_.find(keyword); 1515 keyword_to_turl_and_length_.find(keyword);
1493 if (i == keyword_to_turl_and_length_.end()) { 1516 if (i == keyword_to_turl_and_length_.end()) {
1494 AddToMap(template_url); 1517 AddToMap(template_url);
1495 AddToDomainMap(template_url); 1518 AddToDomainMap(template_url);
1496 } else { 1519 } else {
1497 const TemplateURL* existing_url = i->second.first; 1520 TemplateURL* existing_url = i->second.first;
1498 // We should only have overlapping keywords when at least one comes from 1521 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); 1522 RemoveFromDomainMap(existing_url);
1508 AddToMap(template_url); 1523 AddToMap(template_url);
1509 AddToDomainMap(template_url); 1524 AddToDomainMap(template_url);
1510 } 1525 }
1511 } 1526 }
1512 1527
1513 if (template_url_is_omnibox_api) 1528 if (template_url_is_omnibox_api)
1514 return; 1529 return;
1515 1530
1516 if (!template_url->sync_guid().empty()) 1531 if (!template_url->sync_guid().empty())
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1659 }
1645 return nullptr; 1660 return nullptr;
1646 } 1661 }
1647 1662
1648 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, 1663 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
1649 const TemplateURL& new_values) { 1664 const TemplateURL& new_values) {
1650 DCHECK(existing_turl); 1665 DCHECK(existing_turl);
1651 if (!Contains(&template_urls_, existing_turl)) 1666 if (!Contains(&template_urls_, existing_turl))
1652 return false; 1667 return false;
1653 1668
1654 DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->type()); 1669 DCHECK(!IsCreatedByExtension(existing_turl));
1655 1670
1656 base::string16 old_keyword(existing_turl->keyword()); 1671 base::string16 old_keyword(existing_turl->keyword());
1657 keyword_to_turl_and_length_.erase(old_keyword); 1672 keyword_to_turl_and_length_.erase(old_keyword);
1658 RemoveFromDomainMap(existing_turl); 1673 RemoveFromDomainMap(existing_turl);
1659 if (!existing_turl->sync_guid().empty()) 1674 if (!existing_turl->sync_guid().empty())
1660 guid_to_turl_.erase(existing_turl->sync_guid()); 1675 guid_to_turl_.erase(existing_turl->sync_guid());
1661 1676
1662 // |provider_map_| is only initialized after loading has completed. 1677 // |provider_map_| is only initialized after loading has completed.
1663 if (loaded_) 1678 if (loaded_)
1664 provider_map_->Remove(existing_turl); 1679 provider_map_->Remove(existing_turl);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 } 1970 }
1956 1971
1957 // |default_search_provider_source_| must be set before calling 1972 // |default_search_provider_source_| must be set before calling
1958 // UpdateNoNotify(), since that function needs to know the source of the 1973 // UpdateNoNotify(), since that function needs to know the source of the
1959 // update in question. 1974 // update in question.
1960 default_search_provider_source_ = source; 1975 default_search_provider_source_ = source;
1961 1976
1962 if (!data) { 1977 if (!data) {
1963 default_search_provider_ = nullptr; 1978 default_search_provider_ = nullptr;
1964 } else if (source == DefaultSearchManager::FROM_EXTENSION) { 1979 } else if (source == DefaultSearchManager::FROM_EXTENSION) {
1965 default_search_provider_ = FindMatchingExtensionTemplateURL( 1980 default_search_provider_ = FindMatchingDefaultExtensionTemplateURL(*data);
1966 *data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1967 } else if (source == DefaultSearchManager::FROM_FALLBACK) { 1981 } else if (source == DefaultSearchManager::FROM_FALLBACK) {
1968 default_search_provider_ = 1982 default_search_provider_ =
1969 FindPrepopulatedTemplateURL(data->prepopulate_id); 1983 FindPrepopulatedTemplateURL(data->prepopulate_id);
1970 if (default_search_provider_) { 1984 if (default_search_provider_) {
1971 TemplateURLData update_data(*data); 1985 TemplateURLData update_data(*data);
1972 update_data.sync_guid = default_search_provider_->sync_guid(); 1986 update_data.sync_guid = default_search_provider_->sync_guid();
1973 if (!default_search_provider_->safe_for_autoreplace()) { 1987 if (!default_search_provider_->safe_for_autoreplace()) {
1974 update_data.safe_for_autoreplace = false; 1988 update_data.safe_for_autoreplace = false;
1975 update_data.SetKeyword(default_search_provider_->keyword()); 1989 update_data.SetKeyword(default_search_provider_->keyword());
1976 update_data.SetShortName(default_search_provider_->short_name()); 1990 update_data.SetShortName(default_search_provider_->short_name());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 bool newly_adding) { 2039 bool newly_adding) {
2026 DCHECK(template_url); 2040 DCHECK(template_url);
2027 2041
2028 if (newly_adding) { 2042 if (newly_adding) {
2029 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); 2043 DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
2030 DCHECK(!Contains(&template_urls_, template_url.get())); 2044 DCHECK(!Contains(&template_urls_, template_url.get()));
2031 template_url->data_.id = ++next_id_; 2045 template_url->data_.id = ++next_id_;
2032 } 2046 }
2033 2047
2034 template_url->ResetKeywordIfNecessary(search_terms_data(), false); 2048 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 2049
2040 // Check whether |template_url|'s keyword conflicts with any already in the 2050 // If |template_url| is not created by an extension, its keyword must not
2041 // model. Note that we can reach here during the loading phase while 2051 // conflict with any already in the model.
2042 // processing the template URLs from the web data service. In this case, 2052 if (!IsCreatedByExtension(template_url.get())) {
2043 // GetTemplateURLForKeyword() will look not only at what's already in the 2053 // Note that we can reach here during the loading phase while processing the
2044 // model, but at the |initial_default_search_provider_|. Since this engine 2054 // template URLs from the web data service. In this case,
2045 // will presumably also be present in the web data, we need to double-check 2055 // GetTemplateURLForKeyword() will look not only at what's already in the
2046 // that any "pre-existing" entries we find are actually coming from 2056 // model, but at the |initial_default_search_provider_|. Since this engine
2047 // |template_urls_|, lest we detect a "conflict" between the 2057 // will presumably also be present in the web data, we need to double-check
2048 // |initial_default_search_provider_| and the web data version of itself. 2058 // that any "pre-existing" entries we find are actually coming from
2049 if (template_url->type() != TemplateURL::OMNIBOX_API_EXTENSION && 2059 // |template_urls_|, lest we detect a "conflict" between the
2050 existing_keyword_turl && 2060 // |initial_default_search_provider_| and the web data version of itself.
2051 existing_keyword_turl->type() != TemplateURL::OMNIBOX_API_EXTENSION && 2061 TemplateURL* existing_turl =
2052 Contains(&template_urls_, existing_keyword_turl)) { 2062 FindNonExtensionTemplateURLForKeyword(template_url->keyword());
2053 DCHECK_NE(existing_keyword_turl, template_url.get()); 2063 if (existing_turl && Contains(&template_urls_, existing_turl)) {
2054 // Only replace one of the TemplateURLs if they are either both extensions, 2064 DCHECK_NE(existing_turl, template_url.get());
2055 // or both not extensions. 2065 if (CanReplace(existing_turl)) {
2056 bool are_same_type = IsCreatedByExtension(existing_keyword_turl) == 2066 RemoveNoNotify(existing_turl);
2057 IsCreatedByExtension(template_url.get()); 2067 } else if (CanReplace(template_url.get())) {
2058 if (CanReplace(existing_keyword_turl) && are_same_type) { 2068 return nullptr;
2059 RemoveNoNotify(existing_keyword_turl); 2069 } else {
2060 } else if (CanReplace(template_url.get()) && are_same_type) { 2070 // Neither engine can be replaced. Uniquify the existing keyword.
2061 return nullptr; 2071 base::string16 new_keyword = UniquifyKeyword(*existing_turl, false);
2062 } else { 2072 ResetTemplateURLNoNotify(existing_turl, existing_turl->short_name(),
2063 base::string16 new_keyword = 2073 new_keyword, existing_turl->url());
2064 UniquifyKeyword(*existing_keyword_turl, false); 2074 }
2065 ResetTemplateURLNoNotify(existing_keyword_turl,
2066 existing_keyword_turl->short_name(), new_keyword,
2067 existing_keyword_turl->url());
2068 } 2075 }
2069 } 2076 }
2070 TemplateURL* template_url_ptr = template_url.get(); 2077 TemplateURL* template_url_ptr = template_url.get();
2071 template_urls_.push_back(std::move(template_url)); 2078 template_urls_.push_back(std::move(template_url));
2072 AddToMaps(template_url_ptr); 2079 AddToMaps(template_url_ptr);
2073 2080
2074 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) { 2081 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) {
2075 if (web_data_service_.get()) 2082 if (web_data_service_.get())
2076 web_data_service_->AddKeyword(template_url_ptr->data()); 2083 web_data_service_->AddKeyword(template_url_ptr->data());
2077 2084
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 DCHECK(loaded_); 2208 DCHECK(loaded_);
2202 DCHECK(!guid.empty()); 2209 DCHECK(!guid.empty());
2203 2210
2204 TemplateURLData data(url->data()); 2211 TemplateURLData data(url->data());
2205 data.sync_guid = guid; 2212 data.sync_guid = guid;
2206 UpdateNoNotify(url, TemplateURL(data)); 2213 UpdateNoNotify(url, TemplateURL(data));
2207 } 2214 }
2208 2215
2209 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl, 2216 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl,
2210 bool force) { 2217 bool force) {
2218 DCHECK(!IsCreatedByExtension(&turl));
2211 if (!force) { 2219 if (!force) {
2212 // Already unique. 2220 // Already unique.
2213 if (!GetTemplateURLForKeyword(turl.keyword())) 2221 if (!GetTemplateURLForKeyword(turl.keyword()))
2214 return turl.keyword(); 2222 return turl.keyword();
2215 2223
2216 // First, try to return the generated keyword for the TemplateURL (except 2224 // First, try to return the generated keyword for the TemplateURL (except
2217 // for extensions, as their keywords are not associated with their URLs). 2225 // for extensions, as their keywords are not associated with their URLs).
2218 GURL gurl(turl.url()); 2226 GURL gurl(turl.url());
2219 if (gurl.is_valid() && 2227 if (gurl.is_valid()) {
2220 (turl.type() != TemplateURL::OMNIBOX_API_EXTENSION)) {
2221 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl); 2228 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl);
2222 if (!GetTemplateURLForKeyword(keyword_candidate)) 2229 if (!GetTemplateURLForKeyword(keyword_candidate))
2223 return keyword_candidate; 2230 return keyword_candidate;
2224 } 2231 }
2225 } 2232 }
2226 2233
2227 // We try to uniquify the keyword by appending a special character to the end. 2234 // 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 2235 // 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. 2236 // keyword and let the user do what they will after our attempt.
2230 base::string16 keyword_candidate(turl.keyword()); 2237 base::string16 keyword_candidate(turl.keyword());
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 const std::string& extension_id, 2470 const std::string& extension_id,
2464 TemplateURL::Type type) { 2471 TemplateURL::Type type) {
2465 DCHECK_NE(TemplateURL::NORMAL, type); 2472 DCHECK_NE(TemplateURL::NORMAL, type);
2466 for (const auto& turl : template_urls_) { 2473 for (const auto& turl : template_urls_) {
2467 if (turl->type() == type && turl->GetExtensionId() == extension_id) 2474 if (turl->type() == type && turl->GetExtensionId() == extension_id)
2468 return turl.get(); 2475 return turl.get();
2469 } 2476 }
2470 return nullptr; 2477 return nullptr;
2471 } 2478 }
2472 2479
2473 TemplateURL* TemplateURLService::FindMatchingExtensionTemplateURL( 2480 TemplateURL* TemplateURLService::FindMatchingDefaultExtensionTemplateURL(
2474 const TemplateURLData& data, 2481 const TemplateURLData& data) {
2475 TemplateURL::Type type) {
2476 DCHECK_NE(TemplateURL::NORMAL, type);
2477 for (const auto& turl : template_urls_) { 2482 for (const auto& turl : template_urls_) {
2478 if (turl->type() == type && 2483 if (turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION &&
2484 turl->extension_info_->wants_to_be_default_engine &&
2479 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) 2485 TemplateURL::MatchesData(turl.get(), &data, search_terms_data()))
2480 return turl.get(); 2486 return turl.get();
2481 } 2487 }
2482 return nullptr; 2488 return nullptr;
2483 } 2489 }
2484 2490
2485 void TemplateURLService::UpdateExtensionDefaultSearchEngine() { 2491 void TemplateURLService::UpdateExtensionDefaultSearchEngine() {
2486 TemplateURL* most_recently_intalled_default = nullptr; 2492 TemplateURL* most_recently_intalled_default = nullptr;
2487 for (const auto& turl : template_urls_) { 2493 for (const auto& turl : template_urls_) {
2488 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) && 2494 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) &&
2489 turl->extension_info_->wants_to_be_default_engine && 2495 turl->extension_info_->wants_to_be_default_engine &&
2490 turl->SupportsReplacement(search_terms_data()) && 2496 turl->SupportsReplacement(search_terms_data()) &&
2491 (!most_recently_intalled_default || 2497 (!most_recently_intalled_default ||
2492 (most_recently_intalled_default->extension_info_->install_time < 2498 (most_recently_intalled_default->extension_info_->install_time <
2493 turl->extension_info_->install_time))) 2499 turl->extension_info_->install_time)))
2494 most_recently_intalled_default = turl.get(); 2500 most_recently_intalled_default = turl.get();
2495 } 2501 }
2496 2502
2497 if (most_recently_intalled_default) { 2503 if (most_recently_intalled_default) {
2498 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2504 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2499 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2505 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2500 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2506 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2501 most_recently_intalled_default->data()); 2507 most_recently_intalled_default->data());
2502 } else { 2508 } else {
2503 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2509 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2504 } 2510 }
2505 } 2511 }
OLDNEW
« 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