Chromium Code Reviews| Index: components/search_engines/template_url_parser.cc |
| diff --git a/components/search_engines/template_url_parser.cc b/components/search_engines/template_url_parser.cc |
| index 9c93747b27b419ef410f78226027f78762959461..1ec3453daf6579b8c7581af0b8400c9bfd68eefc 100644 |
| --- a/components/search_engines/template_url_parser.cc |
| +++ b/components/search_engines/template_url_parser.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/logging.h" |
| #include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -140,12 +141,13 @@ class TemplateURLParsingContext { |
| static void EndElementImpl(void* ctx, const xmlChar* name); |
| static void CharactersImpl(void* ctx, const xmlChar* ch, int len); |
| - // Returns a heap-allocated TemplateURL representing the result of parsing. |
| - // 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, |
| - // a resulting TemplateURLRef was invalid, etc.). |
| - TemplateURL* GetTemplateURL(const SearchTermsData& search_terms_data, |
| - bool show_in_default_list); |
| + // Returns a TemplateURL representing the result of parsing. This will be an |
| + // empty unique_ptr if parsing failed or if the results were invalid for some |
|
Peter Kasting
2016/09/01 22:55:41
Nit: "This will be null"?
Avi (use Gerrit)
2016/09/01 23:28:33
Done.
|
| + // reason (e.g. the resulting URL was not HTTP[S], a name wasn't supplied, a |
| + // resulting TemplateURLRef was invalid, etc.). |
| + std::unique_ptr<TemplateURL> GetTemplateURL( |
| + const SearchTermsData& search_terms_data, |
| + bool show_in_default_list); |
| private: |
| // Key is UTF8 encoded. |
| @@ -299,14 +301,14 @@ void TemplateURLParsingContext::CharactersImpl(void* ctx, |
| base::StringPiece(reinterpret_cast<const char*>(ch), len)); |
| } |
| -TemplateURL* TemplateURLParsingContext::GetTemplateURL( |
| +std::unique_ptr<TemplateURL> TemplateURLParsingContext::GetTemplateURL( |
| const SearchTermsData& search_terms_data, |
| bool show_in_default_list) { |
| // TODO(jcampan): Support engines that use POST; see http://crbug.com/18107 |
| if (method_ == TemplateURLParsingContext::POST || |
| data_.short_name().empty() || !IsHTTPRef(data_.url()) || |
| !IsHTTPRef(data_.suggestions_url)) |
| - return NULL; |
| + return std::unique_ptr<TemplateURL>(); |
|
Peter Kasting
2016/09/01 22:55:41
Nit: return nullptr?
|
| if (suggestion_method_ == TemplateURLParsingContext::POST) |
| data_.suggestions_url.clear(); |
| @@ -324,15 +326,16 @@ TemplateURL* TemplateURLParsingContext::GetTemplateURL( |
| data_.show_in_default_list = show_in_default_list; |
| // Bail if the search URL is empty or if either TemplateURLRef is invalid. |
| - std::unique_ptr<TemplateURL> template_url(new TemplateURL(data_)); |
| + std::unique_ptr<TemplateURL> template_url( |
|
Peter Kasting
2016/09/01 22:55:41
Nit: () -> =
Avi (use Gerrit)
2016/09/01 23:28:33
Done.
|
| + base::MakeUnique<TemplateURL>(data_)); |
| if (template_url->url().empty() || |
| !template_url->url_ref().IsValid(search_terms_data) || |
| (!template_url->suggestions_url().empty() && |
| !template_url->suggestions_url_ref().IsValid(search_terms_data))) { |
| - return NULL; |
| + return std::unique_ptr<TemplateURL>(); |
|
Peter Kasting
2016/09/01 22:55:41
Nit: return nullptr?
Avi (use Gerrit)
2016/09/01 23:28:33
Done.
|
| } |
| - return template_url.release(); |
| + return template_url; |
| } |
| // static |
| @@ -490,7 +493,7 @@ TemplateURLParsingContext::ElementType |
| // TemplateURLParser ---------------------------------------------------------- |
| // static |
| -TemplateURL* TemplateURLParser::Parse( |
| +std::unique_ptr<TemplateURL> TemplateURLParser::Parse( |
| const SearchTermsData& search_terms_data, |
| bool show_in_default_list, |
| const char* data, |
| @@ -511,6 +514,6 @@ TemplateURL* TemplateURLParser::Parse( |
| static_cast<int>(length)); |
| xmlSubstituteEntitiesDefault(last_sub_entities_value); |
| - return error ? |
| - NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); |
| + return error ? nullptr : context.GetTemplateURL(search_terms_data, |
| + show_in_default_list); |
| } |