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_) || |
msw
2013/07/18 06:23:57
Did you mean to negate this boolean? It looks unin
Peter Kasting
2013/07/18 17:35:28
Hmm, good catch, I agree. I looked at this code w
Mark P
2013/07/21 20:31:05
Yes, good catch. That was a bug. Fixed.
| |
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_)) { | |
276 match.inline_autocomplete_offset = string16::npos; | 280 match.inline_autocomplete_offset = string16::npos; |
277 } else { | 281 } else { |
278 DCHECK(!new_matches.empty()); | 282 DCHECK(!new_matches.empty()); |
279 match.inline_autocomplete_offset = new_matches[0].offset + | 283 match.inline_autocomplete_offset = new_matches[0].offset + |
280 new_matches[0].length; | 284 new_matches[0].length; |
285 match.allowed_to_be_default_match = true; | |
281 // The following will happen if the user has typed an URL with a scheme | 286 // The following will happen if the user has typed an URL with a scheme |
282 // and the last character typed is a slash because that slash is removed | 287 // and the last character typed is a slash because that slash is removed |
283 // by the FormatURLWithOffsets call above. | 288 // by the FormatURLWithOffsets call above. |
284 if (match.inline_autocomplete_offset > match.fill_into_edit.length()) | 289 if (match.inline_autocomplete_offset > match.fill_into_edit.length()) |
285 match.inline_autocomplete_offset = match.fill_into_edit.length(); | 290 match.inline_autocomplete_offset = match.fill_into_edit.length(); |
286 } | 291 } |
287 | 292 |
288 // Format the description autocomplete presentation. | 293 // Format the description autocomplete presentation. |
289 match.description = info.title(); | 294 match.description = info.title(); |
290 match.description_class = SpansFromTermMatch( | 295 match.description_class = SpansFromTermMatch( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 do { | 338 do { |
334 offset += matches[i].length; | 339 offset += matches[i].length; |
335 ++i; | 340 ++i; |
336 } while ((i < match_count) && (offset == matches[i].offset)); | 341 } while ((i < match_count) && (offset == matches[i].offset)); |
337 if (offset < text_length) | 342 if (offset < text_length) |
338 spans.push_back(ACMatchClassification(offset, url_style)); | 343 spans.push_back(ACMatchClassification(offset, url_style)); |
339 } | 344 } |
340 | 345 |
341 return spans; | 346 return spans; |
342 } | 347 } |
OLD | NEW |