| 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 406 |
| 407 void TemplateURLService::AddMatchingDomainKeywords( | 407 void TemplateURLService::AddMatchingDomainKeywords( |
| 408 const base::string16& prefix, | 408 const base::string16& prefix, |
| 409 bool supports_replacement_only, | 409 bool supports_replacement_only, |
| 410 TURLsAndMeaningfulLengths* matches) { | 410 TURLsAndMeaningfulLengths* matches) { |
| 411 AddMatchingKeywordsHelper( | 411 AddMatchingKeywordsHelper( |
| 412 keyword_domain_to_turl_and_length_, prefix, supports_replacement_only, | 412 keyword_domain_to_turl_and_length_, prefix, supports_replacement_only, |
| 413 matches); | 413 matches); |
| 414 } | 414 } |
| 415 | 415 |
| 416 bool TemplateURLService::IsInDefaultList(const TemplateURL* t_url) { |
| 417 return t_url->prepopulate_id() > 0 || t_url->created_by_policy(); |
| 418 } |
| 419 |
| 416 TemplateURL* TemplateURLService::GetTemplateURLForKeyword( | 420 TemplateURL* TemplateURLService::GetTemplateURLForKeyword( |
| 417 const base::string16& keyword) { | 421 const base::string16& keyword) { |
| 418 KeywordToTURLAndMeaningfulLength::const_iterator elem( | 422 KeywordToTURLAndMeaningfulLength::const_iterator elem( |
| 419 keyword_to_turl_and_length_.find(keyword)); | 423 keyword_to_turl_and_length_.find(keyword)); |
| 420 if (elem != keyword_to_turl_and_length_.end()) | 424 if (elem != keyword_to_turl_and_length_.end()) |
| 421 return elem->second.first; | 425 return elem->second.first; |
| 422 return (!loaded_ && initial_default_search_provider_ && | 426 return (!loaded_ && initial_default_search_provider_ && |
| 423 (initial_default_search_provider_->keyword() == keyword)) | 427 (initial_default_search_provider_->keyword() == keyword)) |
| 424 ? initial_default_search_provider_.get() | 428 ? initial_default_search_provider_.get() |
| 425 : nullptr; | 429 : nullptr; |
| (...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 if (!urls) | 1639 if (!urls) |
| 1636 return true; | 1640 return true; |
| 1637 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { | 1641 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { |
| 1638 if (!(*i)->safe_for_autoreplace()) | 1642 if (!(*i)->safe_for_autoreplace()) |
| 1639 return false; | 1643 return false; |
| 1640 } | 1644 } |
| 1641 return true; | 1645 return true; |
| 1642 } | 1646 } |
| 1643 | 1647 |
| 1644 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { | 1648 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { |
| 1645 return (t_url != default_search_provider_ && !t_url->show_in_default_list() && | 1649 return (t_url != default_search_provider_ && !IsInDefaultList(t_url) && |
| 1646 t_url->safe_for_autoreplace()); | 1650 t_url->safe_for_autoreplace()); |
| 1647 } | 1651 } |
| 1648 | 1652 |
| 1649 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( | 1653 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( |
| 1650 const base::string16& keyword) { | 1654 const base::string16& keyword) { |
| 1651 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); | 1655 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); |
| 1652 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) | 1656 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) |
| 1653 return keyword_turl; | 1657 return keyword_turl; |
| 1654 // The extension keyword in the model may be hiding a replaceable | 1658 // The extension keyword in the model may be hiding a replaceable |
| 1655 // non-extension keyword. Look for it. | 1659 // non-extension keyword. Look for it. |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 | 2478 |
| 2475 if (most_recently_intalled_default) { | 2479 if (most_recently_intalled_default) { |
| 2476 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2480 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2477 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2481 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2478 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2482 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2479 most_recently_intalled_default->data()); | 2483 most_recently_intalled_default->data()); |
| 2480 } else { | 2484 } else { |
| 2481 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2485 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2482 } | 2486 } |
| 2483 } | 2487 } |
| OLD | NEW |