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 "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 } | 101 } |
102 return false; | 102 return false; |
103 } | 103 } |
104 | 104 |
105 // Builds the match contents and classification for the contents, and updates | 105 // Builds the match contents and classification for the contents, and updates |
106 // the given |AutocompleteMatch|. | 106 // the given |AutocompleteMatch|. |
107 void SetAndClassifyMatchContents(const base::string16& query_string, | 107 void SetAndClassifyMatchContents(const base::string16& query_string, |
108 const base::string16& input_text, | 108 const base::string16& input_text, |
109 const base::string16& match_contents, | 109 const base::string16& match_contents, |
110 const base::string16& annotation, | |
111 AutocompleteMatch* match) { | 110 AutocompleteMatch* match) { |
112 size_t match_contents_start = 0; | 111 match->contents = match_contents.empty() ? query_string : match_contents; |
113 size_t annotation_start = match_contents.size(); | |
114 // Append annotation if present. | |
115 if (annotation.empty()) { | |
116 match->contents = match_contents; | |
117 } else { | |
118 std::vector<size_t> positions; | |
119 match->contents = l10n_util::GetStringFUTF16( | |
120 IDS_ANNOTATED_SUGGESTION, match_contents, annotation, &positions); | |
121 match_contents_start = positions[0]; | |
122 annotation_start = positions[1]; | |
123 } | |
124 size_t match_contents_end = match_contents_start + match_contents.size(); | |
125 | |
126 if (!annotation.empty() && (annotation_start < match_contents_start)) | |
127 match->contents_class.push_back(ACMatchClassification( | |
128 annotation_start, ACMatchClassification::DIM)); | |
129 | 112 |
130 // We do intra-string highlighting for suggestions - the suggested segment | 113 // We do intra-string highlighting for suggestions - the suggested segment |
131 // will be highlighted, e.g. for input_text = "you" the suggestion may be | 114 // will be highlighted, e.g. for input_text = "you" the suggestion may be |
132 // "youtube", so we'll bold the "tube" section: you*tube*. | 115 // "youtube", so we'll bold the "tube" section: you*tube*. |
133 if (input_text != match_contents) { | 116 if (input_text != match_contents) { |
134 size_t input_position = match->contents.substr( | 117 size_t input_position = match->contents.find(input_text); |
135 match_contents_start, match_contents.length()).find(input_text); | |
136 if (input_position == base::string16::npos) { | 118 if (input_position == base::string16::npos) { |
137 // The input text is not a substring of the query string, e.g. input | 119 // The input text is not a substring of the query string, e.g. input |
138 // text is "slasdot" and the query string is "slashdot", so we bold the | 120 // text is "slasdot" and the query string is "slashdot", so we bold the |
139 // whole thing. | 121 // whole thing. |
140 match->contents_class.push_back(ACMatchClassification( | 122 match->contents_class.push_back(ACMatchClassification( |
141 match_contents_start, ACMatchClassification::MATCH)); | 123 0, ACMatchClassification::MATCH)); |
142 } else { | 124 } else { |
143 input_position += match_contents_start; | |
144 | |
145 // TODO(beng): ACMatchClassification::MATCH now seems to just mean | 125 // TODO(beng): ACMatchClassification::MATCH now seems to just mean |
146 // "bold" this. Consider modifying the terminology. | 126 // "bold" this. Consider modifying the terminology. |
147 // We don't iterate over the string here annotating all matches because | 127 // We don't iterate over the string here annotating all matches because |
148 // it looks odd to have every occurrence of a substring that may be as | 128 // it looks odd to have every occurrence of a substring that may be as |
149 // short as a single character highlighted in a query suggestion result, | 129 // short as a single character highlighted in a query suggestion result, |
150 // e.g. for input text "s" and query string "southwest airlines", it | 130 // e.g. for input text "s" and query string "southwest airlines", it |
151 // looks odd if both the first and last s are highlighted. | 131 // looks odd if both the first and last s are highlighted. |
152 if (input_position != match_contents_start) { | 132 if (input_position != 0) { |
153 match->contents_class.push_back(ACMatchClassification( | 133 match->contents_class.push_back(ACMatchClassification( |
154 match_contents_start, ACMatchClassification::MATCH)); | 134 0, ACMatchClassification::MATCH)); |
155 } | 135 } |
156 match->contents_class.push_back( | 136 match->contents_class.push_back( |
157 ACMatchClassification(input_position, ACMatchClassification::NONE)); | 137 ACMatchClassification(input_position, ACMatchClassification::NONE)); |
158 size_t next_fragment_position = input_position + input_text.length(); | 138 size_t next_fragment_position = input_position + input_text.length(); |
159 if (next_fragment_position < query_string.length()) { | 139 if (next_fragment_position < query_string.length()) { |
160 match->contents_class.push_back(ACMatchClassification( | 140 match->contents_class.push_back(ACMatchClassification( |
161 next_fragment_position, ACMatchClassification::MATCH)); | 141 next_fragment_position, ACMatchClassification::MATCH)); |
162 } | 142 } |
163 } | 143 } |
164 } else { | 144 } else { |
165 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the | 145 // Otherwise, |match| is a verbatim (what-you-typed) match, either for the |
166 // default provider or a keyword search provider. | 146 // default provider or a keyword search provider. |
167 match->contents_class.push_back(ACMatchClassification( | 147 match->contents_class.push_back(ACMatchClassification( |
168 match_contents_start, ACMatchClassification::NONE)); | 148 0, ACMatchClassification::NONE)); |
169 } | 149 } |
| 150 } |
170 | 151 |
171 if (!annotation.empty() && (annotation_start >= match_contents_start)) | 152 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
172 match->contents_class.push_back(ACMatchClassification( | 153 if (type == "ENTITY") |
173 match_contents_end, ACMatchClassification::DIM)); | 154 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
| 155 if (type == "INFINITE") |
| 156 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
| 157 if (type == "PERSONALIZED") |
| 158 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; |
| 159 if (type == "PROFILE") |
| 160 return AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; |
| 161 return AutocompleteMatchType::SEARCH_SUGGEST; |
174 } | 162 } |
175 | 163 |
176 } // namespace | 164 } // namespace |
177 | 165 |
178 | 166 |
179 // SuggestionDeletionHandler ------------------------------------------------- | 167 // SuggestionDeletionHandler ------------------------------------------------- |
180 | 168 |
181 // This class handles making requests to the server in order to delete | 169 // This class handles making requests to the server in order to delete |
182 // personalized suggestions. | 170 // personalized suggestions. |
183 class SuggestionDeletionHandler : public net::URLFetcherDelegate { | 171 class SuggestionDeletionHandler : public net::URLFetcherDelegate { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 247 } |
260 | 248 |
261 SearchProvider::Result::~Result() { | 249 SearchProvider::Result::~Result() { |
262 } | 250 } |
263 | 251 |
264 | 252 |
265 // SearchProvider::SuggestResult ---------------------------------------------- | 253 // SearchProvider::SuggestResult ---------------------------------------------- |
266 | 254 |
267 SearchProvider::SuggestResult::SuggestResult( | 255 SearchProvider::SuggestResult::SuggestResult( |
268 const base::string16& suggestion, | 256 const base::string16& suggestion, |
| 257 AutocompleteMatchType::Type type, |
269 const base::string16& match_contents, | 258 const base::string16& match_contents, |
270 const base::string16& annotation, | 259 const base::string16& annotation, |
271 const std::string& suggest_query_params, | 260 const std::string& suggest_query_params, |
272 const std::string& deletion_url, | 261 const std::string& deletion_url, |
273 bool from_keyword_provider, | 262 bool from_keyword_provider, |
274 int relevance, | 263 int relevance, |
275 bool relevance_from_server, | 264 bool relevance_from_server, |
276 bool should_prefetch) | 265 bool should_prefetch) |
277 : Result(from_keyword_provider, relevance, relevance_from_server), | 266 : Result(from_keyword_provider, relevance, relevance_from_server), |
278 suggestion_(suggestion), | 267 suggestion_(suggestion), |
| 268 type_(type), |
279 match_contents_(match_contents), | 269 match_contents_(match_contents), |
280 annotation_(annotation), | 270 annotation_(annotation), |
281 suggest_query_params_(suggest_query_params), | 271 suggest_query_params_(suggest_query_params), |
282 deletion_url_(deletion_url), | 272 deletion_url_(deletion_url), |
283 should_prefetch_(should_prefetch) { | 273 should_prefetch_(should_prefetch) { |
284 } | 274 } |
285 | 275 |
286 SearchProvider::SuggestResult::~SuggestResult() { | 276 SearchProvider::SuggestResult::~SuggestResult() { |
287 } | 277 } |
288 | 278 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 const std::string& suggest_query_params, | 409 const std::string& suggest_query_params, |
420 int accepted_suggestion, | 410 int accepted_suggestion, |
421 int omnibox_start_margin, | 411 int omnibox_start_margin, |
422 bool append_extra_query_params) { | 412 bool append_extra_query_params) { |
423 AutocompleteMatch match(autocomplete_provider, relevance, false, type); | 413 AutocompleteMatch match(autocomplete_provider, relevance, false, type); |
424 | 414 |
425 if (!template_url) | 415 if (!template_url) |
426 return match; | 416 return match; |
427 match.keyword = template_url->keyword(); | 417 match.keyword = template_url->keyword(); |
428 | 418 |
429 SetAndClassifyMatchContents( | 419 SetAndClassifyMatchContents(query_string, input_text, match_contents, &match); |
430 query_string, input_text, match_contents, annotation, &match); | 420 |
| 421 if (!annotation.empty()) |
| 422 match.description = annotation; |
431 | 423 |
432 match.allowed_to_be_default_match = (input_text == match_contents); | 424 match.allowed_to_be_default_match = (input_text == match_contents); |
433 | 425 |
434 // When the user forced a query, we need to make sure all the fill_into_edit | 426 // When the user forced a query, we need to make sure all the fill_into_edit |
435 // values preserve that property. Otherwise, if the user starts editing a | 427 // values preserve that property. Otherwise, if the user starts editing a |
436 // suggestion, non-Search results will suddenly appear. | 428 // suggestion, non-Search results will suddenly appear. |
437 if (input.type() == AutocompleteInput::FORCED_QUERY) | 429 if (input.type() == AutocompleteInput::FORCED_QUERY) |
438 match.fill_into_edit.assign(ASCIIToUTF16("?")); | 430 match.fill_into_edit.assign(ASCIIToUTF16("?")); |
439 if (is_keyword) | 431 if (is_keyword) |
440 match.fill_into_edit.append(match.keyword + char16(' ')); | 432 match.fill_into_edit.append(match.keyword + char16(' ')); |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 // Do not blindly trust the URL coming from the server to be valid. | 1164 // Do not blindly trust the URL coming from the server to be valid. |
1173 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion), std::string())); | 1165 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion), std::string())); |
1174 if (url.is_valid() && allow_navsuggest) { | 1166 if (url.is_valid() && allow_navsuggest) { |
1175 base::string16 title; | 1167 base::string16 title; |
1176 if (descriptions != NULL) | 1168 if (descriptions != NULL) |
1177 descriptions->GetString(index, &title); | 1169 descriptions->GetString(index, &title); |
1178 results->navigation_results.push_back(NavigationResult( | 1170 results->navigation_results.push_back(NavigationResult( |
1179 *this, url, title, is_keyword, relevance, true)); | 1171 *this, url, title, is_keyword, relevance, true)); |
1180 } | 1172 } |
1181 } else { | 1173 } else { |
| 1174 AutocompleteMatchType::Type match_type = GetAutocompleteMatchType(type); |
1182 bool should_prefetch = static_cast<int>(index) == prefetch_index; | 1175 bool should_prefetch = static_cast<int>(index) == prefetch_index; |
1183 DictionaryValue* suggestion_detail = NULL; | 1176 DictionaryValue* suggestion_detail = NULL; |
1184 base::string16 match_contents = suggestion; | 1177 base::string16 match_contents = suggestion; |
1185 base::string16 annotation; | 1178 base::string16 annotation; |
1186 std::string suggest_query_params; | 1179 std::string suggest_query_params; |
1187 std::string deletion_url; | 1180 std::string deletion_url; |
1188 | 1181 |
1189 if (suggestion_details) { | 1182 if (suggestion_details) { |
1190 suggestion_details->GetDictionary(index, &suggestion_detail); | 1183 suggestion_details->GetDictionary(index, &suggestion_detail); |
1191 if (suggestion_detail) { | 1184 if (suggestion_detail) { |
1192 suggestion_detail->GetString("du", &deletion_url); | 1185 suggestion_detail->GetString("du", &deletion_url); |
1193 | 1186 suggestion_detail->GetString("title", &match_contents) || |
1194 if (type == "ENTITY") { | 1187 suggestion_detail->GetString("t", &match_contents); |
1195 suggestion_detail->GetString("a", &annotation); | 1188 suggestion_detail->GetString("annotation", &annotation) || |
1196 | 1189 suggestion_detail->GetString("a", &annotation); |
1197 base::string16 disambiguating_query; | 1190 suggestion_detail->GetString("query_params", &suggest_query_params) || |
1198 if (suggestion_detail->GetString("dq", &disambiguating_query) && | 1191 suggestion_detail->GetString("q", &suggest_query_params); |
1199 !disambiguating_query.empty()) | |
1200 suggestion = disambiguating_query; | |
1201 | |
1202 suggestion_detail->GetString("q", &suggest_query_params); | |
1203 } | |
1204 } | 1192 } |
1205 } | 1193 } |
1206 | 1194 |
1207 // TODO(kochi): Improve calculator suggestion presentation. | 1195 // TODO(kochi): Improve calculator suggestion presentation. |
1208 results->suggest_results.push_back(SuggestResult( | 1196 results->suggest_results.push_back(SuggestResult( |
1209 suggestion, match_contents, annotation, suggest_query_params, | 1197 suggestion, match_type, match_contents, annotation, |
1210 deletion_url, is_keyword, relevance, true, should_prefetch)); | 1198 suggest_query_params, deletion_url, is_keyword, relevance, true, |
| 1199 should_prefetch)); |
1211 } | 1200 } |
1212 } | 1201 } |
1213 | 1202 |
1214 // Ignore suggested scores for non-keyword matches in keyword mode; if the | 1203 // Ignore suggested scores for non-keyword matches in keyword mode; if the |
1215 // server is allowed to score these, it could interfere with the user's | 1204 // server is allowed to score these, it could interfere with the user's |
1216 // ability to get good keyword results. | 1205 // ability to get good keyword results. |
1217 const bool abandon_suggested_scores = | 1206 const bool abandon_suggested_scores = |
1218 !is_keyword && !providers_.keyword_provider().empty(); | 1207 !is_keyword && !providers_.keyword_provider().empty(); |
1219 // Apply calculated relevance scores to suggestions if a valid list was | 1208 // Apply calculated relevance scores to suggestions if a valid list was |
1220 // not provided or we're abandoning suggested scores entirely. | 1209 // not provided or we're abandoning suggested scores entirely. |
(...skipping 27 matching lines...) Expand all Loading... |
1248 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 1237 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
1249 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 1238 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
1250 | 1239 |
1251 bool relevance_from_server; | 1240 bool relevance_from_server; |
1252 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); | 1241 int verbatim_relevance = GetVerbatimRelevance(&relevance_from_server); |
1253 int did_not_accept_default_suggestion = | 1242 int did_not_accept_default_suggestion = |
1254 default_results_.suggest_results.empty() ? | 1243 default_results_.suggest_results.empty() ? |
1255 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : | 1244 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : |
1256 TemplateURLRef::NO_SUGGESTION_CHOSEN; | 1245 TemplateURLRef::NO_SUGGESTION_CHOSEN; |
1257 if (verbatim_relevance > 0) { | 1246 if (verbatim_relevance > 0) { |
1258 SuggestResult verbatim(input_.text(), input_.text(), base::string16(), | 1247 SuggestResult verbatim( |
1259 std::string(), std::string(), false, | 1248 input_.text(), AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
1260 verbatim_relevance, relevance_from_server, false); | 1249 input_.text(), base::string16(), std::string(), std::string(), |
| 1250 false, verbatim_relevance, relevance_from_server, false); |
1261 AddMatchToMap(verbatim, input_.text(), std::string(), | 1251 AddMatchToMap(verbatim, input_.text(), std::string(), |
1262 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | |
1263 did_not_accept_default_suggestion, &map); | 1252 did_not_accept_default_suggestion, &map); |
1264 } | 1253 } |
1265 if (!keyword_input_.text().empty()) { | 1254 if (!keyword_input_.text().empty()) { |
1266 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); | 1255 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); |
1267 // We only create the verbatim search query match for a keyword | 1256 // We only create the verbatim search query match for a keyword |
1268 // if it's not an extension keyword. Extension keywords are handled | 1257 // if it's not an extension keyword. Extension keywords are handled |
1269 // in KeywordProvider::Start(). (Extensions are complicated...) | 1258 // in KeywordProvider::Start(). (Extensions are complicated...) |
1270 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond | 1259 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond |
1271 // to the keyword verbatim search query. Do not create other matches | 1260 // to the keyword verbatim search query. Do not create other matches |
1272 // of type SEARCH_OTHER_ENGINE. | 1261 // of type SEARCH_OTHER_ENGINE. |
1273 if (keyword_url && | 1262 if (keyword_url && |
1274 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { | 1263 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { |
1275 bool keyword_relevance_from_server; | 1264 bool keyword_relevance_from_server; |
1276 const int keyword_verbatim_relevance = | 1265 const int keyword_verbatim_relevance = |
1277 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); | 1266 GetKeywordVerbatimRelevance(&keyword_relevance_from_server); |
1278 if (keyword_verbatim_relevance > 0) { | 1267 if (keyword_verbatim_relevance > 0) { |
1279 SuggestResult verbatim(keyword_input_.text(), keyword_input_.text(), | 1268 SuggestResult verbatim( |
1280 base::string16(), std::string(), std::string(), | 1269 keyword_input_.text(), AutocompleteMatchType::SEARCH_OTHER_ENGINE, |
1281 true, keyword_verbatim_relevance, | 1270 keyword_input_.text(), base::string16(), std::string(), |
1282 keyword_relevance_from_server, false); | 1271 std::string(), true, keyword_verbatim_relevance, |
| 1272 keyword_relevance_from_server, false); |
1283 AddMatchToMap(verbatim, keyword_input_.text(), std::string(), | 1273 AddMatchToMap(verbatim, keyword_input_.text(), std::string(), |
1284 AutocompleteMatchType::SEARCH_OTHER_ENGINE, | |
1285 did_not_accept_keyword_suggestion, &map); | 1274 did_not_accept_keyword_suggestion, &map); |
1286 } | 1275 } |
1287 } | 1276 } |
1288 } | 1277 } |
1289 AddHistoryResultsToMap(keyword_history_results_, true, | 1278 AddHistoryResultsToMap(keyword_history_results_, true, |
1290 did_not_accept_keyword_suggestion, &map); | 1279 did_not_accept_keyword_suggestion, &map); |
1291 AddHistoryResultsToMap(default_history_results_, false, | 1280 AddHistoryResultsToMap(default_history_results_, false, |
1292 did_not_accept_default_suggestion, &map); | 1281 did_not_accept_default_suggestion, &map); |
1293 | 1282 |
1294 AddSuggestResultsToMap(keyword_results_.suggest_results, | 1283 AddSuggestResultsToMap(keyword_results_.suggest_results, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 !HasMultipleWords(scored_results.front().suggestion())) | 1561 !HasMultipleWords(scored_results.front().suggestion())) |
1573 scored_results.clear(); // Didn't detect the case above, score normally. | 1562 scored_results.clear(); // Didn't detect the case above, score normally. |
1574 } | 1563 } |
1575 if (scored_results.empty()) | 1564 if (scored_results.empty()) |
1576 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, | 1565 scored_results = ScoreHistoryResults(results, prevent_inline_autocomplete, |
1577 input_multiple_words, input_text, | 1566 input_multiple_words, input_text, |
1578 is_keyword); | 1567 is_keyword); |
1579 for (SuggestResults::const_iterator i(scored_results.begin()); | 1568 for (SuggestResults::const_iterator i(scored_results.begin()); |
1580 i != scored_results.end(); ++i) { | 1569 i != scored_results.end(); ++i) { |
1581 AddMatchToMap(*i, input_text, std::string(), | 1570 AddMatchToMap(*i, input_text, std::string(), |
1582 AutocompleteMatchType::SEARCH_HISTORY, | |
1583 did_not_accept_suggestion, map); | 1571 did_not_accept_suggestion, map); |
1584 } | 1572 } |
1585 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", | 1573 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.AddHistoryResultsTime", |
1586 base::TimeTicks::Now() - start_time); | 1574 base::TimeTicks::Now() - start_time); |
1587 } | 1575 } |
1588 | 1576 |
1589 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( | 1577 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( |
1590 const HistoryResults& results, | 1578 const HistoryResults& results, |
1591 bool base_prevent_inline_autocomplete, | 1579 bool base_prevent_inline_autocomplete, |
1592 bool input_multiple_words, | 1580 bool input_multiple_words, |
(...skipping 28 matching lines...) Expand all Loading... |
1621 if (!prevent_inline_autocomplete && classifier && (i->term != input_text)) { | 1609 if (!prevent_inline_autocomplete && classifier && (i->term != input_text)) { |
1622 AutocompleteMatch match; | 1610 AutocompleteMatch match; |
1623 classifier->Classify(i->term, false, false, &match, NULL); | 1611 classifier->Classify(i->term, false, false, &match, NULL); |
1624 prevent_inline_autocomplete = | 1612 prevent_inline_autocomplete = |
1625 !AutocompleteMatch::IsSearchType(match.type); | 1613 !AutocompleteMatch::IsSearchType(match.type); |
1626 } | 1614 } |
1627 | 1615 |
1628 int relevance = CalculateRelevanceForHistory( | 1616 int relevance = CalculateRelevanceForHistory( |
1629 i->time, is_keyword, !prevent_inline_autocomplete, | 1617 i->time, is_keyword, !prevent_inline_autocomplete, |
1630 prevent_search_history_inlining); | 1618 prevent_search_history_inlining); |
1631 scored_results.push_back( | 1619 scored_results.push_back(SuggestResult( |
1632 SuggestResult(i->term, i->term, base::string16(), std::string(), | 1620 i->term, AutocompleteMatchType::SEARCH_HISTORY, i->term, |
1633 std::string(), is_keyword, relevance, false, false)); | 1621 base::string16(), std::string(), std::string(), is_keyword, relevance, |
| 1622 false, false)); |
1634 } | 1623 } |
1635 | 1624 |
1636 // History returns results sorted for us. However, we may have docked some | 1625 // History returns results sorted for us. However, we may have docked some |
1637 // results' scores, so things are no longer in order. Do a stable sort to get | 1626 // results' scores, so things are no longer in order. Do a stable sort to get |
1638 // things back in order without otherwise disturbing results with equal | 1627 // things back in order without otherwise disturbing results with equal |
1639 // scores, then force the scores to be unique, so that the order in which | 1628 // scores, then force the scores to be unique, so that the order in which |
1640 // they're shown is deterministic. | 1629 // they're shown is deterministic. |
1641 std::stable_sort(scored_results.begin(), scored_results.end(), | 1630 std::stable_sort(scored_results.begin(), scored_results.end(), |
1642 CompareScoredResults()); | 1631 CompareScoredResults()); |
1643 int last_relevance = 0; | 1632 int last_relevance = 0; |
1644 for (SuggestResults::iterator i(scored_results.begin()); | 1633 for (SuggestResults::iterator i(scored_results.begin()); |
1645 i != scored_results.end(); ++i) { | 1634 i != scored_results.end(); ++i) { |
1646 if ((i != scored_results.begin()) && (i->relevance() >= last_relevance)) | 1635 if ((i != scored_results.begin()) && (i->relevance() >= last_relevance)) |
1647 i->set_relevance(last_relevance - 1); | 1636 i->set_relevance(last_relevance - 1); |
1648 last_relevance = i->relevance(); | 1637 last_relevance = i->relevance(); |
1649 } | 1638 } |
1650 | 1639 |
1651 return scored_results; | 1640 return scored_results; |
1652 } | 1641 } |
1653 | 1642 |
1654 void SearchProvider::AddSuggestResultsToMap(const SuggestResults& results, | 1643 void SearchProvider::AddSuggestResultsToMap(const SuggestResults& results, |
1655 const std::string& metadata, | 1644 const std::string& metadata, |
1656 MatchMap* map) { | 1645 MatchMap* map) { |
1657 for (size_t i = 0; i < results.size(); ++i) { | 1646 for (size_t i = 0; i < results.size(); ++i) { |
1658 const bool is_keyword = results[i].from_keyword_provider(); | 1647 const bool is_keyword = results[i].from_keyword_provider(); |
1659 const base::string16& input = is_keyword ? keyword_input_.text() | 1648 const base::string16& input = is_keyword ? keyword_input_.text() |
1660 : input_.text(); | 1649 : input_.text(); |
1661 AddMatchToMap(results[i], input, metadata, | 1650 AddMatchToMap(results[i], input, metadata, i, map); |
1662 AutocompleteMatchType::SEARCH_SUGGEST, i, map); | |
1663 } | 1651 } |
1664 } | 1652 } |
1665 | 1653 |
1666 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const { | 1654 int SearchProvider::GetVerbatimRelevance(bool* relevance_from_server) const { |
1667 // Use the suggested verbatim relevance score if it is non-negative (valid), | 1655 // Use the suggested verbatim relevance score if it is non-negative (valid), |
1668 // if inline autocomplete isn't prevented (always show verbatim on backspace), | 1656 // if inline autocomplete isn't prevented (always show verbatim on backspace), |
1669 // and if it won't suppress verbatim, leaving no default provider matches. | 1657 // and if it won't suppress verbatim, leaving no default provider matches. |
1670 // Otherwise, if the default provider returned no matches and was still able | 1658 // Otherwise, if the default provider returned no matches and was still able |
1671 // to suppress verbatim, the user would have no search/nav matches and may be | 1659 // to suppress verbatim, the user would have no search/nav matches and may be |
1672 // left unable to search using their default provider from the omnibox. | 1660 // left unable to search using their default provider from the omnibox. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1767 if (is_primary_provider) | 1755 if (is_primary_provider) |
1768 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; | 1756 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; |
1769 else | 1757 else |
1770 base_score = 200; | 1758 base_score = 200; |
1771 return std::max(0, base_score - score_discount); | 1759 return std::max(0, base_score - score_discount); |
1772 } | 1760 } |
1773 | 1761 |
1774 void SearchProvider::AddMatchToMap(const SuggestResult& result, | 1762 void SearchProvider::AddMatchToMap(const SuggestResult& result, |
1775 const base::string16& input_text, | 1763 const base::string16& input_text, |
1776 const std::string& metadata, | 1764 const std::string& metadata, |
1777 AutocompleteMatch::Type type, | |
1778 int accepted_suggestion, | 1765 int accepted_suggestion, |
1779 MatchMap* map) { | 1766 MatchMap* map) { |
1780 // On non-mobile, ask the instant controller for the appropriate start margin. | 1767 // On non-mobile, ask the instant controller for the appropriate start margin. |
1781 // On mobile the start margin is unused, so leave the value as default there. | 1768 // On mobile the start margin is unused, so leave the value as default there. |
1782 int omnibox_start_margin = chrome::kDisableStartMargin; | 1769 int omnibox_start_margin = chrome::kDisableStartMargin; |
1783 #if !defined(OS_ANDROID) && !defined(IOS) | 1770 #if !defined(OS_ANDROID) && !defined(IOS) |
1784 if (chrome::IsInstantExtendedAPIEnabled()) { | 1771 if (chrome::IsInstantExtendedAPIEnabled()) { |
1785 Browser* browser = | 1772 Browser* browser = |
1786 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); | 1773 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); |
1787 if (browser && browser->instant_controller() && | 1774 if (browser && browser->instant_controller() && |
1788 browser->instant_controller()->instant()) { | 1775 browser->instant_controller()->instant()) { |
1789 omnibox_start_margin = | 1776 omnibox_start_margin = |
1790 browser->instant_controller()->instant()->omnibox_bounds().x(); | 1777 browser->instant_controller()->instant()->omnibox_bounds().x(); |
1791 } | 1778 } |
1792 } | 1779 } |
1793 #endif // !defined(OS_ANDROID) && !defined(IOS) | 1780 #endif // !defined(OS_ANDROID) && !defined(IOS) |
1794 | 1781 |
1795 const TemplateURL* template_url = result.from_keyword_provider() ? | 1782 const TemplateURL* template_url = result.from_keyword_provider() ? |
1796 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); | 1783 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); |
1797 AutocompleteMatch match = CreateSearchSuggestion( | 1784 AutocompleteMatch match = CreateSearchSuggestion( |
1798 this, input_, input_text, result.relevance(), type, | 1785 this, input_, input_text, result.relevance(), result.type(), |
1799 result.from_keyword_provider(), result.match_contents(), | 1786 result.from_keyword_provider(), result.match_contents(), |
1800 result.annotation(), template_url, result.suggestion(), | 1787 result.annotation(), template_url, result.suggestion(), |
1801 result.suggest_query_params(), accepted_suggestion, omnibox_start_margin, | 1788 result.suggest_query_params(), accepted_suggestion, omnibox_start_margin, |
1802 !result.from_keyword_provider() || providers_.default_provider().empty()); | 1789 !result.from_keyword_provider() || providers_.default_provider().empty()); |
1803 if (!match.destination_url.is_valid()) | 1790 if (!match.destination_url.is_valid()) |
1804 return; | 1791 return; |
1805 match.search_terms_args->bookmark_bar_pinned = | 1792 match.search_terms_args->bookmark_bar_pinned = |
1806 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 1793 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
1807 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 1794 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
1808 result.relevance_from_server() ? kTrue : kFalse); | 1795 result.relevance_from_server() ? kTrue : kFalse); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || | 2026 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || |
2040 service == NULL || | 2027 service == NULL || |
2041 !service->IsSyncEnabledAndLoggedIn() || | 2028 !service->IsSyncEnabledAndLoggedIn() || |
2042 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( | 2029 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( |
2043 syncer::PROXY_TABS) || | 2030 syncer::PROXY_TABS) || |
2044 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) | 2031 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) |
2045 return false; | 2032 return false; |
2046 | 2033 |
2047 return true; | 2034 return true; |
2048 } | 2035 } |
OLD | NEW |