| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 result = url_formatter::StripWWW(result); | 336 result = url_formatter::StripWWW(result); |
| 337 | 337 |
| 338 // Remove trailing "/". | 338 // Remove trailing "/". |
| 339 return (result.empty() || result.back() != '/') ? | 339 return (result.empty() || result.back() != '/') ? |
| 340 result : result.substr(0, result.length() - 1); | 340 result : result.substr(0, result.length() - 1); |
| 341 } | 341 } |
| 342 | 342 |
| 343 bool TemplateURLService::CanAddAutogeneratedKeyword( | 343 bool TemplateURLService::CanAddAutogeneratedKeyword( |
| 344 const base::string16& keyword, | 344 const base::string16& keyword, |
| 345 const GURL& url, | 345 const GURL& url, |
| 346 TemplateURL** template_url_to_replace) { | 346 TemplateURL** template_url_to_replace) const { |
| 347 DCHECK(!keyword.empty()); // This should only be called for non-empty | 347 DCHECK(!keyword.empty()); // This should only be called for non-empty |
| 348 // keywords. If we need to support empty kewords | 348 // keywords. If we need to support empty kewords |
| 349 // the code needs to change slightly. | 349 // the code needs to change slightly. |
| 350 TemplateURL* existing_url = GetTemplateURLForKeyword(keyword); | 350 TemplateURL* existing_url = GetTemplateURLForKeyword(keyword); |
| 351 if (template_url_to_replace) | 351 if (template_url_to_replace) |
| 352 *template_url_to_replace = existing_url; | 352 *template_url_to_replace = existing_url; |
| 353 if (existing_url) { | 353 if (existing_url) { |
| 354 // We already have a TemplateURL for this keyword. Only allow it to be | 354 // We already have a TemplateURL for this keyword. Only allow it to be |
| 355 // replaced if the TemplateURL can be replaced. | 355 // replaced if the TemplateURL can be replaced. |
| 356 return CanReplace(existing_url); | 356 return CanReplace(existing_url); |
| 357 } | 357 } |
| 358 | 358 |
| 359 // We don't have a TemplateURL with keyword. We still may not allow this | 359 // We don't have a TemplateURL with keyword. We still may not allow this |
| 360 // keyword if there's evidence we may have created this keyword before and | 360 // keyword if there's evidence we may have created this keyword before and |
| 361 // the user renamed it (because, for instance, the keyword is a common word | 361 // the user renamed it (because, for instance, the keyword is a common word |
| 362 // that may interfere with search queries). An easy heuristic for this is | 362 // that may interfere with search queries). An easy heuristic for this is |
| 363 // whether the user has a TemplateURL that has been manually modified (e.g., | 363 // whether the user has a TemplateURL that has been manually modified (e.g., |
| 364 // renamed) connected to the same host. | 364 // renamed) connected to the same host. |
| 365 return !url.is_valid() || url.host().empty() || | 365 return !url.is_valid() || url.host().empty() || |
| 366 CanAddAutogeneratedKeywordForHost(url.host()); | 366 CanAddAutogeneratedKeywordForHost(url.host()); |
| 367 } | 367 } |
| 368 | 368 |
| 369 bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy( | 369 bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy( |
| 370 const TemplateURL* t_url) { | 370 const TemplateURL* t_url) const { |
| 371 return (t_url->prepopulate_id() > 0 || t_url->created_by_policy()) && | 371 return (t_url->prepopulate_id() > 0 || t_url->created_by_policy()) && |
| 372 t_url->SupportsReplacement(search_terms_data()); | 372 t_url->SupportsReplacement(search_terms_data()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool TemplateURLService::ShowInDefaultList(const TemplateURL* t_url) { | 375 bool TemplateURLService::ShowInDefaultList(const TemplateURL* t_url) const { |
| 376 return t_url == default_search_provider_ || | 376 return t_url == default_search_provider_ || |
| 377 IsPrepopulatedOrCreatedByPolicy(t_url); | 377 IsPrepopulatedOrCreatedByPolicy(t_url); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void TemplateURLService::AddMatchingKeywords( | 380 void TemplateURLService::AddMatchingKeywords( |
| 381 const base::string16& prefix, | 381 const base::string16& prefix, |
| 382 bool supports_replacement_only, | 382 bool supports_replacement_only, |
| 383 TURLsAndMeaningfulLengths* matches) { | 383 TURLsAndMeaningfulLengths* matches) { |
| 384 AddMatchingKeywordsHelper( | 384 AddMatchingKeywordsHelper( |
| 385 keyword_to_turl_and_length_, prefix, supports_replacement_only, matches); | 385 keyword_to_turl_and_length_, prefix, supports_replacement_only, matches); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void TemplateURLService::AddMatchingDomainKeywords( | 388 void TemplateURLService::AddMatchingDomainKeywords( |
| 389 const base::string16& prefix, | 389 const base::string16& prefix, |
| 390 bool supports_replacement_only, | 390 bool supports_replacement_only, |
| 391 TURLsAndMeaningfulLengths* matches) { | 391 TURLsAndMeaningfulLengths* matches) { |
| 392 AddMatchingKeywordsHelper( | 392 AddMatchingKeywordsHelper( |
| 393 keyword_domain_to_turl_and_length_, prefix, supports_replacement_only, | 393 keyword_domain_to_turl_and_length_, prefix, supports_replacement_only, |
| 394 matches); | 394 matches); |
| 395 } | 395 } |
| 396 | 396 |
| 397 TemplateURL* TemplateURLService::GetTemplateURLForKeyword( | 397 TemplateURL* TemplateURLService::GetTemplateURLForKeyword( |
| 398 const base::string16& keyword) { | 398 const base::string16& keyword) const { |
| 399 KeywordToTURLAndMeaningfulLength::const_iterator elem( | 399 KeywordToTURLAndMeaningfulLength::const_iterator elem( |
| 400 keyword_to_turl_and_length_.find(keyword)); | 400 keyword_to_turl_and_length_.find(keyword)); |
| 401 if (elem != keyword_to_turl_and_length_.end()) | 401 if (elem != keyword_to_turl_and_length_.end()) |
| 402 return elem->second.first; | 402 return elem->second.first; |
| 403 return (!loaded_ && initial_default_search_provider_ && | 403 return (!loaded_ && initial_default_search_provider_ && |
| 404 (initial_default_search_provider_->keyword() == keyword)) | 404 (initial_default_search_provider_->keyword() == keyword)) |
| 405 ? initial_default_search_provider_.get() | 405 ? initial_default_search_provider_.get() |
| 406 : nullptr; | 406 : nullptr; |
| 407 } | 407 } |
| 408 | 408 |
| 409 TemplateURL* TemplateURLService::GetTemplateURLForGUID( | 409 TemplateURL* TemplateURLService::GetTemplateURLForGUID( |
| 410 const std::string& sync_guid) { | 410 const std::string& sync_guid) const { |
| 411 GUIDToTURL::const_iterator elem(guid_to_turl_.find(sync_guid)); | 411 GUIDToTURL::const_iterator elem(guid_to_turl_.find(sync_guid)); |
| 412 if (elem != guid_to_turl_.end()) | 412 if (elem != guid_to_turl_.end()) |
| 413 return elem->second; | 413 return elem->second; |
| 414 return (!loaded_ && initial_default_search_provider_ && | 414 return (!loaded_ && initial_default_search_provider_ && |
| 415 (initial_default_search_provider_->sync_guid() == sync_guid)) | 415 (initial_default_search_provider_->sync_guid() == sync_guid)) |
| 416 ? initial_default_search_provider_.get() | 416 ? initial_default_search_provider_.get() |
| 417 : nullptr; | 417 : nullptr; |
| 418 } | 418 } |
| 419 | 419 |
| 420 TemplateURL* TemplateURLService::GetTemplateURLForHost( | 420 TemplateURL* TemplateURLService::GetTemplateURLForHost( |
| 421 const std::string& host) { | 421 const std::string& host) const { |
| 422 if (loaded_) | 422 if (loaded_) |
| 423 return provider_map_->GetTemplateURLForHost(host); | 423 return provider_map_->GetTemplateURLForHost(host); |
| 424 TemplateURL* initial_dsp = initial_default_search_provider_.get(); | 424 TemplateURL* initial_dsp = initial_default_search_provider_.get(); |
| 425 return (initial_dsp && | 425 return (initial_dsp && |
| 426 (initial_dsp->GenerateSearchURL(search_terms_data()).host_piece() == | 426 (initial_dsp->GenerateSearchURL(search_terms_data()).host_piece() == |
| 427 host)) | 427 host)) |
| 428 ? initial_dsp | 428 ? initial_dsp |
| 429 : nullptr; | 429 : nullptr; |
| 430 } | 430 } |
| 431 | 431 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 563 } |
| 564 | 564 |
| 565 void TemplateURLService::ResetTemplateURL(TemplateURL* url, | 565 void TemplateURLService::ResetTemplateURL(TemplateURL* url, |
| 566 const base::string16& title, | 566 const base::string16& title, |
| 567 const base::string16& keyword, | 567 const base::string16& keyword, |
| 568 const std::string& search_url) { | 568 const std::string& search_url) { |
| 569 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) | 569 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) |
| 570 NotifyObservers(); | 570 NotifyObservers(); |
| 571 } | 571 } |
| 572 | 572 |
| 573 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) { | 573 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) const { |
| 574 return | 574 return |
| 575 ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || | 575 ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || |
| 576 (default_search_provider_source_ == | 576 (default_search_provider_source_ == |
| 577 DefaultSearchManager::FROM_FALLBACK)) && | 577 DefaultSearchManager::FROM_FALLBACK)) && |
| 578 (url != GetDefaultSearchProvider()) && | 578 (url != GetDefaultSearchProvider()) && |
| 579 url->url_ref().SupportsReplacement(search_terms_data()) && | 579 url->url_ref().SupportsReplacement(search_terms_data()) && |
| 580 (url->type() == TemplateURL::NORMAL); | 580 (url->type() == TemplateURL::NORMAL); |
| 581 } | 581 } |
| 582 | 582 |
| 583 void TemplateURLService::SetUserSelectedDefaultSearchProvider( | 583 void TemplateURLService::SetUserSelectedDefaultSearchProvider( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 614 : initial_default_search_provider_.get(); | 614 : initial_default_search_provider_.get(); |
| 615 } | 615 } |
| 616 | 616 |
| 617 bool TemplateURLService::IsSearchResultsPageFromDefaultSearchProvider( | 617 bool TemplateURLService::IsSearchResultsPageFromDefaultSearchProvider( |
| 618 const GURL& url) const { | 618 const GURL& url) const { |
| 619 const TemplateURL* default_provider = GetDefaultSearchProvider(); | 619 const TemplateURL* default_provider = GetDefaultSearchProvider(); |
| 620 return default_provider && | 620 return default_provider && |
| 621 default_provider->IsSearchURL(url, search_terms_data()); | 621 default_provider->IsSearchURL(url, search_terms_data()); |
| 622 } | 622 } |
| 623 | 623 |
| 624 bool TemplateURLService::IsExtensionControlledDefaultSearch() { | 624 bool TemplateURLService::IsExtensionControlledDefaultSearch() const { |
| 625 return default_search_provider_source_ == | 625 return default_search_provider_source_ == |
| 626 DefaultSearchManager::FROM_EXTENSION; | 626 DefaultSearchManager::FROM_EXTENSION; |
| 627 } | 627 } |
| 628 | 628 |
| 629 void TemplateURLService::RepairPrepopulatedSearchEngines() { | 629 void TemplateURLService::RepairPrepopulatedSearchEngines() { |
| 630 // Can't clean DB if it hasn't been loaded. | 630 // Can't clean DB if it hasn't been loaded. |
| 631 DCHECK(loaded()); | 631 DCHECK(loaded()); |
| 632 | 632 |
| 633 if ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || | 633 if ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || |
| 634 (default_search_provider_source_ == | 634 (default_search_provider_source_ == |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 "Search.DefaultSearchProvider", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, | 842 "Search.DefaultSearchProvider", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, |
| 843 net::registry_controlled_domains::GetDomainAndRegistry( | 843 net::registry_controlled_domains::GetDomainAndRegistry( |
| 844 default_search_provider_->url_ref().GetHost(search_terms_data()), | 844 default_search_provider_->url_ref().GetHost(search_terms_data()), |
| 845 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); | 845 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); |
| 846 } | 846 } |
| 847 } | 847 } |
| 848 } | 848 } |
| 849 | 849 |
| 850 base::string16 TemplateURLService::GetKeywordShortName( | 850 base::string16 TemplateURLService::GetKeywordShortName( |
| 851 const base::string16& keyword, | 851 const base::string16& keyword, |
| 852 bool* is_omnibox_api_extension_keyword) { | 852 bool* is_omnibox_api_extension_keyword) const { |
| 853 const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); | 853 const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); |
| 854 | 854 |
| 855 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService | 855 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService |
| 856 // to track changes to the model, this should become a DCHECK. | 856 // to track changes to the model, this should become a DCHECK. |
| 857 if (template_url) { | 857 if (template_url) { |
| 858 *is_omnibox_api_extension_keyword = | 858 *is_omnibox_api_extension_keyword = |
| 859 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; | 859 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; |
| 860 return template_url->AdjustedShortNameForLocaleDirection(); | 860 return template_url->AdjustedShortNameForLocaleDirection(); |
| 861 } | 861 } |
| 862 *is_omnibox_api_extension_keyword = false; | 862 *is_omnibox_api_extension_keyword = false; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 if (i == 0) | 1427 if (i == 0) |
| 1428 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); | 1428 default_search_manager_.SetUserSelectedDefaultSearchEngine(data); |
| 1429 } | 1429 } |
| 1430 } | 1430 } |
| 1431 | 1431 |
| 1432 // Request a server check for the correct Google URL if Google is the | 1432 // Request a server check for the correct Google URL if Google is the |
| 1433 // default search engine. | 1433 // default search engine. |
| 1434 RequestGoogleURLTrackerServerCheckIfNecessary(); | 1434 RequestGoogleURLTrackerServerCheckIfNecessary(); |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1437 TemplateURL* TemplateURLService::BestEngineForKeyword(TemplateURL* engine1, | 1437 TemplateURL* TemplateURLService::BestEngineForKeyword( |
| 1438 TemplateURL* engine2) { | 1438 TemplateURL* engine1, |
| 1439 TemplateURL* engine2) const { |
| 1439 DCHECK(engine1); | 1440 DCHECK(engine1); |
| 1440 DCHECK(engine2); | 1441 DCHECK(engine2); |
| 1441 CHECK_NE(engine1, engine2); | 1442 CHECK_NE(engine1, engine2); |
| 1442 DCHECK_EQ(engine1->keyword(), engine2->keyword()); | 1443 DCHECK_EQ(engine1->keyword(), engine2->keyword()); |
| 1443 | 1444 |
| 1444 std::string engine1_params = base::StringPrintf( | 1445 std::string engine1_params = base::StringPrintf( |
| 1445 "%s, %i, %" PRId64 ", %i, %s, %s", | 1446 "%s, %i, %" PRId64 ", %i, %s, %s", |
| 1446 base::UTF16ToUTF8(engine1->keyword()).c_str(), | 1447 base::UTF16ToUTF8(engine1->keyword()).c_str(), |
| 1447 static_cast<int>(engine1->type()), engine1->id(), | 1448 static_cast<int>(engine1->type()), engine1->id(), |
| 1448 engine1->prepopulate_id(), CanReplace(engine1) ? "true" : "false", | 1449 engine1->prepopulate_id(), CanReplace(engine1) ? "true" : "false", |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1631 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 1632 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 1632 // fixed. | 1633 // fixed. |
| 1633 tracked_objects::ScopedTracker tracking_profile3( | 1634 tracked_objects::ScopedTracker tracking_profile3( |
| 1634 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1635 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1635 "422460 TemplateURLService::ChangeToLoadedState 3")); | 1636 "422460 TemplateURLService::ChangeToLoadedState 3")); |
| 1636 | 1637 |
| 1637 on_loaded_callbacks_.Notify(); | 1638 on_loaded_callbacks_.Notify(); |
| 1638 } | 1639 } |
| 1639 | 1640 |
| 1640 bool TemplateURLService::CanAddAutogeneratedKeywordForHost( | 1641 bool TemplateURLService::CanAddAutogeneratedKeywordForHost( |
| 1641 const std::string& host) { | 1642 const std::string& host) const { |
| 1642 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host); | 1643 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host); |
| 1643 if (!urls) | 1644 if (!urls) |
| 1644 return true; | 1645 return true; |
| 1645 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { | 1646 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { |
| 1646 if (!(*i)->safe_for_autoreplace()) | 1647 if (!(*i)->safe_for_autoreplace()) |
| 1647 return false; | 1648 return false; |
| 1648 } | 1649 } |
| 1649 return true; | 1650 return true; |
| 1650 } | 1651 } |
| 1651 | 1652 |
| 1652 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { | 1653 bool TemplateURLService::CanReplace(const TemplateURL* t_url) const { |
| 1653 return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace(); | 1654 return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace(); |
| 1654 } | 1655 } |
| 1655 | 1656 |
| 1656 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( | 1657 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( |
| 1657 const base::string16& keyword) { | 1658 const base::string16& keyword) const { |
| 1658 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); | 1659 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); |
| 1659 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) | 1660 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) |
| 1660 return keyword_turl; | 1661 return keyword_turl; |
| 1661 // The extension keyword in the model may be hiding a replaceable | 1662 // The extension keyword in the model may be hiding a replaceable |
| 1662 // non-extension keyword. Look for it. | 1663 // non-extension keyword. Look for it. |
| 1663 for (const auto& turl : template_urls_) { | 1664 for (const auto& turl : template_urls_) { |
| 1664 if ((turl->type() == TemplateURL::NORMAL) && | 1665 if ((turl->type() == TemplateURL::NORMAL) && |
| 1665 (turl->keyword() == keyword)) | 1666 (turl->keyword() == keyword)) |
| 1666 return turl.get(); | 1667 return turl.get(); |
| 1667 } | 1668 } |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 // This is a best-effort approach where we try to preserve the original | 2282 // This is a best-effort approach where we try to preserve the original |
| 2282 // keyword and let the user do what they will after our attempt. | 2283 // keyword and let the user do what they will after our attempt. |
| 2283 base::string16 keyword_candidate(turl.keyword()); | 2284 base::string16 keyword_candidate(turl.keyword()); |
| 2284 do { | 2285 do { |
| 2285 keyword_candidate.append(base::ASCIIToUTF16("_")); | 2286 keyword_candidate.append(base::ASCIIToUTF16("_")); |
| 2286 } while (GetTemplateURLForKeyword(keyword_candidate)); | 2287 } while (GetTemplateURLForKeyword(keyword_candidate)); |
| 2287 | 2288 |
| 2288 return keyword_candidate; | 2289 return keyword_candidate; |
| 2289 } | 2290 } |
| 2290 | 2291 |
| 2291 bool TemplateURLService::IsLocalTemplateURLBetter(const TemplateURL* local_turl, | 2292 bool TemplateURLService::IsLocalTemplateURLBetter( |
| 2292 const TemplateURL* sync_turl, | 2293 const TemplateURL* local_turl, |
| 2293 bool prefer_local_default) { | 2294 const TemplateURL* sync_turl, |
| 2295 bool prefer_local_default) const { |
| 2294 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid())); | 2296 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid())); |
| 2295 return local_turl->last_modified() > sync_turl->last_modified() || | 2297 return local_turl->last_modified() > sync_turl->last_modified() || |
| 2296 local_turl->created_by_policy() || | 2298 local_turl->created_by_policy() || |
| 2297 (prefer_local_default && local_turl == GetDefaultSearchProvider()); | 2299 (prefer_local_default && local_turl == GetDefaultSearchProvider()); |
| 2298 } | 2300 } |
| 2299 | 2301 |
| 2300 void TemplateURLService::ResolveSyncKeywordConflict( | 2302 void TemplateURLService::ResolveSyncKeywordConflict( |
| 2301 TemplateURL* unapplied_sync_turl, | 2303 TemplateURL* unapplied_sync_turl, |
| 2302 TemplateURL* applied_sync_turl, | 2304 TemplateURL* applied_sync_turl, |
| 2303 syncer::SyncChangeList* change_list) { | 2305 syncer::SyncChangeList* change_list) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2497 // Add to vector of matching keywords. | 2499 // Add to vector of matching keywords. |
| 2498 for (typename Container::const_iterator i(match_range.first); | 2500 for (typename Container::const_iterator i(match_range.first); |
| 2499 i != match_range.second; ++i) { | 2501 i != match_range.second; ++i) { |
| 2500 if (!supports_replacement_only || | 2502 if (!supports_replacement_only || |
| 2501 i->second.first->url_ref().SupportsReplacement(search_terms_data())) | 2503 i->second.first->url_ref().SupportsReplacement(search_terms_data())) |
| 2502 matches->push_back(i->second); | 2504 matches->push_back(i->second); |
| 2503 } | 2505 } |
| 2504 } | 2506 } |
| 2505 | 2507 |
| 2506 TemplateURL* TemplateURLService::FindPrepopulatedTemplateURL( | 2508 TemplateURL* TemplateURLService::FindPrepopulatedTemplateURL( |
| 2507 int prepopulated_id) { | 2509 int prepopulated_id) const { |
| 2508 for (const auto& turl : template_urls_) { | 2510 for (const auto& turl : template_urls_) { |
| 2509 if (turl->prepopulate_id() == prepopulated_id) | 2511 if (turl->prepopulate_id() == prepopulated_id) |
| 2510 return turl.get(); | 2512 return turl.get(); |
| 2511 } | 2513 } |
| 2512 return nullptr; | 2514 return nullptr; |
| 2513 } | 2515 } |
| 2514 | 2516 |
| 2515 TemplateURL* TemplateURLService::FindTemplateURLForExtension( | 2517 TemplateURL* TemplateURLService::FindTemplateURLForExtension( |
| 2516 const std::string& extension_id, | 2518 const std::string& extension_id, |
| 2517 TemplateURL::Type type) { | 2519 TemplateURL::Type type) const { |
| 2518 DCHECK_NE(TemplateURL::NORMAL, type); | 2520 DCHECK_NE(TemplateURL::NORMAL, type); |
| 2519 for (const auto& turl : template_urls_) { | 2521 for (const auto& turl : template_urls_) { |
| 2520 if (turl->type() == type && turl->GetExtensionId() == extension_id) | 2522 if (turl->type() == type && turl->GetExtensionId() == extension_id) |
| 2521 return turl.get(); | 2523 return turl.get(); |
| 2522 } | 2524 } |
| 2523 return nullptr; | 2525 return nullptr; |
| 2524 } | 2526 } |
| 2525 | 2527 |
| 2526 TemplateURL* TemplateURLService::FindMatchingDefaultExtensionTemplateURL( | 2528 TemplateURL* TemplateURLService::FindMatchingDefaultExtensionTemplateURL( |
| 2527 const TemplateURLData& data) { | 2529 const TemplateURLData& data) const { |
| 2528 for (const auto& turl : template_urls_) { | 2530 for (const auto& turl : template_urls_) { |
| 2529 if (turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION && | 2531 if (turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION && |
| 2530 turl->extension_info_->wants_to_be_default_engine && | 2532 turl->extension_info_->wants_to_be_default_engine && |
| 2531 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) | 2533 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) |
| 2532 return turl.get(); | 2534 return turl.get(); |
| 2533 } | 2535 } |
| 2534 return nullptr; | 2536 return nullptr; |
| 2535 } | 2537 } |
| 2536 | 2538 |
| 2537 bool TemplateURLService::HasDuplicateKeywords() const { | 2539 bool TemplateURLService::HasDuplicateKeywords() const { |
| 2538 std::map<base::string16, TemplateURL*> keyword_to_template_url; | 2540 std::map<base::string16, TemplateURL*> keyword_to_template_url; |
| 2539 for (const auto& template_url : template_urls_) { | 2541 for (const auto& template_url : template_urls_) { |
| 2540 // Validate no duplicate normal engines with same keyword. | 2542 // Validate no duplicate normal engines with same keyword. |
| 2541 if (!IsCreatedByExtension(template_url.get())) { | 2543 if (!IsCreatedByExtension(template_url.get())) { |
| 2542 if (keyword_to_template_url.find(template_url->keyword()) != | 2544 if (keyword_to_template_url.find(template_url->keyword()) != |
| 2543 keyword_to_template_url.end()) { | 2545 keyword_to_template_url.end()) { |
| 2544 return true; | 2546 return true; |
| 2545 } | 2547 } |
| 2546 keyword_to_template_url[template_url->keyword()] = template_url.get(); | 2548 keyword_to_template_url[template_url->keyword()] = template_url.get(); |
| 2547 } | 2549 } |
| 2548 } | 2550 } |
| 2549 return false; | 2551 return false; |
| 2550 } | 2552 } |
| OLD | NEW |