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

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 test, check removal of search engines. 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(
1449 TemplateURL* existing_engine,
1450 TemplateURL* new_engine) {
1451 DCHECK(new_engine);
1452 if (!existing_engine)
1453 return new_engine; // Better than nothing.
1454
1455 DCHECK_EQ(new_engine->keyword(), existing_engine->keyword());
1456 // We should only have overlapping keywords when at least one comes from
1457 // an extension.
1458 DCHECK(IsCreatedByExtension(existing_engine) ||
1459 IsCreatedByExtension(new_engine));
1460
1461 // Following ranking is implemented:
1462 // omnibox api keyword > extension search engine > normal engine.
1463 // If both extensions are of same type, latest installed wins.
1464 if (new_engine->type() == existing_engine->type()) {
1465 return existing_engine->extension_info_->install_time >
1466 new_engine->extension_info_->install_time
1467 ? existing_engine
1468 : new_engine;
1469 } else if (new_engine->type() ==
vasilii 2017/02/20 15:30:08 You don't need else as the previous block always r
Alexander Yashkin 2017/02/20 19:52:47 Done.
1470 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) {
1471 return existing_engine->type() == TemplateURL::OMNIBOX_API_EXTENSION
1472 ? existing_engine
1473 : new_engine;
1474 } else {
1475 // Omnibox api keyword always wins. Normal engine loses to any extensions
1476 // keywords.
1477 return new_engine->type() == TemplateURL::OMNIBOX_API_EXTENSION
1478 ? new_engine
1479 : existing_engine;
1480 }
1481 }
1482
1446 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) { 1483 void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
1447 const base::string16& keyword = template_url->keyword(); 1484 const base::string16& keyword = template_url->keyword();
1448 DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword)); 1485 DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword));
1449 if (keyword_to_turl_and_length_[keyword].first == template_url) { 1486 if (keyword_to_turl_and_length_[keyword].first == template_url) {
1450 // We need to check whether the keyword can now be provided by another 1487 // We need to check whether the keyword can now be provided by another
1451 // TemplateURL. See the comments in AddToMaps() for more information on 1488 // TemplateURL. See the comments in AddToMaps() for more information on
1452 // extension keywords and how they can coexist with non-extension keywords. 1489 // 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 1490 // 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 1491 // installed (which will be the most recently added, which will have the
1455 // highest ID). 1492 // highest ID).
1456 TemplateURL* best_fallback = nullptr; 1493 TemplateURL* best_fallback = nullptr;
1457 for (const auto& turl : template_urls_) { 1494 for (const auto& turl : template_urls_) {
1458 // This next statement relies on the fact that there can only be one 1495 if ((turl.get() != template_url) && (turl->keyword() == keyword))
1459 // non-Omnibox API TemplateURL with a given keyword. 1496 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 } 1497 }
1467 RemoveFromDomainMap(template_url); 1498 RemoveFromDomainMap(template_url);
1468 if (best_fallback) { 1499 if (best_fallback) {
1469 AddToMap(best_fallback); 1500 AddToMap(best_fallback);
1470 AddToDomainMap(best_fallback); 1501 AddToDomainMap(best_fallback);
1471 } else { 1502 } else {
1472 keyword_to_turl_and_length_.erase(keyword); 1503 keyword_to_turl_and_length_.erase(keyword);
1473 } 1504 }
1474 } 1505 }
1475 1506
(...skipping 11 matching lines...) Expand all
1487 void TemplateURLService::AddToMaps(TemplateURL* template_url) { 1518 void TemplateURLService::AddToMaps(TemplateURL* template_url) {
1488 bool template_url_is_omnibox_api = 1519 bool template_url_is_omnibox_api =
1489 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; 1520 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
1490 const base::string16& keyword = template_url->keyword(); 1521 const base::string16& keyword = template_url->keyword();
1491 KeywordToTURLAndMeaningfulLength::const_iterator i = 1522 KeywordToTURLAndMeaningfulLength::const_iterator i =
1492 keyword_to_turl_and_length_.find(keyword); 1523 keyword_to_turl_and_length_.find(keyword);
1493 if (i == keyword_to_turl_and_length_.end()) { 1524 if (i == keyword_to_turl_and_length_.end()) {
1494 AddToMap(template_url); 1525 AddToMap(template_url);
1495 AddToDomainMap(template_url); 1526 AddToDomainMap(template_url);
1496 } else { 1527 } else {
1497 const TemplateURL* existing_url = i->second.first; 1528 TemplateURL* existing_url = i->second.first;
1498 // We should only have overlapping keywords when at least one comes from 1529 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); 1530 RemoveFromDomainMap(existing_url);
1508 AddToMap(template_url); 1531 AddToMap(template_url);
1509 AddToDomainMap(template_url); 1532 AddToDomainMap(template_url);
1510 } 1533 }
1511 } 1534 }
1512 1535
1513 if (template_url_is_omnibox_api) 1536 if (template_url_is_omnibox_api)
1514 return; 1537 return;
1515 1538
1516 if (!template_url->sync_guid().empty()) 1539 if (!template_url->sync_guid().empty())
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1667 }
1645 return nullptr; 1668 return nullptr;
1646 } 1669 }
1647 1670
1648 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, 1671 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
1649 const TemplateURL& new_values) { 1672 const TemplateURL& new_values) {
1650 DCHECK(existing_turl); 1673 DCHECK(existing_turl);
1651 if (!Contains(&template_urls_, existing_turl)) 1674 if (!Contains(&template_urls_, existing_turl))
1652 return false; 1675 return false;
1653 1676
1654 DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->type()); 1677 DCHECK(!IsCreatedByExtension(existing_turl));
1655 1678
1656 base::string16 old_keyword(existing_turl->keyword()); 1679 base::string16 old_keyword(existing_turl->keyword());
1657 keyword_to_turl_and_length_.erase(old_keyword); 1680 keyword_to_turl_and_length_.erase(old_keyword);
1658 RemoveFromDomainMap(existing_turl); 1681 RemoveFromDomainMap(existing_turl);
1659 if (!existing_turl->sync_guid().empty()) 1682 if (!existing_turl->sync_guid().empty())
1660 guid_to_turl_.erase(existing_turl->sync_guid()); 1683 guid_to_turl_.erase(existing_turl->sync_guid());
1661 1684
1662 // |provider_map_| is only initialized after loading has completed. 1685 // |provider_map_| is only initialized after loading has completed.
1663 if (loaded_) 1686 if (loaded_)
1664 provider_map_->Remove(existing_turl); 1687 provider_map_->Remove(existing_turl);
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 } 1978 }
1956 1979
1957 // |default_search_provider_source_| must be set before calling 1980 // |default_search_provider_source_| must be set before calling
1958 // UpdateNoNotify(), since that function needs to know the source of the 1981 // UpdateNoNotify(), since that function needs to know the source of the
1959 // update in question. 1982 // update in question.
1960 default_search_provider_source_ = source; 1983 default_search_provider_source_ = source;
1961 1984
1962 if (!data) { 1985 if (!data) {
1963 default_search_provider_ = nullptr; 1986 default_search_provider_ = nullptr;
1964 } else if (source == DefaultSearchManager::FROM_EXTENSION) { 1987 } else if (source == DefaultSearchManager::FROM_EXTENSION) {
1965 default_search_provider_ = FindMatchingExtensionTemplateURL( 1988 default_search_provider_ = FindMatchingDefaultExtensionTemplateURL(*data);
1966 *data, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
1967 } else if (source == DefaultSearchManager::FROM_FALLBACK) { 1989 } else if (source == DefaultSearchManager::FROM_FALLBACK) {
1968 default_search_provider_ = 1990 default_search_provider_ =
1969 FindPrepopulatedTemplateURL(data->prepopulate_id); 1991 FindPrepopulatedTemplateURL(data->prepopulate_id);
1970 if (default_search_provider_) { 1992 if (default_search_provider_) {
1971 TemplateURLData update_data(*data); 1993 TemplateURLData update_data(*data);
1972 update_data.sync_guid = default_search_provider_->sync_guid(); 1994 update_data.sync_guid = default_search_provider_->sync_guid();
1973 if (!default_search_provider_->safe_for_autoreplace()) { 1995 if (!default_search_provider_->safe_for_autoreplace()) {
1974 update_data.safe_for_autoreplace = false; 1996 update_data.safe_for_autoreplace = false;
1975 update_data.SetKeyword(default_search_provider_->keyword()); 1997 update_data.SetKeyword(default_search_provider_->keyword());
1976 update_data.SetShortName(default_search_provider_->short_name()); 1998 update_data.SetShortName(default_search_provider_->short_name());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 bool newly_adding) { 2047 bool newly_adding) {
2026 DCHECK(template_url); 2048 DCHECK(template_url);
2027 2049
2028 if (newly_adding) { 2050 if (newly_adding) {
2029 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); 2051 DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
2030 DCHECK(!Contains(&template_urls_, template_url.get())); 2052 DCHECK(!Contains(&template_urls_, template_url.get()));
2031 template_url->data_.id = ++next_id_; 2053 template_url->data_.id = ++next_id_;
2032 } 2054 }
2033 2055
2034 template_url->ResetKeywordIfNecessary(search_terms_data(), false); 2056 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 2057
2040 // Check whether |template_url|'s keyword conflicts with any already in the 2058 // Check for conflicts between non extension engines keywords.
2041 // model. Note that we can reach here during the loading phase while 2059 if (!IsCreatedByExtension(template_url.get())) {
2042 // processing the template URLs from the web data service. In this case, 2060 // Check whether |template_url|'s keyword conflicts with any already in the
2043 // GetTemplateURLForKeyword() will look not only at what's already in the 2061 // model.
2044 // model, but at the |initial_default_search_provider_|. Since this engine 2062 TemplateURL* existing_turl =
2045 // will presumably also be present in the web data, we need to double-check 2063 FindNonExtensionTemplateURLForKeyword(template_url->keyword());
2046 // that any "pre-existing" entries we find are actually coming from 2064
2047 // |template_urls_|, lest we detect a "conflict" between the 2065 // Check whether |template_url|'s keyword conflicts with any already in the
2048 // |initial_default_search_provider_| and the web data version of itself. 2066 // model. Note that we can reach here during the loading phase while
2049 if (template_url->type() != TemplateURL::OMNIBOX_API_EXTENSION && 2067 // processing the template URLs from the web data service. In this case,
2050 existing_keyword_turl && 2068 // GetTemplateURLForKeyword() will look not only at what's already in the
2051 existing_keyword_turl->type() != TemplateURL::OMNIBOX_API_EXTENSION && 2069 // model, but at the |initial_default_search_provider_|. Since this engine
2052 Contains(&template_urls_, existing_keyword_turl)) { 2070 // will presumably also be present in the web data, we need to double-check
2053 DCHECK_NE(existing_keyword_turl, template_url.get()); 2071 // that any "pre-existing" entries we find are actually coming from
2054 // Only replace one of the TemplateURLs if they are either both extensions, 2072 // |template_urls_|, lest we detect a "conflict" between the
2055 // or both not extensions. 2073 // |initial_default_search_provider_| and the web data version of itself.
2056 bool are_same_type = IsCreatedByExtension(existing_keyword_turl) == 2074 if (existing_turl && Contains(&template_urls_, existing_turl)) {
2057 IsCreatedByExtension(template_url.get()); 2075 DCHECK_NE(existing_turl, template_url.get());
2058 if (CanReplace(existing_keyword_turl) && are_same_type) { 2076 if (CanReplace(existing_turl))
vasilii 2017/02/20 15:30:08 {} here and below.
Alexander Yashkin 2017/02/20 19:52:47 Done.
2059 RemoveNoNotify(existing_keyword_turl); 2077 RemoveNoNotify(existing_turl);
2060 } else if (CanReplace(template_url.get()) && are_same_type) { 2078 else if (CanReplace(template_url.get()))
2061 return nullptr; 2079 return nullptr;
2062 } else { 2080 else {
2063 base::string16 new_keyword = 2081 base::string16 new_keyword = UniquifyKeyword(*existing_turl, false);
2064 UniquifyKeyword(*existing_keyword_turl, false); 2082 // Resolve keyword conflicts for engines that can not be replaced.
2065 ResetTemplateURLNoNotify(existing_keyword_turl, 2083 // Replace keyword for existing engine.
2066 existing_keyword_turl->short_name(), new_keyword, 2084 ResetTemplateURLNoNotify(existing_turl, existing_turl->short_name(),
2067 existing_keyword_turl->url()); 2085 new_keyword, existing_turl->url());
2086 }
2068 } 2087 }
2069 } 2088 }
2070 TemplateURL* template_url_ptr = template_url.get(); 2089 TemplateURL* template_url_ptr = template_url.get();
2071 template_urls_.push_back(std::move(template_url)); 2090 template_urls_.push_back(std::move(template_url));
2072 AddToMaps(template_url_ptr); 2091 AddToMaps(template_url_ptr);
2073 2092
2074 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) { 2093 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) {
2075 if (web_data_service_.get()) 2094 if (web_data_service_.get())
2076 web_data_service_->AddKeyword(template_url_ptr->data()); 2095 web_data_service_->AddKeyword(template_url_ptr->data());
2077 2096
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 DCHECK(loaded_); 2220 DCHECK(loaded_);
2202 DCHECK(!guid.empty()); 2221 DCHECK(!guid.empty());
2203 2222
2204 TemplateURLData data(url->data()); 2223 TemplateURLData data(url->data());
2205 data.sync_guid = guid; 2224 data.sync_guid = guid;
2206 UpdateNoNotify(url, TemplateURL(data)); 2225 UpdateNoNotify(url, TemplateURL(data));
2207 } 2226 }
2208 2227
2209 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl, 2228 base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl,
2210 bool force) { 2229 bool force) {
2230 DCHECK(!IsCreatedByExtension(&turl));
2211 if (!force) { 2231 if (!force) {
2212 // Already unique. 2232 // Already unique.
2213 if (!GetTemplateURLForKeyword(turl.keyword())) 2233 if (!GetTemplateURLForKeyword(turl.keyword()))
2214 return turl.keyword(); 2234 return turl.keyword();
2215 2235
2216 // First, try to return the generated keyword for the TemplateURL (except 2236 // First, try to return the generated keyword for the TemplateURL (except
2217 // for extensions, as their keywords are not associated with their URLs). 2237 // for extensions, as their keywords are not associated with their URLs).
2218 GURL gurl(turl.url()); 2238 GURL gurl(turl.url());
2219 if (gurl.is_valid() && 2239 if (gurl.is_valid()) {
2220 (turl.type() != TemplateURL::OMNIBOX_API_EXTENSION)) {
2221 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl); 2240 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl);
2222 if (!GetTemplateURLForKeyword(keyword_candidate)) 2241 if (!GetTemplateURLForKeyword(keyword_candidate))
2223 return keyword_candidate; 2242 return keyword_candidate;
2224 } 2243 }
2225 } 2244 }
2226 2245
2227 // We try to uniquify the keyword by appending a special character to the end. 2246 // 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 2247 // 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. 2248 // keyword and let the user do what they will after our attempt.
2230 base::string16 keyword_candidate(turl.keyword()); 2249 base::string16 keyword_candidate(turl.keyword());
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 const std::string& extension_id, 2482 const std::string& extension_id,
2464 TemplateURL::Type type) { 2483 TemplateURL::Type type) {
2465 DCHECK_NE(TemplateURL::NORMAL, type); 2484 DCHECK_NE(TemplateURL::NORMAL, type);
2466 for (const auto& turl : template_urls_) { 2485 for (const auto& turl : template_urls_) {
2467 if (turl->type() == type && turl->GetExtensionId() == extension_id) 2486 if (turl->type() == type && turl->GetExtensionId() == extension_id)
2468 return turl.get(); 2487 return turl.get();
2469 } 2488 }
2470 return nullptr; 2489 return nullptr;
2471 } 2490 }
2472 2491
2473 TemplateURL* TemplateURLService::FindMatchingExtensionTemplateURL( 2492 TemplateURL* TemplateURLService::FindMatchingDefaultExtensionTemplateURL(
2474 const TemplateURLData& data, 2493 const TemplateURLData& data) {
2475 TemplateURL::Type type) {
2476 DCHECK_NE(TemplateURL::NORMAL, type);
2477 for (const auto& turl : template_urls_) { 2494 for (const auto& turl : template_urls_) {
2478 if (turl->type() == type && 2495 if (turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION &&
2496 turl->extension_info_->wants_to_be_default_engine &&
2479 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) 2497 TemplateURL::MatchesData(turl.get(), &data, search_terms_data()))
2480 return turl.get(); 2498 return turl.get();
2481 } 2499 }
2482 return nullptr; 2500 return nullptr;
2483 } 2501 }
2484 2502
2485 void TemplateURLService::UpdateExtensionDefaultSearchEngine() { 2503 void TemplateURLService::UpdateExtensionDefaultSearchEngine() {
2486 TemplateURL* most_recently_intalled_default = nullptr; 2504 TemplateURL* most_recently_intalled_default = nullptr;
2487 for (const auto& turl : template_urls_) { 2505 for (const auto& turl : template_urls_) {
2488 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) && 2506 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) &&
2489 turl->extension_info_->wants_to_be_default_engine && 2507 turl->extension_info_->wants_to_be_default_engine &&
2490 turl->SupportsReplacement(search_terms_data()) && 2508 turl->SupportsReplacement(search_terms_data()) &&
2491 (!most_recently_intalled_default || 2509 (!most_recently_intalled_default ||
2492 (most_recently_intalled_default->extension_info_->install_time < 2510 (most_recently_intalled_default->extension_info_->install_time <
2493 turl->extension_info_->install_time))) 2511 turl->extension_info_->install_time)))
2494 most_recently_intalled_default = turl.get(); 2512 most_recently_intalled_default = turl.get();
2495 } 2513 }
2496 2514
2497 if (most_recently_intalled_default) { 2515 if (most_recently_intalled_default) {
2498 base::AutoReset<DefaultSearchChangeOrigin> change_origin( 2516 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2499 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); 2517 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2500 default_search_manager_.SetExtensionControlledDefaultSearchEngine( 2518 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2501 most_recently_intalled_default->data()); 2519 most_recently_intalled_default->data());
2502 } else { 2520 } else {
2503 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); 2521 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2504 } 2522 }
2505 } 2523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698