OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/history_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 // Loop over every result and add it to matches_. In the process, | 204 // Loop over every result and add it to matches_. In the process, |
205 // guarantee that scores are decreasing. |max_match_score| keeps | 205 // guarantee that scores are decreasing. |max_match_score| keeps |
206 // track of the highest score we can assign to any later results we | 206 // track of the highest score we can assign to any later results we |
207 // see. Also, if we're not allowing inline autocompletions in | 207 // see. Also, if we're not allowing inline autocompletions in |
208 // general or the current best suggestion isn't inlineable, | 208 // general or the current best suggestion isn't inlineable, |
209 // artificially reduce the starting |max_match_score| (which | 209 // artificially reduce the starting |max_match_score| (which |
210 // therefore applies to all results) to something low enough that | 210 // therefore applies to all results) to something low enough that |
211 // guarantees no result will be offered as an autocomplete | 211 // guarantees no result will be offered as an inline autocomplete |
212 // suggestion. Also do a similar reduction if we think there will be | 212 // suggestion. Also do a similar reduction if we think there will be |
213 // a URL-what-you-typed match. (We want URL-what-you-typed matches for | 213 // a URL-what-you-typed match. (We want URL-what-you-typed matches for |
214 // visited URLs to beat out any longer URLs, no matter how frequently | 214 // visited URLs to beat out any longer URLs, no matter how frequently |
215 // they're visited.) The strength of this last reduction depends on the | 215 // they're visited.) The strength of this last reduction depends on the |
216 // likely score for the URL-what-you-typed result. | 216 // likely score for the URL-what-you-typed result. |
217 | 217 |
218 // |template_url_service| or |template_url| can be NULL in unit tests. | 218 // |template_url_service| or |template_url| can be NULL in unit tests. |
219 TemplateURLService* template_url_service = | 219 TemplateURLService* template_url_service = |
220 TemplateURLServiceFactory::GetForProfile(profile_); | 220 TemplateURLServiceFactory::GetForProfile(profile_); |
221 TemplateURL* template_url = template_url_service ? | 221 TemplateURL* template_url = template_url_service ? |
222 template_url_service->GetDefaultSearchProvider() : NULL; | 222 template_url_service->GetDefaultSearchProvider() : NULL; |
223 int max_match_score = (PreventInlineAutocomplete(autocomplete_input_) || | 223 int max_match_score = |
224 !matches.begin()->can_inline) ? | 224 (OmniboxFieldTrial::ReorderForLegalDefaultMatch( |
225 (AutocompleteResult::kLowestDefaultScore - 1) : | 225 autocomplete_input_.current_page_classification()) || |
226 matches.begin()->raw_score; | 226 (!PreventInlineAutocomplete(autocomplete_input_) && |
| 227 matches.begin()->can_inline)) ? |
| 228 matches.begin()->raw_score : |
| 229 (AutocompleteResult::kLowestDefaultScore - 1); |
227 if (will_have_url_what_you_typed_match_first) { | 230 if (will_have_url_what_you_typed_match_first) { |
228 max_match_score = std::min(max_match_score, | 231 max_match_score = std::min(max_match_score, |
229 url_what_you_typed_match_score - 1); | 232 url_what_you_typed_match_score - 1); |
230 } | 233 } |
231 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); | 234 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); |
232 match_iter != matches.end(); ++match_iter) { | 235 match_iter != matches.end(); ++match_iter) { |
233 const ScoredHistoryMatch& history_match(*match_iter); | 236 const ScoredHistoryMatch& history_match(*match_iter); |
234 // Culls results corresponding to queries from the default search engine. | 237 // Culls results corresponding to queries from the default search engine. |
235 // These are low-quality, difficult-to-understand matches for users, and the | 238 // These are low-quality, difficult-to-understand matches for users, and the |
236 // SearchProvider should surface past queries in a better way anyway. | 239 // SearchProvider should surface past queries in a better way anyway. |
(...skipping 28 matching lines...) Expand all Loading... |
265 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), | 268 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), |
266 net::FormatUrlWithOffsets(info.url(), languages_, format_types, | 269 net::FormatUrlWithOffsets(info.url(), languages_, format_types, |
267 net::UnescapeRule::SPACES, NULL, NULL, &offsets)); | 270 net::UnescapeRule::SPACES, NULL, NULL, &offsets)); |
268 history::TermMatches new_matches = | 271 history::TermMatches new_matches = |
269 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); | 272 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); |
270 match.contents = net::FormatUrl(info.url(), languages_, format_types, | 273 match.contents = net::FormatUrl(info.url(), languages_, format_types, |
271 net::UnescapeRule::SPACES, NULL, NULL, NULL); | 274 net::UnescapeRule::SPACES, NULL, NULL, NULL); |
272 match.contents_class = | 275 match.contents_class = |
273 SpansFromTermMatch(new_matches, match.contents.length(), true); | 276 SpansFromTermMatch(new_matches, match.contents.length(), true); |
274 | 277 |
275 if (history_match.can_inline) { | 278 match.allowed_to_be_default_match = history_match.can_inline && |
| 279 !PreventInlineAutocomplete(autocomplete_input_); |
| 280 if (match.allowed_to_be_default_match) { |
276 DCHECK(!new_matches.empty()); | 281 DCHECK(!new_matches.empty()); |
277 size_t inline_autocomplete_offset = new_matches[0].offset + | 282 size_t inline_autocomplete_offset = new_matches[0].offset + |
278 new_matches[0].length; | 283 new_matches[0].length; |
279 // |inline_autocomplete_offset| may be beyond the end of the | 284 // |inline_autocomplete_offset| may be beyond the end of the |
280 // |fill_into_edit| if the user has typed an URL with a scheme and the | 285 // |fill_into_edit| if the user has typed an URL with a scheme and the |
281 // last character typed is a slash. That slash is removed by the | 286 // last character typed is a slash. That slash is removed by the |
282 // FormatURLWithOffsets call above. | 287 // FormatURLWithOffsets call above. |
283 if (inline_autocomplete_offset < match.fill_into_edit.length()) { | 288 if (inline_autocomplete_offset < match.fill_into_edit.length()) { |
284 match.inline_autocompletion = | 289 match.inline_autocompletion = |
285 match.fill_into_edit.substr(inline_autocomplete_offset); | 290 match.fill_into_edit.substr(inline_autocomplete_offset); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 do { | 339 do { |
335 offset += matches[i].length; | 340 offset += matches[i].length; |
336 ++i; | 341 ++i; |
337 } while ((i < match_count) && (offset == matches[i].offset)); | 342 } while ((i < match_count) && (offset == matches[i].offset)); |
338 if (offset < text_length) | 343 if (offset < text_length) |
339 spans.push_back(ACMatchClassification(offset, url_style)); | 344 spans.push_back(ACMatchClassification(offset, url_style)); |
340 } | 345 } |
341 | 346 |
342 return spans; | 347 return spans; |
343 } | 348 } |
OLD | NEW |