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

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

Issue 2811793007: Make several methods of TemplateUrlService const (Closed)
Patch Set: Revert some unnecessary clang formatting per review comments Created 3 years, 8 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 "Search.DefaultSearchProvider", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, 843 "Search.DefaultSearchProvider", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
844 net::registry_controlled_domains::GetDomainAndRegistry( 844 net::registry_controlled_domains::GetDomainAndRegistry(
845 default_search_provider_->url_ref().GetHost(search_terms_data()), 845 default_search_provider_->url_ref().GetHost(search_terms_data()),
846 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); 846 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
847 } 847 }
848 } 848 }
849 } 849 }
850 850
851 base::string16 TemplateURLService::GetKeywordShortName( 851 base::string16 TemplateURLService::GetKeywordShortName(
852 const base::string16& keyword, 852 const base::string16& keyword,
853 bool* is_omnibox_api_extension_keyword) { 853 bool* is_omnibox_api_extension_keyword) const {
854 const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); 854 const TemplateURL* template_url =
855 const_cast<TemplateURLService*>(this)->GetTemplateURLForKeyword(keyword);
Peter Kasting 2017/04/13 22:42:52 If you're 100% sure you'll be able to convert thes
855 856
856 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService 857 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService
857 // to track changes to the model, this should become a DCHECK. 858 // to track changes to the model, this should become a DCHECK.
858 if (template_url) { 859 if (template_url) {
859 *is_omnibox_api_extension_keyword = 860 *is_omnibox_api_extension_keyword =
860 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; 861 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION;
861 return template_url->AdjustedShortNameForLocaleDirection(); 862 return template_url->AdjustedShortNameForLocaleDirection();
862 } 863 }
863 *is_omnibox_api_extension_keyword = false; 864 *is_omnibox_api_extension_keyword = false;
864 return base::string16(); 865 return base::string16();
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is 1623 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is
1623 // fixed. 1624 // fixed.
1624 tracked_objects::ScopedTracker tracking_profile3( 1625 tracked_objects::ScopedTracker tracking_profile3(
1625 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1626 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1626 "422460 TemplateURLService::ChangeToLoadedState 3")); 1627 "422460 TemplateURLService::ChangeToLoadedState 3"));
1627 1628
1628 on_loaded_callbacks_.Notify(); 1629 on_loaded_callbacks_.Notify();
1629 } 1630 }
1630 1631
1631 bool TemplateURLService::CanAddAutogeneratedKeywordForHost( 1632 bool TemplateURLService::CanAddAutogeneratedKeywordForHost(
1632 const std::string& host) { 1633 const std::string& host) const {
1633 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host); 1634 const TemplateURLSet* urls = provider_map_->GetURLsForHost(host);
1634 if (!urls) 1635 if (!urls)
1635 return true; 1636 return true;
1636 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) { 1637 for (TemplateURLSet::const_iterator i(urls->begin()); i != urls->end(); ++i) {
1637 if (!(*i)->safe_for_autoreplace()) 1638 if (!(*i)->safe_for_autoreplace())
1638 return false; 1639 return false;
1639 } 1640 }
1640 return true; 1641 return true;
1641 } 1642 }
1642 1643
1643 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { 1644 bool TemplateURLService::CanReplace(const TemplateURL* t_url) const {
1644 return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace(); 1645 return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace();
1645 } 1646 }
1646 1647
1647 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( 1648 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
1648 const base::string16& keyword) { 1649 const base::string16& keyword) {
1649 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); 1650 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword);
1650 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) 1651 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL))
1651 return keyword_turl; 1652 return keyword_turl;
1652 // The extension keyword in the model may be hiding a replaceable 1653 // The extension keyword in the model may be hiding a replaceable
1653 // non-extension keyword. Look for it. 1654 // non-extension keyword. Look for it.
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 // This is a best-effort approach where we try to preserve the original 2224 // This is a best-effort approach where we try to preserve the original
2224 // keyword and let the user do what they will after our attempt. 2225 // keyword and let the user do what they will after our attempt.
2225 base::string16 keyword_candidate(turl.keyword()); 2226 base::string16 keyword_candidate(turl.keyword());
2226 do { 2227 do {
2227 keyword_candidate.append(base::ASCIIToUTF16("_")); 2228 keyword_candidate.append(base::ASCIIToUTF16("_"));
2228 } while (GetTemplateURLForKeyword(keyword_candidate)); 2229 } while (GetTemplateURLForKeyword(keyword_candidate));
2229 2230
2230 return keyword_candidate; 2231 return keyword_candidate;
2231 } 2232 }
2232 2233
2233 bool TemplateURLService::IsLocalTemplateURLBetter(const TemplateURL* local_turl, 2234 bool TemplateURLService::IsLocalTemplateURLBetter(
2234 const TemplateURL* sync_turl, 2235 const TemplateURL* local_turl,
2235 bool prefer_local_default) { 2236 const TemplateURL* sync_turl,
2236 DCHECK(GetTemplateURLForGUID(local_turl->sync_guid())); 2237 bool prefer_local_default) const {
2238 const TemplateURL* templateURL =
Peter Kasting 2017/04/13 22:42:52 Nit: C++ variable names are lowercase, with unders
2239 const_cast<TemplateURLService*>(this)->GetTemplateURLForGUID(
2240 local_turl->sync_guid());
2241 DCHECK(templateURL);
Peter Kasting 2017/04/13 22:42:52 Nit: While I'm normally fine with pulling temps ou
2237 return local_turl->last_modified() > sync_turl->last_modified() || 2242 return local_turl->last_modified() > sync_turl->last_modified() ||
2238 local_turl->created_by_policy() || 2243 local_turl->created_by_policy() ||
2239 (prefer_local_default && local_turl == GetDefaultSearchProvider()); 2244 (prefer_local_default && local_turl == GetDefaultSearchProvider());
2240 } 2245 }
2241 2246
2242 void TemplateURLService::ResolveSyncKeywordConflict( 2247 void TemplateURLService::ResolveSyncKeywordConflict(
2243 TemplateURL* unapplied_sync_turl, 2248 TemplateURL* unapplied_sync_turl,
2244 TemplateURL* applied_sync_turl, 2249 TemplateURL* applied_sync_turl,
2245 syncer::SyncChangeList* change_list) { 2250 syncer::SyncChangeList* change_list) {
2246 DCHECK(loaded_); 2251 DCHECK(loaded_);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2483 if (!IsCreatedByExtension(template_url.get())) { 2488 if (!IsCreatedByExtension(template_url.get())) {
2484 if (keyword_to_template_url.find(template_url->keyword()) != 2489 if (keyword_to_template_url.find(template_url->keyword()) !=
2485 keyword_to_template_url.end()) { 2490 keyword_to_template_url.end()) {
2486 return true; 2491 return true;
2487 } 2492 }
2488 keyword_to_template_url[template_url->keyword()] = template_url.get(); 2493 keyword_to_template_url[template_url->keyword()] = template_url.get();
2489 } 2494 }
2490 } 2495 }
2491 return false; 2496 return false;
2492 } 2497 }
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