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_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { | 471 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { |
472 } | 472 } |
473 | 473 |
474 HistoryURLProviderParams::~HistoryURLProviderParams() { | 474 HistoryURLProviderParams::~HistoryURLProviderParams() { |
475 } | 475 } |
476 | 476 |
477 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderListener* listener, | 477 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderListener* listener, |
478 Profile* profile) | 478 Profile* profile) |
479 : HistoryProvider(profile, AutocompleteProvider::TYPE_HISTORY_URL), | 479 : HistoryProvider(profile, AutocompleteProvider::TYPE_HISTORY_URL), |
480 listener_(listener), | 480 listener_(listener), |
481 params_(NULL), | 481 params_(NULL) { |
482 cull_redirects_( | |
483 !OmniboxFieldTrial::InHUPCullRedirectsFieldTrial() || | |
484 !OmniboxFieldTrial::InHUPCullRedirectsFieldTrialExperimentGroup()), | |
485 create_shorter_match_( | |
486 !OmniboxFieldTrial::InHUPCreateShorterMatchFieldTrial() || | |
487 !OmniboxFieldTrial:: | |
488 InHUPCreateShorterMatchFieldTrialExperimentGroup()) { | |
489 // Initialize HUP scoring params based on the current experiment. | 482 // Initialize HUP scoring params based on the current experiment. |
490 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); | 483 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); |
491 } | 484 } |
492 | 485 |
493 void HistoryURLProvider::Start(const AutocompleteInput& input, | 486 void HistoryURLProvider::Start(const AutocompleteInput& input, |
494 bool minimal_changes) { | 487 bool minimal_changes) { |
495 // NOTE: We could try hard to do less work in the |minimal_changes| case | 488 // NOTE: We could try hard to do less work in the |minimal_changes| case |
496 // here; some clever caching would let us reuse the raw matches from the | 489 // here; some clever caching would let us reuse the raw matches from the |
497 // history DB without re-querying. However, we'd still have to go back to | 490 // history DB without re-querying. However, we'd still have to go back to |
498 // the history thread to mark these up properly, and if pass 2 is currently | 491 // the history thread to mark these up properly, and if pass 2 is currently |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 params->promote_type = HistoryURLProviderParams::FRONT_HISTORY_MATCH; | 809 params->promote_type = HistoryURLProviderParams::FRONT_HISTORY_MATCH; |
817 } else { | 810 } else { |
818 // Failed to promote any URLs. Use the What You Typed match, if we have it. | 811 // Failed to promote any URLs. Use the What You Typed match, if we have it. |
819 params->promote_type = params->have_what_you_typed_match ? | 812 params->promote_type = params->have_what_you_typed_match ? |
820 HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH : | 813 HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH : |
821 HistoryURLProviderParams::NEITHER; | 814 HistoryURLProviderParams::NEITHER; |
822 } | 815 } |
823 | 816 |
824 const size_t max_results = | 817 const size_t max_results = |
825 kMaxMatches + (params->exact_suggestion_is_in_history ? 1 : 0); | 818 kMaxMatches + (params->exact_suggestion_is_in_history ? 1 : 0); |
826 if (backend && cull_redirects_) { | 819 if (backend) { |
827 // Remove redirects and trim list to size. We want to provide up to | 820 // Remove redirects and trim list to size. We want to provide up to |
828 // kMaxMatches results plus the What You Typed result, if it was added to | 821 // kMaxMatches results plus the What You Typed result, if it was added to |
829 // params->matches above. | 822 // params->matches above. |
830 CullRedirects(backend, ¶ms->matches, max_results); | 823 CullRedirects(backend, ¶ms->matches, max_results); |
831 } else if (params->matches.size() > max_results) { | 824 } else if (params->matches.size() > max_results) { |
832 // Simply trim the list to size. | 825 // Simply trim the list to size. |
833 params->matches.resize(max_results); | 826 params->matches.resize(max_results); |
834 } | 827 } |
835 } | 828 } |
836 | 829 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 // Try to get info on the search base itself. Promote it to the top if the | 1041 // Try to get info on the search base itself. Promote it to the top if the |
1049 // original best match isn't good enough to autocomplete. | 1042 // original best match isn't good enough to autocomplete. |
1050 db->GetRowForURL(search_base, &info); | 1043 db->GetRowForURL(search_base, &info); |
1051 promote = match.url_info.typed_count() <= 1; | 1044 promote = match.url_info.typed_count() <= 1; |
1052 } | 1045 } |
1053 | 1046 |
1054 // Promote or add the desired URL to the list of matches. | 1047 // Promote or add the desired URL to the list of matches. |
1055 const bool ensure_can_inline = | 1048 const bool ensure_can_inline = |
1056 promote && CanPromoteMatchForInlineAutocomplete(match); | 1049 promote && CanPromoteMatchForInlineAutocomplete(match); |
1057 return CreateOrPromoteMatch(info, match.input_location, match.match_in_scheme, | 1050 return CreateOrPromoteMatch(info, match.input_location, match.match_in_scheme, |
1058 ¶ms->matches, create_shorter_match_, | 1051 ¶ms->matches, true, promote) && |
1059 promote) && | |
1060 ensure_can_inline; | 1052 ensure_can_inline; |
1061 } | 1053 } |
1062 | 1054 |
1063 void HistoryURLProvider::CullPoorMatches( | 1055 void HistoryURLProvider::CullPoorMatches( |
1064 HistoryURLProviderParams* params) const { | 1056 HistoryURLProviderParams* params) const { |
1065 const base::Time& threshold(history::AutocompleteAgeThreshold()); | 1057 const base::Time& threshold(history::AutocompleteAgeThreshold()); |
1066 for (history::HistoryMatches::iterator i(params->matches.begin()); | 1058 for (history::HistoryMatches::iterator i(params->matches.begin()); |
1067 i != params->matches.end(); ) { | 1059 i != params->matches.end(); ) { |
1068 if (RowQualifiesAsSignificant(i->url_info, threshold) && | 1060 if (RowQualifiesAsSignificant(i->url_info, threshold) && |
1069 (!params->default_search_provider || | 1061 (!params->default_search_provider || |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1185 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
1194 match.contents.length(), ACMatchClassification::URL, | 1186 match.contents.length(), ACMatchClassification::URL, |
1195 &match.contents_class); | 1187 &match.contents_class); |
1196 } | 1188 } |
1197 match.description = info.title(); | 1189 match.description = info.title(); |
1198 match.description_class = | 1190 match.description_class = |
1199 ClassifyDescription(params.input.text(), match.description); | 1191 ClassifyDescription(params.input.text(), match.description); |
1200 RecordAdditionalInfoFromUrlRow(info, &match); | 1192 RecordAdditionalInfoFromUrlRow(info, &match); |
1201 return match; | 1193 return match; |
1202 } | 1194 } |
OLD | NEW |