Chromium Code Reviews| Index: components/search_engines/template_url_service.cc |
| diff --git a/components/search_engines/template_url_service.cc b/components/search_engines/template_url_service.cc |
| index a4db5e184d0ef54d3414597f5e1c4564a867d66e..7fc65fb5db0fe4948d5f8986e0fffed8c98b2d60 100644 |
| --- a/components/search_engines/template_url_service.cc |
| +++ b/components/search_engines/template_url_service.cc |
| @@ -394,8 +394,8 @@ void TemplateURLService::AddMatchingDomainKeywords( |
| matches); |
| } |
| -TemplateURL* TemplateURLService::GetTemplateURLForKeyword( |
| - const base::string16& keyword) { |
| +const TemplateURL* TemplateURLService::GetTemplateURLForKeyword( |
| + const base::string16& keyword) const { |
|
Peter Kasting
2017/04/17 18:53:24
Nit: Definition order should match declaration ord
|
| KeywordToTURLAndMeaningfulLength::const_iterator elem( |
| keyword_to_turl_and_length_.find(keyword)); |
| if (elem != keyword_to_turl_and_length_.end()) |
| @@ -406,8 +406,15 @@ TemplateURL* TemplateURLService::GetTemplateURLForKeyword( |
| : nullptr; |
| } |
| -TemplateURL* TemplateURLService::GetTemplateURLForGUID( |
| - const std::string& sync_guid) { |
| +TemplateURL* TemplateURLService::GetTemplateURLForKeyword( |
| + const base::string16& keyword) { |
| + return const_cast<TemplateURL*>( |
| + static_cast<const TemplateURLService*>(this)-> |
| + GetTemplateURLForKeyword(keyword)); |
| +} |
| + |
| +const TemplateURL* TemplateURLService::GetTemplateURLForGUID( |
| + const std::string& sync_guid) const { |
| GUIDToTURL::const_iterator elem(guid_to_turl_.find(sync_guid)); |
| if (elem != guid_to_turl_.end()) |
| return elem->second; |
| @@ -417,8 +424,15 @@ TemplateURL* TemplateURLService::GetTemplateURLForGUID( |
| : nullptr; |
| } |
| -TemplateURL* TemplateURLService::GetTemplateURLForHost( |
| - const std::string& host) { |
| +TemplateURL* TemplateURLService::GetTemplateURLForGUID( |
| + const std::string& sync_guid) { |
| +return const_cast<TemplateURL*>( |
| + static_cast<const TemplateURLService*>(this)-> |
| + GetTemplateURLForGUID(sync_guid)); |
| +} |
| + |
| +const TemplateURL* TemplateURLService::GetTemplateURLForHost( |
| + const std::string& host) const { |
| if (loaded_) |
| return provider_map_->GetTemplateURLForHost(host); |
| TemplateURL* initial_dsp = initial_default_search_provider_.get(); |
| @@ -429,6 +443,13 @@ TemplateURL* TemplateURLService::GetTemplateURLForHost( |
| : nullptr; |
| } |
| +TemplateURL* TemplateURLService::GetTemplateURLForHost( |
| + const std::string& host) { |
| + return const_cast<TemplateURL*>( |
| + static_cast<const TemplateURLService*>(this)-> |
| + GetTemplateURLForHost(host)); |
| +} |
| + |
| TemplateURL* TemplateURLService::Add( |
| std::unique_ptr<TemplateURL> template_url) { |
| KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
| @@ -851,10 +872,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( |
| base::string16 TemplateURLService::GetKeywordShortName( |
| const base::string16& keyword, |
| bool* is_omnibox_api_extension_keyword) const { |
| - // TODO(jeffschiller): Make GetTemplateURLForKeyword const and remove the |
| - // const_cast. |
| - const TemplateURL* template_url = |
| - const_cast<TemplateURLService*>(this)->GetTemplateURLForKeyword(keyword); |
| + const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); |
| // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService |
| // to track changes to the model, this should become a DCHECK. |
| @@ -1264,7 +1282,7 @@ TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( |
| TemplateURLServiceClient* client, |
| PrefService* prefs, |
| const SearchTermsData& search_terms_data, |
| - TemplateURL* existing_turl, |
| + const TemplateURL* existing_turl, |
| const syncer::SyncData& sync_data, |
| syncer::SyncChangeList* change_list) { |
| DCHECK(change_list); |
| @@ -2237,10 +2255,7 @@ bool TemplateURLService::IsLocalTemplateURLBetter( |
| const TemplateURL* local_turl, |
| const TemplateURL* sync_turl, |
| bool prefer_local_default) const { |
| - // TODO(jeffschiller): Make GetTemplateURLForKeyword const and remove the |
| - // const_cast. |
| - DCHECK(const_cast<TemplateURLService*>(this)->GetTemplateURLForGUID( |
| - local_turl->sync_guid())); |
| + DCHECK(GetTemplateURLForGUID(local_turl->sync_guid())); |
| return local_turl->last_modified() > sync_turl->last_modified() || |
| local_turl->created_by_policy() || |
| (prefer_local_default && local_turl == GetDefaultSearchProvider()); |
| @@ -2418,7 +2433,7 @@ void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { |
| return; |
| } |
| - TemplateURL* turl = GetTemplateURLForGUID(new_guid); |
| + const TemplateURL* turl = GetTemplateURLForGUID(new_guid); |
| if (turl) |
| default_search_manager_.SetUserSelectedDefaultSearchEngine(turl->data()); |
| } |