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

Unified Diff: chrome/browser/search_engines/template_url_parser.cc

Issue 10021008: Reland r131019: Move most TemplateURL data members to a new struct, TemplateURLData. This allows us… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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: chrome/browser/search_engines/template_url_parser.cc
===================================================================
--- chrome/browser/search_engines/template_url_parser.cc (revision 131175)
+++ chrome/browser/search_engines/template_url_parser.cc (working copy)
@@ -145,7 +145,7 @@
// This will be NULL if parsing failed or if the results were invalid for some
// reason (e.g. the resulting URL was not HTTP[S], a name wasn't supplied,
// etc.).
- TemplateURL* GetTemplateURL(Profile* profile);
+ TemplateURL* GetTemplateURL(Profile* profile, bool show_in_default_list);
private:
// Key is UTF8 encoded.
@@ -163,7 +163,9 @@
static ElementNameToElementTypeMap* kElementNameToElementTypeMap;
- scoped_ptr<TemplateURL> url_;
+ // Data that gets updated as we parse, and is converted to a TemplateURL by
+ // GetTemplateURL().
+ TemplateURLData data_;
std::vector<ElementType> elements_;
bool image_is_valid_for_favicon_;
@@ -197,8 +199,7 @@
TemplateURLParsingContext::TemplateURLParsingContext(
TemplateURLParser::ParameterFilter* parameter_filter)
- : url_(new TemplateURL()),
- image_is_valid_for_favicon_(false),
+ : image_is_valid_for_favicon_(false),
parameter_filter_(parameter_filter),
method_(GET),
suggestion_method_(GET),
@@ -206,9 +207,9 @@
derive_image_from_url_(false) {
if (kElementNameToElementTypeMap == NULL)
InitMapping();
- // When combined with proscriptions elsewhere against updating url_->url_ to
- // the empty string, this call ensures url_->url() will never be NULL.
- url_->SetURL("x");
+ // When combined with proscriptions elsewhere against updating data_->url_ to
+ // the empty string, this call ensures data_->url() will never be NULL.
+ data_.SetURL("x");
}
// static
@@ -249,7 +250,7 @@
reinterpret_cast<TemplateURLParsingContext*>(ctx);
switch (context->GetKnownType()) {
case TemplateURLParsingContext::SHORT_NAME:
- context->url_->short_name_ = context->string_;
+ context->data_.short_name = context->string_;
break;
case TemplateURLParsingContext::IMAGE: {
GURL image_url(UTF16ToUTF8(context->string_));
@@ -261,7 +262,7 @@
} else if (context->image_is_valid_for_favicon_ && image_url.is_valid() &&
(image_url.SchemeIs(chrome::kHttpScheme) ||
image_url.SchemeIs(chrome::kHttpsScheme))) {
- context->url_->set_favicon_url(image_url);
+ context->data_.favicon_url = image_url;
}
context->image_is_valid_for_favicon_ = false;
break;
@@ -269,7 +270,7 @@
case TemplateURLParsingContext::INPUT_ENCODING: {
std::string input_encoding = UTF16ToASCII(context->string_);
if (IsValidEncodingString(input_encoding))
- context->url_->input_encodings_.push_back(input_encoding);
+ context->data_.input_encodings.push_back(input_encoding);
break;
}
case TemplateURLParsingContext::URL:
@@ -290,30 +291,33 @@
UTF8ToUTF16(std::string(reinterpret_cast<const char*>(ch), len));
}
-TemplateURL* TemplateURLParsingContext::GetTemplateURL(Profile* profile) {
+TemplateURL* TemplateURLParsingContext::GetTemplateURL(
+ Profile* profile,
+ bool show_in_default_list) {
// Basic legality checks.
- if (url_->short_name_.empty() || !IsHTTPRef(url_->url()) ||
- !IsHTTPRef(url_->suggestions_url()))
+ if (data_.short_name.empty() || !IsHTTPRef(data_.url()) ||
+ !IsHTTPRef(data_.suggestions_url))
return NULL;
// If the image was a data URL, use the favicon from the search URL instead.
// (see TODO inEndElementImpl()).
- GURL url(url_->url());
- if (derive_image_from_url_ && url_->favicon_url().is_empty())
- url_->set_favicon_url(TemplateURL::GenerateFaviconURL(url));
+ GURL url(data_.url());
+ if (derive_image_from_url_ && data_.favicon_url.is_empty())
+ data_.favicon_url = TemplateURL::GenerateFaviconURL(url);
// TODO(jcampan): http://b/issue?id=1196285 we do not support search engines
// that use POST yet.
if (method_ == TemplateURLParsingContext::POST)
return NULL;
if (suggestion_method_ == TemplateURLParsingContext::POST)
- url_->SetSuggestionsURL(std::string());
+ data_.suggestions_url.clear();
// Give this a keyword to facilitate tab-to-search.
string16 keyword(TemplateURLService::GenerateKeyword(url, false));
DCHECK(!keyword.empty());
- url_->set_keyword(keyword);
- return url_.release();
+ data_.SetKeyword(keyword);
+ data_.show_in_default_list = show_in_default_list;
+ return new TemplateURL(data_);
}
// static
@@ -353,12 +357,12 @@
}
if (is_html_url && !template_url.empty()) {
- url_->SetURL(template_url);
+ data_.SetURL(template_url);
is_suggest_url_ = false;
if (is_post)
method_ = POST;
} else if (is_suggest_url) {
- url_->SetSuggestionsURL(template_url);
+ data_.suggestions_url = template_url;
is_suggest_url_ = true;
if (is_post)
suggestion_method_ = POST;
@@ -413,7 +417,7 @@
if (!parameter_filter_ && extra_params_.empty())
return;
- GURL url(is_suggest_url_ ? url_->suggestions_url() : url_->url());
+ GURL url(is_suggest_url_ ? data_.suggestions_url : data_.url());
if (url.is_empty())
return;
@@ -451,9 +455,9 @@
repl.SetQueryStr(new_query);
url = url.ReplaceComponents(repl);
if (is_suggest_url_)
- url_->SetSuggestionsURL(url.spec());
+ data_.suggestions_url = url.spec();
else if (url.is_valid())
- url_->SetURL(url.spec());
+ data_.SetURL(url.spec());
}
}
@@ -472,6 +476,7 @@
// static
TemplateURL* TemplateURLParser::Parse(
Profile* profile,
+ bool show_in_default_list,
const char* data,
size_t length,
TemplateURLParser::ParameterFilter* param_filter) {
@@ -489,5 +494,5 @@
xmlSAXUserParseMemory(&sax_handler, &context, data, static_cast<int>(length));
xmlSubstituteEntitiesDefault(last_sub_entities_value);
- return context.GetTemplateURL(profile);
+ return context.GetTemplateURL(profile, show_in_default_list);
}
« no previous file with comments | « chrome/browser/search_engines/template_url_parser.h ('k') | chrome/browser/search_engines/template_url_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698