| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 ConvertResultsToAutocompleteMatches(); | 508 ConvertResultsToAutocompleteMatches(); |
| 509 | 509 |
| 510 // Check constraints that may be violated by suggested relevances. | 510 // Check constraints that may be violated by suggested relevances. |
| 511 if (!matches_.empty() && | 511 if (!matches_.empty() && |
| 512 (default_results_.HasServerProvidedScores() || | 512 (default_results_.HasServerProvidedScores() || |
| 513 keyword_results_.HasServerProvidedScores())) { | 513 keyword_results_.HasServerProvidedScores())) { |
| 514 // These blocks attempt to repair undesirable behavior by suggested | 514 // These blocks attempt to repair undesirable behavior by suggested |
| 515 // relevances with minimal impact, preserving other suggested relevances. | 515 // relevances with minimal impact, preserving other suggested relevances. |
| 516 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 516 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
| 517 const bool is_extension_keyword = (keyword_url != NULL) && | 517 const bool is_extension_keyword = (keyword_url != NULL) && |
| 518 (keyword_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION); | 518 (keyword_url->type() == TemplateURL::OMNIBOX_API_EXTENSION); |
| 519 if ((keyword_url != NULL) && !is_extension_keyword && | 519 if ((keyword_url != NULL) && !is_extension_keyword && |
| 520 (FindTopMatch() == matches_.end())) { | 520 (FindTopMatch() == matches_.end())) { |
| 521 // In non-extension keyword mode, disregard the keyword verbatim suggested | 521 // In non-extension keyword mode, disregard the keyword verbatim suggested |
| 522 // relevance if necessary, so at least one match is allowed to be default. | 522 // relevance if necessary, so at least one match is allowed to be default. |
| 523 // (In extension keyword mode this is not necessary because the extension | 523 // (In extension keyword mode this is not necessary because the extension |
| 524 // will return a default match.) Give keyword verbatim the lowest | 524 // will return a default match.) Give keyword verbatim the lowest |
| 525 // non-zero score to best reflect what the server desired. | 525 // non-zero score to best reflect what the server desired. |
| 526 DCHECK_EQ(0, keyword_results_.verbatim_relevance); | 526 DCHECK_EQ(0, keyword_results_.verbatim_relevance); |
| 527 keyword_results_.verbatim_relevance = 1; | 527 keyword_results_.verbatim_relevance = 1; |
| 528 ConvertResultsToAutocompleteMatches(); | 528 ConvertResultsToAutocompleteMatches(); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 false, keyword_url != NULL, &map); | 947 false, keyword_url != NULL, &map); |
| 948 } | 948 } |
| 949 if (!keyword_input_.text().empty()) { | 949 if (!keyword_input_.text().empty()) { |
| 950 // We only create the verbatim search query match for a keyword | 950 // We only create the verbatim search query match for a keyword |
| 951 // if it's not an extension keyword. Extension keywords are handled | 951 // if it's not an extension keyword. Extension keywords are handled |
| 952 // in KeywordProvider::Start(). (Extensions are complicated...) | 952 // in KeywordProvider::Start(). (Extensions are complicated...) |
| 953 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond | 953 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond |
| 954 // to the keyword verbatim search query. Do not create other matches | 954 // to the keyword verbatim search query. Do not create other matches |
| 955 // of type SEARCH_OTHER_ENGINE. | 955 // of type SEARCH_OTHER_ENGINE. |
| 956 if (keyword_url && | 956 if (keyword_url && |
| 957 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { | 957 (keyword_url->type() != TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 958 bool keyword_relevance_from_server; | 958 bool keyword_relevance_from_server; |
| 959 const int keyword_verbatim_relevance = | 959 const int keyword_verbatim_relevance = |
| 960 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); | 960 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); |
| 961 if (keyword_verbatim_relevance > 0) { | 961 if (keyword_verbatim_relevance > 0) { |
| 962 const base::string16& trimmed_verbatim = | 962 const base::string16& trimmed_verbatim = |
| 963 base::CollapseWhitespace(keyword_input_.text(), false); | 963 base::CollapseWhitespace(keyword_input_.text(), false); |
| 964 SearchSuggestionParser::SuggestResult verbatim( | 964 SearchSuggestionParser::SuggestResult verbatim( |
| 965 trimmed_verbatim, AutocompleteMatchType::SEARCH_OTHER_ENGINE, | 965 trimmed_verbatim, AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
| 966 trimmed_verbatim, base::string16(), base::string16(), | 966 trimmed_verbatim, base::string16(), base::string16(), |
| 967 base::string16(), base::string16(), nullptr, std::string(), | 967 base::string16(), base::string16(), nullptr, std::string(), |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1496 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 1497 matches.push_back(i->second); | 1497 matches.push_back(i->second); |
| 1498 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1498 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
| 1499 | 1499 |
| 1500 // If there is a top scoring entry, find the corresponding answer. | 1500 // If there is a top scoring entry, find the corresponding answer. |
| 1501 if (!matches.empty()) | 1501 if (!matches.empty()) |
| 1502 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1502 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
| 1503 | 1503 |
| 1504 return AnswersQueryData(); | 1504 return AnswersQueryData(); |
| 1505 } | 1505 } |
| OLD | NEW |