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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 using history::ScoredHistoryMatch; | 49 using history::ScoredHistoryMatch; |
50 using history::ScoredHistoryMatches; | 50 using history::ScoredHistoryMatches; |
51 | 51 |
52 bool HistoryQuickProvider::disabled_ = false; | 52 bool HistoryQuickProvider::disabled_ = false; |
53 | 53 |
54 HistoryQuickProvider::HistoryQuickProvider( | 54 HistoryQuickProvider::HistoryQuickProvider( |
55 AutocompleteProviderListener* listener, | 55 AutocompleteProviderListener* listener, |
56 Profile* profile) | 56 Profile* profile) |
57 : HistoryProvider(listener, profile, | 57 : HistoryProvider(listener, profile, |
58 AutocompleteProvider::TYPE_HISTORY_QUICK), | 58 AutocompleteProvider::TYPE_HISTORY_QUICK), |
59 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)) { | 59 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), |
| 60 omnibox_will_reorder_for_legal_default_match_( |
| 61 OmniboxFieldTrial::InReorderForLegalDefaultMatchGroup()) { |
60 } | 62 } |
61 | 63 |
62 void HistoryQuickProvider::Start(const AutocompleteInput& input, | 64 void HistoryQuickProvider::Start(const AutocompleteInput& input, |
63 bool minimal_changes) { | 65 bool minimal_changes) { |
64 matches_.clear(); | 66 matches_.clear(); |
65 if (disabled_) | 67 if (disabled_) |
66 return; | 68 return; |
67 | 69 |
68 // Don't bother with INVALID and FORCED_QUERY. Also pass when looking for | 70 // Don't bother with INVALID and FORCED_QUERY. Also pass when looking for |
69 // BEST_MATCH and there is no inline autocompletion because none of the HQP | 71 // BEST_MATCH and there is no inline autocompletion because none of the HQP |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 203 } |
202 } | 204 } |
203 | 205 |
204 // Loop over every result and add it to matches_. In the process, | 206 // Loop over every result and add it to matches_. In the process, |
205 // guarantee that scores are decreasing. |max_match_score| keeps | 207 // guarantee that scores are decreasing. |max_match_score| keeps |
206 // track of the highest score we can assign to any later results we | 208 // track of the highest score we can assign to any later results we |
207 // see. Also, if we're not allowing inline autocompletions in | 209 // see. Also, if we're not allowing inline autocompletions in |
208 // general or the current best suggestion isn't inlineable, | 210 // general or the current best suggestion isn't inlineable, |
209 // artificially reduce the starting |max_match_score| (which | 211 // artificially reduce the starting |max_match_score| (which |
210 // therefore applies to all results) to something low enough that | 212 // therefore applies to all results) to something low enough that |
211 // guarantees no result will be offered as an autocomplete | 213 // guarantees no result will be offered as an inline autocomplete |
212 // suggestion. Also do a similar reduction if we think there will be | 214 // 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 | 215 // 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 | 216 // 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 | 217 // they're visited.) The strength of this last reduction depends on the |
216 // likely score for the URL-what-you-typed result. | 218 // likely score for the URL-what-you-typed result. |
217 | 219 |
218 // |template_url_service| or |template_url| can be NULL in unit tests. | 220 // |template_url_service| or |template_url| can be NULL in unit tests. |
219 TemplateURLService* template_url_service = | 221 TemplateURLService* template_url_service = |
220 TemplateURLServiceFactory::GetForProfile(profile_); | 222 TemplateURLServiceFactory::GetForProfile(profile_); |
221 TemplateURL* template_url = template_url_service ? | 223 TemplateURL* template_url = template_url_service ? |
222 template_url_service->GetDefaultSearchProvider() : NULL; | 224 template_url_service->GetDefaultSearchProvider() : NULL; |
223 int max_match_score = (PreventInlineAutocomplete(autocomplete_input_) || | 225 int max_match_score = (!omnibox_will_reorder_for_legal_default_match_ && |
224 !matches.begin()->can_inline) ? | 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 || |
| 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 |