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(
bool ChromeAutocompleteProviderClient::StrippedURLsAreEqual(
const GURL& url1,
const GURL& url2,
const AutocompleteInput* input) {
const AutocompleteInput* input) const {
AutocompleteInput empty_input;
if (!input)
input = &empty_input;
TemplateURLService* template_url_service = GetTemplateURLService();
const TemplateURLService* template_url_service = GetTemplateURLService();
return AutocompleteMatch::GURLToStrippedGURL(url1, AutocompleteInput(),
template_url_service,
base::string16()) ==
......
......@@ -76,7 +76,7 @@ class ChromeAutocompleteProviderClient : public AutocompleteProviderClient {
bool StrippedURLsAreEqual(const GURL& url1,
const GURL& url2,
const AutocompleteInput* input);
const AutocompleteInput* input) const;
private:
Profile* profile_;
......
......@@ -178,7 +178,7 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary(
return;
}
TemplateURL* current_url;
const TemplateURL* current_url;
GURL url = handle->GetSearchableFormURL();
if (!url_service->CanAddAutogeneratedKeyword(keyword, url, &current_url))
return;
......
......@@ -438,9 +438,19 @@ TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
TemplateURLService* template_url_service,
const base::string16& keyword,
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)
return nullptr;
TemplateURL* template_url =
const TemplateURL* template_url =
keyword.empty() ? nullptr
: template_url_service->GetTemplateURLForKeyword(keyword);
return (template_url || host.empty()) ?
......@@ -451,7 +461,7 @@ TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
GURL AutocompleteMatch::GURLToStrippedGURL(
const GURL& url,
const AutocompleteInput& input,
TemplateURLService* template_url_service,
const TemplateURLService* template_url_service,
const base::string16& keyword) {
if (!url.is_valid())
return url;
......
......@@ -194,6 +194,10 @@ struct AutocompleteMatch {
TemplateURLService* template_url_service,
const base::string16& keyword,
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
// to http, and stripping excess query parameters. These conversions are
......@@ -212,7 +216,7 @@ struct AutocompleteMatch {
// seems to matter to the user.
static GURL GURLToStrippedGURL(const GURL& url,
const AutocompleteInput& input,
TemplateURLService* template_url_service,
const TemplateURLService* template_url_service,
const base::string16& keyword);
// Sets the |match_in_scheme|, |match_in_subdomain|, and |match_after_host|
......
......@@ -36,7 +36,7 @@ void SearchHostToURLsMap::Add(TemplateURL* 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(template_url);
DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, template_url->type());
......@@ -45,7 +45,8 @@ void SearchHostToURLsMap::Remove(TemplateURL* template_url) {
auto set_with_url =
std::find_if(host_to_urls_map_.begin(), host_to_urls_map_.end(),
[&](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())
......
......@@ -34,7 +34,7 @@ class SearchHostToURLsMap {
const SearchTermsData& search_terms_data);
// 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|,
// or NULL if there are no such TemplateURLs
......
......@@ -168,7 +168,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() {
DCHECK(model);
DCHECK(model->loaded());
TemplateURL* existing_url = nullptr;
const TemplateURL* existing_url = nullptr;
if (!model->CanAddAutogeneratedKeyword(keyword_, GURL(template_url_->url()),
&existing_url)) {
fetcher_->RequestCompleted(this); // WARNING: Deletes us!
......
......@@ -183,7 +183,7 @@ size_t GetMeaningfulKeywordLength(const base::string16& keyword,
}
bool Contains(TemplateURLService::OwnedTemplateURLVector* template_urls,
TemplateURL* turl) {
const TemplateURL* turl) {
return FindTemplateURL(template_urls, turl) != template_urls->end();
}
......@@ -304,11 +304,11 @@ void TemplateURLService::RegisterProfilePrefs(
bool TemplateURLService::CanAddAutogeneratedKeyword(
const base::string16& keyword,
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
// keywords. If we need to support empty kewords
// the code needs to change slightly.
TemplateURL* existing_url = GetTemplateURLForKeyword(keyword);
const TemplateURL* existing_url = GetTemplateURLForKeyword(keyword);
if (template_url_to_replace)
*template_url_to_replace = existing_url;
if (existing_url) {
......@@ -441,7 +441,7 @@ TemplateURL* TemplateURLService::AddWithOverrides(
return Add(std::move(template_url));
}
void TemplateURLService::Remove(TemplateURL* template_url) {
void TemplateURLService::Remove(const TemplateURL* template_url) {
RemoveNoNotify(template_url);
NotifyObservers();
}
......@@ -1370,7 +1370,7 @@ TemplateURL* TemplateURLService::BestEngineForKeyword(TemplateURL* engine1,
: engine1;
}
void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
void TemplateURLService::RemoveFromMaps(const TemplateURL* template_url) {
const base::string16& keyword = template_url->keyword();
DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword));
if (keyword_to_turl_and_length_[keyword].first == template_url) {
......@@ -1562,7 +1562,7 @@ bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
// functions.
// Search for conflicting keyword turl before updating values of
// existing_turl.
TemplateURL* conflicting_keyword_turl =
const TemplateURL* conflicting_keyword_turl =
FindNonExtensionTemplateURLForKeyword(new_values.keyword());
// Update existing turl with new values.
......@@ -1956,7 +1956,7 @@ TemplateURL* TemplateURLService::AddNoNotify(
return template_url_ptr;
}
void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) {
void TemplateURLService::RemoveNoNotify(const TemplateURL* template_url) {
DCHECK(template_url != default_search_provider_);
auto i = FindTemplateURL(&template_urls_, template_url);
......
......@@ -128,7 +128,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// a keyword for hosts already associated with a manually-edited keyword.
bool CanAddAutogeneratedKeyword(const base::string16& keyword,
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
// prepopulate list or created by policy.
......@@ -192,7 +192,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Removes the keyword from the model. This deletes the supplied TemplateURL.
// 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
// |extension_id|. Unlike with Remove(), this can be called when the
......@@ -494,7 +494,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Removes |template_url| from various internal maps
// (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|,
// |guid_to_turl_|, |provider_map_|).
void RemoveFromMaps(TemplateURL* template_url);
void RemoveFromMaps(const TemplateURL* template_url);
// Adds |template_url| to various internal maps
// (|keyword_to_turl_and_length_|, |keyword_domain_to_turl_and_length_|,
......@@ -613,7 +613,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Removes the keyword from the model. This deletes the supplied TemplateURL.
// This fails if the supplied template_url is the default search provider.
// 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
// 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