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 autocomplete_input_.current_page_classification()) && | |
Peter Kasting
2013/08/06 22:56:16
Nit: No parens around unary operator application
Mark P
2013/08/07 00:44:31
It's not around the unary operator; its around the
| |
226 (PreventInlineAutocomplete(autocomplete_input_) || | |
227 !matches.begin()->can_inline)) ? | |
225 (AutocompleteResult::kLowestDefaultScore - 1) : | 228 (AutocompleteResult::kLowestDefaultScore - 1) : |
226 matches.begin()->raw_score; | 229 matches.begin()->raw_score; |
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. |
(...skipping 30 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 if (!history_match.can_inline || |
Peter Kasting
2013/08/06 22:56:16
Nit: Shorter:
match.allowed_to_be_default_match
Mark P
2013/08/07 00:44:31
Yup, that's shorter and no less clear.
| |
279 PreventInlineAutocomplete(autocomplete_input_)) { | |
280 match.allowed_to_be_default_match = false; | |
281 } else { | |
276 DCHECK(!new_matches.empty()); | 282 DCHECK(!new_matches.empty()); |
277 size_t inline_autocomplete_offset = new_matches[0].offset + | 283 size_t inline_autocomplete_offset = new_matches[0].offset + |
278 new_matches[0].length; | 284 new_matches[0].length; |
285 match.allowed_to_be_default_match = true; | |
279 // |inline_autocomplete_offset| may be beyond the end of the | 286 // |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 | 287 // |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 | 288 // last character typed is a slash. That slash is removed by the |
282 // FormatURLWithOffsets call above. | 289 // FormatURLWithOffsets call above. |
283 if (inline_autocomplete_offset < match.fill_into_edit.length()) { | 290 if (inline_autocomplete_offset < match.fill_into_edit.length()) { |
284 match.inline_autocompletion = | 291 match.inline_autocompletion = |
285 match.fill_into_edit.substr(inline_autocomplete_offset); | 292 match.fill_into_edit.substr(inline_autocomplete_offset); |
286 } | 293 } |
287 } | 294 } |
288 | 295 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 do { | 341 do { |
335 offset += matches[i].length; | 342 offset += matches[i].length; |
336 ++i; | 343 ++i; |
337 } while ((i < match_count) && (offset == matches[i].offset)); | 344 } while ((i < match_count) && (offset == matches[i].offset)); |
338 if (offset < text_length) | 345 if (offset < text_length) |
339 spans.push_back(ACMatchClassification(offset, url_style)); | 346 spans.push_back(ACMatchClassification(offset, url_style)); |
340 } | 347 } |
341 | 348 |
342 return spans; | 349 return spans; |
343 } | 350 } |
OLD | NEW |