Commit 499298a3 authored by Kevin Bailey's avatar Kevin Bailey Committed by Commit Bot

[omnibox] Make const some methods with TemplateURLs

Just making const some things that can be made const. Primarily
stemming from template_url_service.

Change-Id: If7e368a15fcf3ada82c074f808de5fa8b7c4a878
Reviewed-on: https://chromium-review.googlesource.com/959055
Commit-Queue: Kevin Bailey <krb@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543699}
parent 458cb43d
...@@ -393,11 +393,11 @@ bool ChromeAutocompleteProviderClient::IsTabOpenWithURL( ...@@ -393,11 +393,11 @@ bool ChromeAutocompleteProviderClient::IsTabOpenWithURL(
bool ChromeAutocompleteProviderClient::StrippedURLsAreEqual( bool ChromeAutocompleteProviderClient::StrippedURLsAreEqual(
const GURL& url1, const GURL& url1,
const GURL& url2, const GURL& url2,
const AutocompleteInput* input) { const AutocompleteInput* input) const {
AutocompleteInput empty_input; AutocompleteInput empty_input;
if (!input) if (!input)
input = &empty_input; input = &empty_input;
TemplateURLService* template_url_service = GetTemplateURLService(); const TemplateURLService* template_url_service = GetTemplateURLService();
return AutocompleteMatch::GURLToStrippedGURL(url1, AutocompleteInput(), return AutocompleteMatch::GURLToStrippedGURL(url1, AutocompleteInput(),
template_url_service, template_url_service,
base::string16()) == base::string16()) ==
......
...@@ -76,7 +76,7 @@ class ChromeAutocompleteProviderClient : public AutocompleteProviderClient { ...@@ -76,7 +76,7 @@ class ChromeAutocompleteProviderClient : public AutocompleteProviderClient {
bool StrippedURLsAreEqual(const GURL& url1, bool StrippedURLsAreEqual(const GURL& url1,
const GURL& url2, const GURL& url2,
const AutocompleteInput* input); const AutocompleteInput* input) const;
private: private:
Profile* profile_; Profile* profile_;
......
...@@ -178,7 +178,7 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary( ...@@ -178,7 +178,7 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary(
return; return;
} }
TemplateURL* current_url; const TemplateURL* current_url;
GURL url = handle->GetSearchableFormURL(); GURL url = handle->GetSearchableFormURL();
if (!url_service->CanAddAutogeneratedKeyword(keyword, url, &current_url)) if (!url_service->CanAddAutogeneratedKeyword(keyword, url, &current_url))
return; return;
......
...@@ -438,9 +438,19 @@ TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword( ...@@ -438,9 +438,19 @@ TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
TemplateURLService* template_url_service, TemplateURLService* template_url_service,
const base::string16& keyword, const base::string16& keyword,
const std::string& host) { const std::string& host) {
return const_cast<TemplateURL*>(GetTemplateURLWithKeyword(
static_cast<const TemplateURLService*>(template_url_service), keyword,
host));
}
// static
const TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
const TemplateURLService* template_url_service,
const base::string16& keyword,
const std::string& host) {
if (template_url_service == nullptr) if (template_url_service == nullptr)
return nullptr; return nullptr;
TemplateURL* template_url = const TemplateURL* template_url =
keyword.empty() ? nullptr keyword.empty() ? nullptr
: template_url_service->GetTemplateURLForKeyword(keyword); : template_url_service->GetTemplateURLForKeyword(keyword);
return (template_url || host.empty()) ? return (template_url || host.empty()) ?
...@@ -451,7 +461,7 @@ TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword( ...@@ -451,7 +461,7 @@ TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
GURL AutocompleteMatch::GURLToStrippedGURL( GURL AutocompleteMatch::GURLToStrippedGURL(
const GURL& url, const GURL& url,
const AutocompleteInput& input, const AutocompleteInput& input,
TemplateURLService* template_url_service, const TemplateURLService* template_url_service,
const base::string16& keyword) { const base::string16& keyword) {
if (!url.is_valid()) if (!url.is_valid())
return url; return url;
......
...@@ -194,6 +194,10 @@ struct AutocompleteMatch { ...@@ -194,6 +194,10 @@ struct AutocompleteMatch {
TemplateURLService* template_url_service, TemplateURLService* template_url_service,
const base::string16& keyword, const base::string16& keyword,
const std::string& host); const std::string& host);
static const TemplateURL* GetTemplateURLWithKeyword(
const TemplateURLService* template_url_service,
const base::string16& keyword,
const std::string& host);
// Returns |url| altered by stripping off "www.", converting https protocol // Returns |url| altered by stripping off "www.", converting https protocol
// to http, and stripping excess query parameters. These conversions are // to http, and stripping excess query parameters. These conversions are
...@@ -212,7 +216,7 @@ struct AutocompleteMatch { ...@@ -212,7 +216,7 @@ struct AutocompleteMatch {
// seems to matter to the user. // seems to matter to the user.
static GURL GURLToStrippedGURL(const GURL& url, static GURL GURLToStrippedGURL(const GURL& url,
const AutocompleteInput& input, const AutocompleteInput& input,
TemplateURLService* template_url_service, const TemplateURLService* template_url_service,
const base::string16& keyword); const base::string16& keyword);
// Sets the |match_in_scheme|, |match_in_subdomain|, and |match_after_host| // Sets the |match_in_scheme|, |match_in_subdomain|, and |match_after_host|
......
...@@ -36,7 +36,7 @@ void SearchHostToURLsMap::Add(TemplateURL* template_url, ...@@ -36,7 +36,7 @@ void SearchHostToURLsMap::Add(TemplateURL* template_url,
host_to_urls_map_[url.host()].insert(template_url); host_to_urls_map_[url.host()].insert(template_url);
} }
void SearchHostToURLsMap::Remove(TemplateURL* template_url) { void SearchHostToURLsMap::Remove(const TemplateURL* template_url) {
DCHECK(initialized_); DCHECK(initialized_);
DCHECK(template_url); DCHECK(template_url);
DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, template_url->type()); DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, template_url->type());
...@@ -45,7 +45,8 @@ void SearchHostToURLsMap::Remove(TemplateURL* template_url) { ...@@ -45,7 +45,8 @@ void SearchHostToURLsMap::Remove(TemplateURL* template_url) {
auto set_with_url = auto set_with_url =
std::find_if(host_to_urls_map_.begin(), host_to_urls_map_.end(), std::find_if(host_to_urls_map_.begin(), host_to_urls_map_.end(),
[&](std::pair<const std::string, TemplateURLSet>& entry) { [&](std::pair<const std::string, TemplateURLSet>& entry) {
return entry.second.erase(template_url); return entry.second.erase(
const_cast<TemplateURL*>(template_url));
}); });
if (set_with_url != host_to_urls_map_.end() && set_with_url->second.empty()) if (set_with_url != host_to_urls_map_.end() && set_with_url->second.empty())
......
...@@ -34,7 +34,7 @@ class SearchHostToURLsMap { ...@@ -34,7 +34,7 @@ class SearchHostToURLsMap {
const SearchTermsData& search_terms_data); const SearchTermsData& search_terms_data);
// Removes the TemplateURL from the lookup. // Removes the TemplateURL from the lookup.
void Remove(TemplateURL* template_url); void Remove(const TemplateURL* template_url);
// Returns the first TemplateURL found with a URL using the specified |host|, // Returns the first TemplateURL found with a URL using the specified |host|,
// or NULL if there are no such TemplateURLs // or NULL if there are no such TemplateURLs
......
...@@ -168,7 +168,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { ...@@ -168,7 +168,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() {
DCHECK(model); DCHECK(model);
DCHECK(model->loaded()); DCHECK(model->loaded());
TemplateURL* existing_url = nullptr; const TemplateURL* existing_url = nullptr;
if (!model->CanAddAutogeneratedKeyword(keyword_, GURL(template_url_->url()), if (!model->CanAddAutogeneratedKeyword(keyword_, GURL(template_url_->url()),
&existing_url)) { &existing_url)) {
fetcher_->RequestCompleted(this); // WARNING: Deletes us! fetcher_->RequestCompleted(this); // WARNING: Deletes us!
......
...@@ -183,7 +183,7 @@ size_t GetMeaningfulKeywordLength(const base::string16& keyword, ...@@ -183,7 +183,7 @@ size_t GetMeaningfulKeywordLength(const base::string16& keyword,
} }
bool Contains(TemplateURLService::OwnedTemplateURLVector* template_urls, bool Contains(TemplateURLService::OwnedTemplateURLVector* template_urls,
TemplateURL* turl) { const TemplateURL* turl) {
return FindTemplateURL(template_urls, turl) != template_urls->end(); return FindTemplateURL(template_urls, turl) != template_urls->end();
} }
...@@ -304,11 +304,11 @@ void TemplateURLService::RegisterProfilePrefs( ...@@ -304,11 +304,11 @@ void TemplateURLService::RegisterProfilePrefs(
bool TemplateURLService::CanAddAutogeneratedKeyword( bool TemplateURLService::CanAddAutogeneratedKeyword(
const base::string16& keyword, const base::string16& keyword,
const GURL& url, const GURL& url,
TemplateURL** template_url_to_replace) { const TemplateURL** template_url_to_replace) {
DCHECK(!keyword.empty()); // This should only be called for non-empty DCHECK(!keyword.empty()); // This should only be called for non-empty
// keywords. If we need to support empty kewords // keywords. If we need to support empty kewords
// the code needs to change slightly. // the code needs to change slightly.
TemplateURL* existing_url = GetTemplateURLForKeyword(keyword); const TemplateURL* existing_url = GetTemplateURLForKeyword(keyword);
if (template_url_to_replace) if (template_url_to_replace)
*template_url_to_replace = existing_url; *template_url_to_replace = existing_url;
if (existing_url) { if (existing_url) {
...@@ -441,7 +441,7 @@ TemplateURL* TemplateURLService::AddWithOverrides( ...@@ -441,7 +441,7 @@ TemplateURL* TemplateURLService::AddWithOverrides(
return Add(std::move(template_url)); return Add(std::move(template_url));
} }
void TemplateURLService::Remove(TemplateURL* template_url) { void TemplateURLService::Remove(const TemplateURL* template_url) {
RemoveNoNotify(template_url); RemoveNoNotify(template_url);
NotifyObservers(); NotifyObservers();
} }
...@@ -1370,7 +1370,7 @@ TemplateURL* TemplateURLService::BestEngineForKeyword(TemplateURL* engine1, ...@@ -1370,7 +1370,7 @@ TemplateURL* TemplateURLService::BestEngineForKeyword(TemplateURL* engine1,
: engine1; : engine1;
} }
void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) { void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) {
const base::string16& keyword = template_url->keyword(); const base::string16& keyword = template_url->keyword();
DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword)); DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword));
if (keyword_to_turl_and_length_[keyword].first == template_url) { if (keyword_to_turl_and_length_[keyword].first == template_url) {
...@@ -1562,7 +1562,7 @@ bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, ...@@ -1562,7 +1562,7 @@ bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
// functions. // functions.
// Search for conflicting keyword turl before updating values of // Search for conflicting keyword turl before updating values of
// existing_turl. // existing_turl.
TemplateURL* conflicting_keyword_turl = const TemplateURL* conflicting_keyword_turl =
FindNonExtensionTemplateURLForKeyword(new_values.keyword()); FindNonExtensionTemplateURLForKeyword(new_values.keyword());
// Update existing turl with new values. // Update existing turl with new values.
...@@ -1956,7 +1956,7 @@ TemplateURL* TemplateURLService::AddNoNotify( ...@@ -1956,7 +1956,7 @@ TemplateURL* TemplateURLService::AddNoNotify(
return template_url_ptr; return template_url_ptr;
} }
void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { void TemplateURLService::RemoveNoNotify(const TemplateURL* template_url) {
DCHECK(template_url != default_search_provider_); DCHECK(template_url != default_search_provider_);
auto i = FindTemplateURL(&template_urls_, template_url); auto i = FindTemplateURL(&template_urls_, template_url);
......
...@@ -128,7 +128,7 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -128,7 +128,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// a keyword for hosts already associated with a manually-edited keyword. // a keyword for hosts already associated with a manually-edited keyword.
bool CanAddAutogeneratedKeyword(const base::string16& keyword, bool CanAddAutogeneratedKeyword(const base::string16& keyword,
const GURL& url, const GURL& url,
TemplateURL** template_url_to_replace); const TemplateURL** template_url_to_replace);
// Returns whether the engine is a "pre-existing" engine, either from the // Returns whether the engine is a "pre-existing" engine, either from the
// prepopulate list or created by policy. // prepopulate list or created by policy.
...@@ -192,7 +192,7 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -192,7 +192,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Removes the keyword from the model. This deletes the supplied TemplateURL. // Removes the keyword from the model. This deletes the supplied TemplateURL.
// This fails if the supplied template_url is the default search provider. // This fails if the supplied template_url is the default search provider.
void Remove(TemplateURL* template_url); void Remove(const TemplateURL* template_url);
// Removes any TemplateURL of the specified |type| associated with // Removes any TemplateURL of the specified |type| associated with
// |extension_id|. Unlike with Remove(), this can be called when the // |extension_id|. Unlike with Remove(), this can be called when the
...@@ -494,7 +494,7 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -494,7 +494,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Removes |template_url| from various internal maps // Removes |template_url| from various internal maps
// (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|,
// |guid_to_turl_|, |provider_map_|). // |guid_to_turl_|, |provider_map_|).
void RemoveFromMaps(TemplateURL* template_url); void RemoveFromMaps(const TemplateURL* template_url);
// Adds |template_url| to various internal maps // Adds |template_url| to various internal maps
// (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|, // (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|,
...@@ -613,7 +613,7 @@ class TemplateURLService : public WebDataServiceConsumer, ...@@ -613,7 +613,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Removes the keyword from the model. This deletes the supplied TemplateURL. // Removes the keyword from the model. This deletes the supplied TemplateURL.
// This fails if the supplied template_url is the default search provider. // This fails if the supplied template_url is the default search provider.
// Caller is responsible for notifying observers. // Caller is responsible for notifying observers.
void RemoveNoNotify(TemplateURL* template_url); void RemoveNoNotify(const TemplateURL* template_url);
// Like ResetTemplateURL(), but instead of notifying observers, returns // Like ResetTemplateURL(), but instead of notifying observers, returns
// whether anything has changed. // whether anything has changed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment