Commit d0325408 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Eliminate |url_ref_| and use url_refs_.back().

BUG=789424
TEST=none

Change-Id: If6f9a889c5b67684c7157c451ccfc3e459c9e50d
Reviewed-on: https://chromium-review.googlesource.com/799850Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520842}
parent e16ce69a
......@@ -1155,7 +1155,6 @@ TemplateURL::AssociatedExtensionInfo::~AssociatedExtensionInfo() {
TemplateURL::TemplateURL(const TemplateURLData& data, Type type)
: data_(data),
url_ref_(nullptr),
suggestions_url_ref_(this, TemplateURLRef::SUGGEST),
image_url_ref_(this, TemplateURLRef::IMAGE),
new_tab_url_ref_(this, TemplateURLRef::NEW_TAB),
......@@ -1247,7 +1246,7 @@ base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
bool TemplateURL::SupportsReplacement(
const SearchTermsData& search_terms_data) const {
return url_ref_->SupportsReplacement(search_terms_data);
return url_ref().SupportsReplacement(search_terms_data);
}
bool TemplateURL::HasGoogleBaseURLs(
......@@ -1264,10 +1263,9 @@ bool TemplateURL::HasGoogleBaseURLs(
bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword(
const SearchTermsData& search_terms_data) const {
return (type_ == NORMAL) &&
url_ref_->HasGoogleBaseURLs(search_terms_data) &&
google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()),
google_util::DISALLOW_SUBDOMAIN);
return (type_ == NORMAL) && url_ref().HasGoogleBaseURLs(search_terms_data) &&
google_util::IsGoogleHostname(base::UTF16ToUTF8(data_.keyword()),
google_util::DISALLOW_SUBDOMAIN);
}
bool TemplateURL::HasSameKeywordAs(
......@@ -1386,10 +1384,10 @@ void TemplateURL::EncodeSearchTerms(
GURL TemplateURL::GenerateSearchURL(
const SearchTermsData& search_terms_data) const {
if (!url_ref_->IsValid(search_terms_data))
if (!url_ref().IsValid(search_terms_data))
return GURL();
if (!url_ref_->SupportsReplacement(search_terms_data))
if (!url_ref().SupportsReplacement(search_terms_data))
return GURL(url());
// Use something obscure for the search terms argument so that in the rare
......@@ -1397,7 +1395,7 @@ GURL TemplateURL::GenerateSearchURL(
// same url.
// TODO(jnd): Add additional parameters to get post data when the search URL
// has post parameters.
return GURL(url_ref_->ReplaceSearchTerms(
return GURL(url_ref().ReplaceSearchTerms(
TemplateURLRef::SearchTermsArgs(
base::ASCIIToUTF16("blah.blah.blah.blah.blah")),
search_terms_data, nullptr));
......@@ -1416,7 +1414,7 @@ void TemplateURL::CopyFrom(const TemplateURL& other) {
void TemplateURL::SetURL(const std::string& url) {
data_.SetURL(url);
engine_type_ = SEARCH_ENGINE_UNKNOWN;
url_ref_->InvalidateCachedValues();
url_ref().InvalidateCachedValues();
}
void TemplateURL::SetPrepopulateId(int id) {
......@@ -1455,14 +1453,11 @@ void TemplateURL::ResizeURLRefVector() {
if (url_refs_.size() == new_size)
return;
// See comment on TemplateURL::ExtractSearchTermsFromURL() for understanding
// the order of TemplateURLRefs in the |url_refs_| vector.
url_refs_.clear();
url_refs_.reserve(new_size);
for (size_t i = 0; i != data_.alternate_urls.size(); ++i)
url_refs_.emplace_back(this, i);
url_refs_.emplace_back(this, TemplateURLRef::SEARCH);
url_ref_ = &url_refs_.back();
}
bool TemplateURL::FindSearchTermsInURL(
......
......@@ -578,7 +578,7 @@ class TemplateURL {
const std::string& sync_guid() const { return data_.sync_guid; }
const std::vector<TemplateURLRef>& url_refs() const { return url_refs_; }
const TemplateURLRef& url_ref() const { return *url_ref_; }
const TemplateURLRef& url_ref() const { return url_refs_.back(); }
const TemplateURLRef& suggestions_url_ref() const {
return suggestions_url_ref_;
}
......@@ -624,13 +624,8 @@ class TemplateURL {
// Use the alternate URLs and the search URL to match the provided |url|
// and extract |search_terms| from it. Returns false and an empty
// |search_terms| if no search terms can be matched. The order in which the
// alternate URLs are listed dictates their priority, the URL at index 0 is
// treated as the highest priority and the primary search URL is treated as
// the lowest priority. For example, if a TemplateURL has alternate URL
// "http://foo/#q={searchTerms}" and search URL "http://foo/?q={searchTerms}",
// and the URL to be decoded is "http://foo/?q=a#q=b", the alternate URL will
// match first and the decoded search term will be "b".
// |search_terms| if no search terms can be matched. The URLs are matched in
// the order listed in |url_refs_| (see comment there).
bool ExtractSearchTermsFromURL(const GURL& url,
const SearchTermsData& search_terms_data,
base::string16* search_terms) const;
......@@ -688,7 +683,8 @@ class TemplateURL {
void ResetKeywordIfNecessary(const SearchTermsData& search_terms_data,
bool force);
// Resizes the |url_refs_| vector and sets |url_ref_| according to |data_|.
// Resizes the |url_refs_| vector, which always holds the search URL as the
// last item.
void ResizeURLRefVector();
// Uses the alternate URLs and the search URL to match the provided |url|
......@@ -704,14 +700,15 @@ class TemplateURL {
TemplateURLData data_;
// Contains TemplateURLRefs corresponding to the alternate URLs and the search
// URL. This vector must not be resized except by ResizeURLRefVector() to keep
// the |url_ref_| pointer correct.
// URL, in priority order: the URL at index 0 is treated as the highest
// priority and the primary search URL is treated as the lowest priority. For
// example, if a TemplateURL has alternate URL "http://foo/#q={searchTerms}"
// and search URL "http://foo/?q={searchTerms}", and the URL to be decoded is
// "http://foo/?q=a#q=b", the alternate URL will match first and the decoded
// search term will be "b". Note that since every TemplateURLRef has a
// primary search URL, this vector is never empty.
std::vector<TemplateURLRef> url_refs_;
// Points to the TemplateURLRef in |url_refs_| which corresponds to the search
// URL.
TemplateURLRef* url_ref_;
TemplateURLRef suggestions_url_ref_;
TemplateURLRef image_url_ref_;
TemplateURLRef new_tab_url_ref_;
......
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