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

Unified Diff: components/search_engines/template_url_service.cc

Issue 2816353002: Make const versions GetTemplateURLForKeyword, GetTemplateURLForGUID, GetTemplateURLForHost (Closed)
Patch Set: Make definition and declaration order of new functions match 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 side-by-side diff with in-line comments
Download patch
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 f4e7a85a2f3b1f32b92bb22dc90b30ec64c47974..b836f06804097860bb43b9ea5ab8ada373a90c5f 100644
--- a/components/search_engines/template_url_service.cc
+++ b/components/search_engines/template_url_service.cc
@@ -396,6 +396,13 @@ void TemplateURLService::AddMatchingDomainKeywords(
TemplateURL* TemplateURLService::GetTemplateURLForKeyword(
const base::string16& keyword) {
+ return const_cast<TemplateURL*>(
+ static_cast<const TemplateURLService*>(this)->
+ GetTemplateURLForKeyword(keyword));
+}
+
+const TemplateURL* TemplateURLService::GetTemplateURLForKeyword(
+ const base::string16& keyword) const {
KeywordToTURLAndMeaningfulLength::const_iterator elem(
keyword_to_turl_and_length_.find(keyword));
if (elem != keyword_to_turl_and_length_.end())
@@ -408,6 +415,13 @@ TemplateURL* TemplateURLService::GetTemplateURLForKeyword(
TemplateURL* TemplateURLService::GetTemplateURLForGUID(
const std::string& sync_guid) {
+return const_cast<TemplateURL*>(
+ static_cast<const TemplateURLService*>(this)->
+ GetTemplateURLForGUID(sync_guid));
+}
+
+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;
@@ -419,6 +433,13 @@ TemplateURL* TemplateURLService::GetTemplateURLForGUID(
TemplateURL* TemplateURLService::GetTemplateURLForHost(
const std::string& host) {
+ return const_cast<TemplateURL*>(
+ static_cast<const TemplateURLService*>(this)->
+ GetTemplateURLForHost(host));
+}
+
+const TemplateURL* TemplateURLService::GetTemplateURLForHost(
+ const std::string& host) const {
if (loaded_)
return provider_map_->GetTemplateURLForHost(host);
TemplateURL* initial_dsp = initial_default_search_provider_.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());
}
« no previous file with comments | « components/search_engines/template_url_service.h ('k') | ios/chrome/browser/ui/omnibox/chrome_omnibox_client_ios.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698