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

Side by Side Diff: components/omnibox/browser/search_provider.cc

Issue 2755503002: Add a new entry to omnibox_event.proto to log specific type of contextual suggestions (Closed)
Patch Set: Small fixes and sync. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 if (it->answer && 956 if (it->answer &&
957 base::i18n::ToLower(it->fill_into_edit) == trimmed_verbatim_lower) { 957 base::i18n::ToLower(it->fill_into_edit) == trimmed_verbatim_lower) {
958 answer_contents = it->answer_contents; 958 answer_contents = it->answer_contents;
959 answer_type = it->answer_type; 959 answer_type = it->answer_type;
960 answer = SuggestionAnswer::copy(it->answer.get()); 960 answer = SuggestionAnswer::copy(it->answer.get());
961 break; 961 break;
962 } 962 }
963 } 963 }
964 964
965 SearchSuggestionParser::SuggestResult verbatim( 965 SearchSuggestionParser::SuggestResult verbatim(
966 trimmed_verbatim, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 966 trimmed_verbatim, AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 0,
967 trimmed_verbatim, base::string16(), base::string16(), answer_contents, 967 trimmed_verbatim, base::string16(), base::string16(), answer_contents,
968 answer_type, std::move(answer), std::string(), std::string(), false, 968 answer_type, std::move(answer), std::string(), std::string(), false,
969 verbatim_relevance, relevance_from_server, false, trimmed_verbatim); 969 verbatim_relevance, relevance_from_server, false, trimmed_verbatim);
970 AddMatchToMap(verbatim, std::string(), did_not_accept_default_suggestion, 970 AddMatchToMap(verbatim, std::string(), did_not_accept_default_suggestion,
971 false, keyword_url != NULL, &map); 971 false, keyword_url != NULL, &map);
972 } 972 }
973 if (!keyword_input_.text().empty()) { 973 if (!keyword_input_.text().empty()) {
974 // We only create the verbatim search query match for a keyword 974 // We only create the verbatim search query match for a keyword
975 // if it's not an extension keyword. Extension keywords are handled 975 // if it's not an extension keyword. Extension keywords are handled
976 // in KeywordProvider::Start(). (Extensions are complicated...) 976 // in KeywordProvider::Start(). (Extensions are complicated...)
977 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond 977 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond
978 // to the keyword verbatim search query. Do not create other matches 978 // to the keyword verbatim search query. Do not create other matches
979 // of type SEARCH_OTHER_ENGINE. 979 // of type SEARCH_OTHER_ENGINE.
980 if (keyword_url && 980 if (keyword_url &&
981 (keyword_url->type() != TemplateURL::OMNIBOX_API_EXTENSION)) { 981 (keyword_url->type() != TemplateURL::OMNIBOX_API_EXTENSION)) {
982 bool keyword_relevance_from_server; 982 bool keyword_relevance_from_server;
983 const int keyword_verbatim_relevance = 983 const int keyword_verbatim_relevance =
984 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); 984 GetKeywordVerbatimRelevance(&keyword_relevance_from_server);
985 if (keyword_verbatim_relevance > 0) { 985 if (keyword_verbatim_relevance > 0) {
986 const base::string16& trimmed_verbatim = 986 const base::string16& trimmed_verbatim =
987 base::CollapseWhitespace(keyword_input_.text(), false); 987 base::CollapseWhitespace(keyword_input_.text(), false);
988 SearchSuggestionParser::SuggestResult verbatim( 988 SearchSuggestionParser::SuggestResult verbatim(
989 trimmed_verbatim, AutocompleteMatchType::SEARCH_OTHER_ENGINE, 989 trimmed_verbatim, AutocompleteMatchType::SEARCH_OTHER_ENGINE, 0,
990 trimmed_verbatim, base::string16(), base::string16(), 990 trimmed_verbatim, base::string16(), base::string16(),
991 base::string16(), base::string16(), nullptr, std::string(), 991 base::string16(), base::string16(), nullptr, std::string(),
992 std::string(), true, keyword_verbatim_relevance, 992 std::string(), true, keyword_verbatim_relevance,
993 keyword_relevance_from_server, false, trimmed_verbatim); 993 keyword_relevance_from_server, false, trimmed_verbatim);
994 AddMatchToMap(verbatim, std::string(), 994 AddMatchToMap(verbatim, std::string(),
995 did_not_accept_keyword_suggestion, false, true, &map); 995 did_not_accept_keyword_suggestion, false, true, &map);
996 } 996 }
997 } 997 }
998 } 998 }
999 AddRawHistoryResultsToMap(true, did_not_accept_keyword_suggestion, &map); 999 AddRawHistoryResultsToMap(true, did_not_accept_keyword_suggestion, &map);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 // Add the match to |scored_results| by putting the what-you-typed match 1165 // Add the match to |scored_results| by putting the what-you-typed match
1166 // on the front and appending all other matches. We want the what-you- 1166 // on the front and appending all other matches. We want the what-you-
1167 // typed match to always be first. 1167 // typed match to always be first.
1168 SearchSuggestionParser::SuggestResults::iterator insertion_position = 1168 SearchSuggestionParser::SuggestResults::iterator insertion_position =
1169 scored_results.end(); 1169 scored_results.end();
1170 if (trimmed_suggestion == trimmed_input) { 1170 if (trimmed_suggestion == trimmed_input) {
1171 found_what_you_typed_match = true; 1171 found_what_you_typed_match = true;
1172 insertion_position = scored_results.begin(); 1172 insertion_position = scored_results.begin();
1173 } 1173 }
1174 SearchSuggestionParser::SuggestResult history_suggestion( 1174 SearchSuggestionParser::SuggestResult history_suggestion(
1175 trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY, 1175 trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY, 0,
1176 trimmed_suggestion, base::string16(), base::string16(), 1176 trimmed_suggestion, base::string16(), base::string16(),
1177 base::string16(), base::string16(), nullptr, std::string(), 1177 base::string16(), base::string16(), nullptr, std::string(),
1178 std::string(), is_keyword, relevance, false, false, trimmed_input); 1178 std::string(), is_keyword, relevance, false, false, trimmed_input);
1179 // History results are synchronous; they are received on the last keystroke. 1179 // History results are synchronous; they are received on the last keystroke.
1180 history_suggestion.set_received_after_last_keystroke(false); 1180 history_suggestion.set_received_after_last_keystroke(false);
1181 scored_results.insert(insertion_position, history_suggestion); 1181 scored_results.insert(insertion_position, history_suggestion);
1182 } 1182 }
1183 1183
1184 // History returns results sorted for us. However, we may have docked some 1184 // History returns results sorted for us. However, we may have docked some
1185 // results' scores, so things are no longer in order. While keeping the 1185 // results' scores, so things are no longer in order. While keeping the
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 AutocompleteMatch SearchProvider::NavigationToMatch( 1407 AutocompleteMatch SearchProvider::NavigationToMatch(
1408 const SearchSuggestionParser::NavigationResult& navigation) { 1408 const SearchSuggestionParser::NavigationResult& navigation) {
1409 base::string16 input; 1409 base::string16 input;
1410 const bool trimmed_whitespace = base::TrimWhitespace( 1410 const bool trimmed_whitespace = base::TrimWhitespace(
1411 navigation.from_keyword_provider() ? 1411 navigation.from_keyword_provider() ?
1412 keyword_input_.text() : input_.text(), 1412 keyword_input_.text() : input_.text(),
1413 base::TRIM_TRAILING, &input) != base::TRIM_NONE; 1413 base::TRIM_TRAILING, &input) != base::TRIM_NONE;
1414 AutocompleteMatch match(this, navigation.relevance(), false, 1414 AutocompleteMatch match(this, navigation.relevance(), false,
1415 navigation.type()); 1415 navigation.type());
1416 match.destination_url = navigation.url(); 1416 match.destination_url = navigation.url();
1417 match.subtype_identifier = navigation.subtype_identifier();
1417 BaseSearchProvider::SetDeletionURL(navigation.deletion_url(), &match); 1418 BaseSearchProvider::SetDeletionURL(navigation.deletion_url(), &match);
1418 // First look for the user's input inside the formatted url as it would be 1419 // First look for the user's input inside the formatted url as it would be
1419 // without trimming the scheme, so we can find matches at the beginning of the 1420 // without trimming the scheme, so we can find matches at the beginning of the
1420 // scheme. 1421 // scheme.
1421 const URLPrefix* prefix = 1422 const URLPrefix* prefix =
1422 URLPrefix::BestURLPrefix(navigation.formatted_url(), input); 1423 URLPrefix::BestURLPrefix(navigation.formatted_url(), input);
1423 size_t match_start = (prefix == NULL) ? 1424 size_t match_start = (prefix == NULL) ?
1424 navigation.formatted_url().find(input) : prefix->prefix.length(); 1425 navigation.formatted_url().find(input) : prefix->prefix.length();
1425 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) && 1426 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) &&
1426 (!prefix || (match_start != 0)); 1427 (!prefix || (match_start != 0));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) 1516 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i)
1516 matches.push_back(i->second); 1517 matches.push_back(i->second);
1517 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); 1518 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant);
1518 1519
1519 // If there is a top scoring entry, find the corresponding answer. 1520 // If there is a top scoring entry, find the corresponding answer.
1520 if (!matches.empty()) 1521 if (!matches.empty())
1521 return answers_cache_.GetTopAnswerEntry(matches[0].contents); 1522 return answers_cache_.GetTopAnswerEntry(matches[0].contents);
1522 1523
1523 return AnswersQueryData(); 1524 return AnswersQueryData();
1524 } 1525 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/omnibox_metrics_provider.cc ('k') | components/omnibox/browser/search_suggestion_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698