Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete_match.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/autocomplete_match.cc (revision 93757) |
| +++ chrome/browser/autocomplete/autocomplete_match.cc (working copy) |
| @@ -37,9 +37,64 @@ |
| from_previous(false) { |
| } |
| +AutocompleteMatch::AutocompleteMatch(const AutocompleteMatch& match) |
| + : provider(match.provider), |
| + relevance(match.relevance), |
| + deletable(match.deletable), |
| + inline_autocomplete_offset(match.inline_autocomplete_offset), |
| + transition(match.transition), |
| + is_history_what_you_typed_match(match.is_history_what_you_typed_match), |
| + type(match.type), |
| + keyword(match.keyword), |
| + template_url(match.template_url), |
| + starred(match.starred), |
| + from_previous(match.from_previous), |
| + fill_into_edit(match.fill_into_edit), |
| + destination_url(match.destination_url), |
| + stripped_destination_url(match.stripped_destination_url), |
| + contents(match.contents), |
| + contents_class(match.contents_class), |
| + description(match.description), |
| + description_class(match.description_class) { |
| + if (match.associated_keyword.get()) |
| + associated_keyword.reset(new AutocompleteMatch(*match.associated_keyword)); |
| +} |
| + |
| AutocompleteMatch::~AutocompleteMatch() { |
| } |
| +AutocompleteMatch& AutocompleteMatch::operator=( |
| + const AutocompleteMatch& match) { |
| + if (this == &match) |
| + return *this; |
| + |
| + provider = match.provider; |
| + relevance = match.relevance; |
| + deletable = match.deletable; |
| + inline_autocomplete_offset = match.inline_autocomplete_offset; |
| + transition = match.transition; |
| + is_history_what_you_typed_match = match.is_history_what_you_typed_match; |
| + type = match.type; |
| + keyword = match.keyword; |
| + template_url = match.template_url; |
| + starred = match.starred; |
| + from_previous = match.from_previous; |
| + fill_into_edit = match.fill_into_edit; |
| + destination_url = match.destination_url; |
| + stripped_destination_url = match.stripped_destination_url; |
| + contents = match.contents; |
| + contents_class = match.contents_class; |
| + description = match.description; |
| + description_class = match.description_class; |
| + |
| + if (match.associated_keyword.get()) |
|
Peter Kasting
2011/07/27 20:18:25
Nit: Shorter:
associated_keyword.reset(match.as
|
| + associated_keyword.reset(new AutocompleteMatch(*match.associated_keyword)); |
| + else |
| + associated_keyword.reset(NULL); |
| + |
| + return *this; |
| +} |
| + |
| // static |
| std::string AutocompleteMatch::TypeToString(Type type) { |
| const char* strings[] = { |
| @@ -98,15 +153,15 @@ |
| // Sort identical destination_urls together. Place the most relevant matches |
| // first, so that when we call std::unique(), these are the ones that get |
| // preserved. |
| - return (elem1.destination_url != elem2.destination_url) ? |
| - (elem1.destination_url < elem2.destination_url) : |
| + return (elem1.stripped_destination_url != elem2.stripped_destination_url) ? |
| + (elem1.stripped_destination_url < elem2.stripped_destination_url) : |
| MoreRelevant(elem1, elem2); |
| } |
| // static |
| bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1, |
| const AutocompleteMatch& elem2) { |
| - return elem1.destination_url == elem2.destination_url; |
| + return elem1.stripped_destination_url == elem2.stripped_destination_url; |
| } |
| // static |
| @@ -156,6 +211,22 @@ |
| } |
| } |
| +void AutocompleteMatch::ComputeStrippedDestinationURL() { |
| + static const char prefix[] = "www."; |
| + static const size_t prefix_len = arraysize(prefix) - 1; |
| + |
| + std::string host = destination_url.host(); |
| + if (destination_url.is_valid() && host.compare(0, prefix_len, prefix) == 0) { |
| + host = host.substr(prefix_len); |
| + GURL::Replacements replace_host; |
| + replace_host.SetHostStr(host); |
| + stripped_destination_url = |
| + destination_url.ReplaceComponents(replace_host); |
| + } else { |
| + stripped_destination_url = destination_url; |
| + } |
| +} |
| + |
| #ifndef NDEBUG |
| void AutocompleteMatch::Validate() const { |
| ValidateClassifications(contents, contents_class); |