Chromium Code Reviews| Index: chrome/browser/autocomplete/history_url_provider.cc |
| diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc |
| index 0c395ef89ac1f5746352c488ef4cbbe0bf956bcd..2f7a563834819a42159d7cde11774564651c0d55 100644 |
| --- a/chrome/browser/autocomplete/history_url_provider.cc |
| +++ b/chrome/browser/autocomplete/history_url_provider.cc |
| @@ -568,7 +568,7 @@ void HistoryURLProvider::Start(const AutocompleteInput& input, |
| if (url_db) { |
| DoAutocomplete(NULL, url_db, params.get()); |
| matches_.clear(); |
| - PromoteMatchIfNecessary(*params); |
| + PromoteMatchesIfNecessary(*params); |
| // NOTE: We don't reset |params| here since at least the |promote_type| |
| // field on it will be read by the second pass -- see comments in |
| // DoAutocomplete(). |
| @@ -766,7 +766,7 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, |
| // searching has been disabled by policy. In the cases where we've parsed as |
| // UNKNOWN, we'll still show an accidental search infobar if need be. |
| VisitClassifier classifier(this, params->input, db); |
| - bool have_what_you_typed_match = |
| + params->have_what_you_typed_match = |
| (params->input.type() != metrics::OmniboxInputType::QUERY) && |
| ((params->input.type() != metrics::OmniboxInputType::UNKNOWN) || |
| (classifier.type() == VisitClassifier::UNVISITED_INTRANET) || |
| @@ -774,7 +774,7 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, |
| (AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0) || |
| !params->default_search_provider); |
| const bool have_shorter_suggestion_suitable_for_inline_autocomplete = |
| - PromoteOrCreateShorterSuggestion(db, have_what_you_typed_match, params); |
| + PromoteOrCreateShorterSuggestion(db, params); |
| // Check whether what the user typed appears in history. |
| const bool can_check_history_for_exact_match = |
| @@ -802,13 +802,13 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, |
| // this input, so we can promote that as the best match. |
| if (params->exact_suggestion_is_in_history) { |
| params->promote_type = HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH; |
| - } else if (!params->prevent_inline_autocomplete && !params->matches.empty() && |
| - (have_shorter_suggestion_suitable_for_inline_autocomplete || |
| - CanPromoteMatchForInlineAutocomplete(params->matches[0]))) { |
| + } else if (!params->matches.empty() && |
|
Peter Kasting
2015/03/24 22:02:43
Rather than just removing the |prevent_inline_auto
Mark P
2015/03/24 22:35:46
This is not a problem. Promoting has to do with s
Peter Kasting
2015/03/24 23:05:19
That is fine as long as SearchProvider always actu
Mark P
2015/03/25 19:04:57
SearchProvider is always supposed to provide a leg
|
| + (have_shorter_suggestion_suitable_for_inline_autocomplete || |
| + CanPromoteMatchForInlineAutocomplete(params->matches[0]))) { |
| params->promote_type = HistoryURLProviderParams::FRONT_HISTORY_MATCH; |
|
Peter Kasting
2015/03/24 23:05:19
OK, so let's put something like this comment here:
Mark P
2015/03/25 19:04:57
Okay, that's a nice clarification to add. Added w
|
| } else { |
| // Failed to promote any URLs. Use the What You Typed match, if we have it. |
| - params->promote_type = have_what_you_typed_match ? |
| + params->promote_type = params->have_what_you_typed_match ? |
| HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH : |
| HistoryURLProviderParams::NEITHER; |
| } |
| @@ -826,15 +826,24 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, |
| } |
| } |
| -void HistoryURLProvider::PromoteMatchIfNecessary( |
| +void HistoryURLProvider::PromoteMatchesIfNecessary( |
| const HistoryURLProviderParams& params) { |
| if (params.promote_type == HistoryURLProviderParams::NEITHER) |
| return; |
| - matches_.push_back( |
| - (params.promote_type == HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH) ? |
| - params.what_you_typed_match : |
| - HistoryMatchToACMatch(params, 0, INLINE_AUTOCOMPLETE, |
| - CalculateRelevance(INLINE_AUTOCOMPLETE, 0))); |
| + if (params.promote_type == HistoryURLProviderParams::FRONT_HISTORY_MATCH) { |
| + matches_.push_back( |
| + HistoryMatchToACMatch(params, 0, INLINE_AUTOCOMPLETE, |
| + CalculateRelevance(INLINE_AUTOCOMPLETE, 0))); |
| + } |
| + // Add the what-you-typed match if we're explicitly told to or if we might |
| + // need it (because inline autocompletion is disabled, i.e., no other URL |
| + // suggestion is allowed to be the default match) and it's eligible for |
| + // display. |
|
Peter Kasting
2015/03/24 22:02:43
After thinking more, this code is correct.
Mark P
2015/03/24 22:35:46
Acknowledged.
Peter Kasting
2015/03/24 23:05:19
Let's make the comment here something like this:
Mark P
2015/03/25 19:04:57
Done with trivial edits.
|
| + if ((params.promote_type == HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH) || |
| + (params.prevent_inline_autocomplete && |
| + params.have_what_you_typed_match)) { |
| + matches_.push_back(params.what_you_typed_match); |
| + } |
| } |
| void HistoryURLProvider::QueryComplete( |
| @@ -855,7 +864,7 @@ void HistoryURLProvider::QueryComplete( |
| // match in it, whereas |params->matches| will be empty. |
| if (!params->failed) { |
| matches_.clear(); |
| - PromoteMatchIfNecessary(*params); |
| + PromoteMatchesIfNecessary(*params); |
| // Determine relevance of highest scoring match, if any. |
| int relevance = matches_.empty() ? |
| @@ -956,7 +965,6 @@ bool HistoryURLProvider::CanFindIntranetURL( |
| bool HistoryURLProvider::PromoteOrCreateShorterSuggestion( |
| history::URLDatabase* db, |
| - bool have_what_you_typed_match, |
| HistoryURLProviderParams* params) { |
| if (params->matches.empty()) |
| return false; // No matches, nothing to do. |
| @@ -966,7 +974,7 @@ bool HistoryURLProvider::PromoteOrCreateShorterSuggestion( |
| // the same" as any "what you typed" match. |
| const history::HistoryMatch& match = params->matches[0]; |
| GURL search_base = ConvertToHostOnly(match, params->input.text()); |
| - bool can_add_search_base_to_matches = !have_what_you_typed_match; |
| + bool can_add_search_base_to_matches = !params->have_what_you_typed_match; |
| if (search_base.is_empty()) { |
| // Search from what the user typed when we couldn't reduce the best match |
| // to a host. Careful: use a substring of |match| here, rather than the |