| 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/history/scored_history_match.h" | 5 #include "chrome/browser/history/scored_history_match.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <numeric> | 10 #include <numeric> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include <math.h> | 13 #include <math.h> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/browser/autocomplete/history_url_provider.h" | 19 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 20 #include "chrome/browser/autocomplete/url_prefix.h" | 20 #include "chrome/browser/autocomplete/url_prefix.h" |
| 21 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 21 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 22 #include "components/bookmarks/browser/bookmark_service.h" | |
| 23 #include "components/bookmarks/browser/bookmark_utils.h" | 22 #include "components/bookmarks/browser/bookmark_utils.h" |
| 23 #include "components/history/core/browser/history_client.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 | 25 |
| 26 namespace history { | 26 namespace history { |
| 27 | 27 |
| 28 // ScoredHistoryMatch ---------------------------------------------------------- | 28 // ScoredHistoryMatch ---------------------------------------------------------- |
| 29 | 29 |
| 30 // static | 30 // static |
| 31 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; | 31 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; |
| 32 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; | 32 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; |
| 33 const int ScoredHistoryMatch::kMaxRawTermScore = 30; | 33 const int ScoredHistoryMatch::kMaxRawTermScore = 30; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 48 | 48 |
| 49 ScoredHistoryMatch::ScoredHistoryMatch( | 49 ScoredHistoryMatch::ScoredHistoryMatch( |
| 50 const URLRow& row, | 50 const URLRow& row, |
| 51 const VisitInfoVector& visits, | 51 const VisitInfoVector& visits, |
| 52 const std::string& languages, | 52 const std::string& languages, |
| 53 const base::string16& lower_string, | 53 const base::string16& lower_string, |
| 54 const String16Vector& terms, | 54 const String16Vector& terms, |
| 55 const WordStarts& terms_to_word_starts_offsets, | 55 const WordStarts& terms_to_word_starts_offsets, |
| 56 const RowWordStarts& word_starts, | 56 const RowWordStarts& word_starts, |
| 57 const base::Time now, | 57 const base::Time now, |
| 58 BookmarkService* bookmark_service) | 58 HistoryClient* history_client) |
| 59 : HistoryMatch(row, 0, false, false), | 59 : HistoryMatch(row, 0, false, false), |
| 60 raw_score_(0), | 60 raw_score_(0), |
| 61 can_inline_(false) { | 61 can_inline_(false) { |
| 62 Init(); | 62 Init(); |
| 63 | 63 |
| 64 GURL gurl = row.url(); | 64 GURL gurl = row.url(); |
| 65 if (!gurl.is_valid()) | 65 if (!gurl.is_valid()) |
| 66 return; | 66 return; |
| 67 | 67 |
| 68 // Figure out where each search term appears in the URL and/or page title | 68 // Figure out where each search term appears in the URL and/or page title |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 DCHECK(best_inlineable_prefix != NULL); | 146 DCHECK(best_inlineable_prefix != NULL); |
| 147 const int num_components_in_best_inlineable_prefix = | 147 const int num_components_in_best_inlineable_prefix = |
| 148 best_inlineable_prefix->num_components; | 148 best_inlineable_prefix->num_components; |
| 149 innermost_match = (num_components_in_best_inlineable_prefix == | 149 innermost_match = (num_components_in_best_inlineable_prefix == |
| 150 num_components_in_best_prefix); | 150 num_components_in_best_prefix); |
| 151 } | 151 } |
| 152 | 152 |
| 153 const float topicality_score = GetTopicalityScore( | 153 const float topicality_score = GetTopicalityScore( |
| 154 terms.size(), url, terms_to_word_starts_offsets, word_starts); | 154 terms.size(), url, terms_to_word_starts_offsets, word_starts); |
| 155 const float frequency_score = GetFrequency( | 155 const float frequency_score = GetFrequency( |
| 156 now, (bookmark_service && bookmark_service->IsBookmarked(gurl)), visits); | 156 now, (history_client && history_client->IsBookmarked(gurl)), visits); |
| 157 raw_score_ = GetFinalRelevancyScore(topicality_score, frequency_score); | 157 raw_score_ = GetFinalRelevancyScore(topicality_score, frequency_score); |
| 158 raw_score_ = | 158 raw_score_ = |
| 159 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; | 159 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; |
| 160 | 160 |
| 161 if (also_do_hup_like_scoring_ && can_inline_) { | 161 if (also_do_hup_like_scoring_ && can_inline_) { |
| 162 // HistoryURL-provider-like scoring gives any match that is | 162 // HistoryURL-provider-like scoring gives any match that is |
| 163 // capable of being inlined a certain minimum score. Some of these | 163 // capable of being inlined a certain minimum score. Some of these |
| 164 // are given a higher score that lets them be shown in inline. | 164 // are given a higher score that lets them be shown in inline. |
| 165 // This test here derives from the test in | 165 // This test here derives from the test in |
| 166 // HistoryURLProvider::PromoteMatchForInlineAutocomplete(). | 166 // HistoryURLProvider::PromoteMatchForInlineAutocomplete(). |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 max_assigned_score_for_non_inlineable_matches_ = | 599 max_assigned_score_for_non_inlineable_matches_ = |
| 600 HistoryURLProvider::kScoreForBestInlineableResult - 1; | 600 HistoryURLProvider::kScoreForBestInlineableResult - 1; |
| 601 } | 601 } |
| 602 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); | 602 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
| 603 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 603 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
| 604 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 604 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
| 605 initialized_ = true; | 605 initialized_ = true; |
| 606 } | 606 } |
| 607 | 607 |
| 608 } // namespace history | 608 } // namespace history |
| OLD | NEW |