Chromium Code Reviews| Index: chrome/browser/autocomplete/search_provider.cc |
| diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc |
| index 2e79b08f3841cd8c1562bf669ea5ce13ea10a12b..ff2d4b95475cbd77fd27def3d3a15943eaf0a07d 100644 |
| --- a/chrome/browser/autocomplete/search_provider.cc |
| +++ b/chrome/browser/autocomplete/search_provider.cc |
| @@ -1307,15 +1307,27 @@ ACMatches::const_iterator SearchProvider::FindTopMatch( |
| return it; |
| } |
| -bool SearchProvider::IsTopMatchNavigationInKeywordMode( |
| +bool SearchProvider::IsTopMatchNavigation( |
|
msw
2013/11/20 21:05:03
Keep this as IsTopMatchNavigationInKeywordMode. I
Mark P
2013/11/21 21:30:22
Okay. I don't feel strongly.
|
| bool autocomplete_result_will_reorder_for_default_match) const { |
| ACMatches::const_iterator first_match = |
| FindTopMatch(autocomplete_result_will_reorder_for_default_match); |
| - return !providers_.keyword_provider().empty() && |
| - (first_match != matches_.end()) && |
| + return (first_match != matches_.end()) && |
| (first_match->type == AutocompleteMatchType::NAVSUGGEST); |
| } |
| +bool SearchProvider::HasKeywordMatchThatCanBeDefault() const { |
|
msw
2013/11/20 21:05:03
Rename this to HasValidDefaultMatchInKeywordMode t
Mark P
2013/11/21 21:30:22
Revised it to something similar to your suggested
|
| + const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
| + if (keyword_url == NULL) // not in keyword mode -> say everything's okay |
|
msw
2013/11/20 21:05:03
nit: Please make this comment more formal.
Mark P
2013/11/21 21:30:22
Done.
|
| + return true; |
| + for (ACMatches::const_iterator it = matches_.begin(); it != matches_.end(); |
| + ++it) { |
| + if ((it->keyword == keyword_url->keyword()) && |
| + it->allowed_to_be_default_match) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| bool SearchProvider::IsTopMatchScoreTooLow( |
| bool autocomplete_result_will_reorder_for_default_match) const { |
| // In reorder mode, there's no such thing as a score that's too low. |
| @@ -1364,8 +1376,15 @@ bool SearchProvider::HasValidDefaultMatch( |
| void SearchProvider::UpdateMatches() { |
| base::TimeTicks update_matches_start_time(base::TimeTicks::Now()); |
| + const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
| ConvertResultsToAutocompleteMatches(); |
| + // True if the omnibox will reorder matches as necessary to make the first |
|
msw
2013/11/20 21:05:03
nit: you don't check this outside the if block; le
Mark P
2013/11/21 21:30:22
Good point. That code movement comes from an earl
|
| + // one something that is allowed to be the default match. |
| + const bool omnibox_will_reorder_for_legal_default_match = |
| + OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| + input_.current_page_classification()); |
| + |
| // Check constraints that may be violated by suggested relevances. |
| if (!matches_.empty() && |
| (default_results_.HasServerProvidedScores() || |
| @@ -1373,26 +1392,27 @@ void SearchProvider::UpdateMatches() { |
| // These blocks attempt to repair undesirable behavior by suggested |
| // relevances with minimal impact, preserving other suggested relevances. |
| - // True if the omnibox will reorder matches as necessary to make the first |
| - // one something that is allowed to be the default match. |
| - const bool omnibox_will_reorder_for_legal_default_match = |
| - OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
| - input_.current_page_classification()); |
| - if (IsTopMatchNavigationInKeywordMode( |
| - omnibox_will_reorder_for_legal_default_match)) { |
| + if ((keyword_url != NULL) && |
| + IsTopMatchNavigation(omnibox_will_reorder_for_legal_default_match)) { |
| // Correct the suggested relevance scores if the top match is a |
| // navigation in keyword mode, since inlining a navigation match |
| - // would break the user out of keyword mode. By the way, if the top |
| - // match is a non-keyword match (query or navsuggestion) in keyword |
| - // mode, the user would also break out of keyword mode. However, |
| - // that situation is impossible given the current scoring paradigm |
| - // and the fact that only one search engine (Google) provides suggested |
| - // relevance scores at this time. |
| + // would break the user out of keyword mode. This will only be |
| + // triggered in regular (non-reorder) mode; in reorder mode, |
| + // navigation matches are marked as not allowed to be the default |
| + // match and hence IsTopMatchNavigation() will always return false. |
| + DCHECK(!omnibox_will_reorder_for_legal_default_match); |
| DemoteKeywordNavigationMatchesPastTopQuery(); |
| ConvertResultsToAutocompleteMatches(); |
| - DCHECK(!IsTopMatchNavigationInKeywordMode( |
| + DCHECK(!IsTopMatchNavigation( |
|
msw
2013/11/20 21:05:03
nit: remove this DCHECK; it's redundant with the o
Mark P
2013/11/21 21:30:22
I'd prefer to keep it to verify that DemoteKeyword
msw
2013/11/21 22:11:11
Good call!
Mark P
2013/11/22 01:17:57
Acknowledged.
|
| omnibox_will_reorder_for_legal_default_match)); |
| } |
| + if ((keyword_url != NULL) && !HasKeywordMatchThatCanBeDefault()) { |
|
msw
2013/11/20 21:05:03
Like IsTopMatchNavigation[InKeywordMode], I'd pref
Mark P
2013/11/21 21:30:22
Okay.
|
| + // In keyword mode, disregard the keyword verbatim suggested relevance |
| + // if necessary so there at least one keyword match that's allowed to |
| + // be the default match. |
| + keyword_results_.verbatim_relevance = -1; |
| + ConvertResultsToAutocompleteMatches(); |
| + } |
| if (IsTopMatchScoreTooLow(omnibox_will_reorder_for_legal_default_match)) { |
| // Disregard the suggested verbatim relevance if the top score is below |
| // the usual verbatim value. For example, a BarProvider may rely on |
| @@ -1429,8 +1449,9 @@ void SearchProvider::UpdateMatches() { |
| ApplyCalculatedRelevance(); |
| ConvertResultsToAutocompleteMatches(); |
| } |
| - DCHECK(!IsTopMatchNavigationInKeywordMode( |
| - omnibox_will_reorder_for_legal_default_match)); |
| + DCHECK((keyword_url == NULL) || |
| + !IsTopMatchNavigation(omnibox_will_reorder_for_legal_default_match)); |
| + DCHECK((keyword_url == NULL) || HasKeywordMatchThatCanBeDefault()); |
| DCHECK(!IsTopMatchScoreTooLow( |
| omnibox_will_reorder_for_legal_default_match)); |
| DCHECK(!IsTopMatchSearchWithURLInput( |
| @@ -1438,6 +1459,17 @@ void SearchProvider::UpdateMatches() { |
| DCHECK(HasValidDefaultMatch(omnibox_will_reorder_for_legal_default_match)); |
| } |
| + if ((keyword_url != NULL) && HasKeywordMatchThatCanBeDefault()) { |
| + // If there is a keyword match that is allowed to be the default match, |
| + // then prohibit default provider matches from being the defaul match lest |
|
msw
2013/11/20 21:05:03
nit: defaul->default
Mark P
2013/11/21 21:30:22
Done.
|
| + // such matches cause the user to break out of keyword mode. |
| + for (ACMatches::iterator it = matches_.begin(); it != matches_.end(); |
| + ++it) { |
| + if (it->keyword != keyword_url->keyword()) |
| + it->allowed_to_be_default_match = false; |
| + } |
| + } |
| + |
| base::TimeTicks update_starred_start_time(base::TimeTicks::Now()); |
| UpdateStarredStateOfMatches(); |
| UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.UpdateStarredTime", |
| @@ -1839,7 +1871,11 @@ AutocompleteMatch SearchProvider::NavigationToMatch( |
| if (!input_.prevent_inline_autocomplete() && |
| (inline_autocomplete_offset != string16::npos)) { |
| DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
| - match.allowed_to_be_default_match = true; |
| + // A navsuggestion can only be the default match when there is no |
| + // keyword provider active, lest it appear first and break the user |
| + // out of keyword mode. |
| + match.allowed_to_be_default_match = |
| + (providers_.GetKeywordProviderURL() == NULL); |
| match.inline_autocompletion = |
| match.fill_into_edit.substr(inline_autocomplete_offset); |
| } |