Chromium Code Reviews| Index: components/omnibox/search_provider.cc |
| diff --git a/components/omnibox/search_provider.cc b/components/omnibox/search_provider.cc |
| index 41763048fb52a74899b507382e64b6f902d82fae..408fc46166c14aef740ce07669a0c199ba7e59fe 100644 |
| --- a/components/omnibox/search_provider.cc |
| +++ b/components/omnibox/search_provider.cc |
| @@ -873,7 +873,7 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
| // scores, unless we have already accepted AutocompleteResult::kMaxMatches |
| // higher-scoring matches under the conditions above. |
| std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
| - matches_.clear(); |
| + |
| // Guarantee that if there's a legal default match anywhere in the result |
| // set that it'll get returned. The rotate() call does this by moving the |
| // default match to the front of the list. |
| @@ -881,6 +881,15 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
| if (default_match != matches.end()) |
| std::rotate(matches.begin(), default_match, default_match + 1); |
| + // It's possible to get a copy of an answer from previous matches and get the |
| + // same answer attached to a similar server-provided answer. In the future, |
| + // we may decide that we want to have different answers attached to multiple |
| + // suggestions, but the current assumption is that there should only ever be |
| + // one suggestion with an answer. To maintain this assumption, remove any |
| + // answers after the first. |
| + RemoveExtraAnswers(&matches); |
| + |
| + matches_.clear(); |
| size_t num_suggestions = 0; |
| for (ACMatches::const_iterator i(matches.begin()); |
| (i != matches.end()) && |
| @@ -908,6 +917,20 @@ void SearchProvider::ConvertResultsToAutocompleteMatches() { |
| base::TimeTicks::Now() - start_time); |
| } |
| +void SearchProvider::RemoveExtraAnswers(ACMatches* matches) { |
| + bool answer_seen = false; |
| + for (ACMatches::iterator it = matches->begin(); it != matches->end(); ++it) { |
| + if (!it->answer_contents.empty()) { |
| + if (!answer_seen) { |
| + answer_seen = true; |
| + } else { |
| + it->answer_contents = base::string16(); |
|
groby-ooo-7-16
2014/09/24 22:26:38
nit: answer_contents.clear()/answer_type.clear() m
Justin Donnelly
2014/09/25 01:05:13
Done.
|
| + it->answer_type = base::string16(); |
| + } |
| + } |
| + } |
| +} |
| + |
| ACMatches::const_iterator SearchProvider::FindTopMatch() const { |
| ACMatches::const_iterator it = matches_.begin(); |
| while ((it != matches_.end()) && !it->allowed_to_be_default_match) |