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

Unified Diff: components/omnibox/search_provider.cc

Issue 603683004: [AiS] Remove answer contents from all matches other than the first. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test, respond to comments Created 6 years, 3 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
« no previous file with comments | « components/omnibox/search_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/omnibox/search_provider.cc
diff --git a/components/omnibox/search_provider.cc b/components/omnibox/search_provider.cc
index dca916af65b59ad6d826273a8ba9d026d04e9812..3511e34af637b40eb86d39f76c5a71559ade4ee3 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 or a different answer to another server-provided suggestion. In the
+ // future we may decide that we want to have 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.clear();
+ it->answer_type.clear();
+ }
+ }
+ }
+}
+
ACMatches::const_iterator SearchProvider::FindTopMatch() const {
ACMatches::const_iterator it = matches_.begin();
while ((it != matches_.end()) && !it->allowed_to_be_default_match)
« no previous file with comments | « components/omnibox/search_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698