Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Side by Side Diff: chrome/browser/history/scored_history_match.cc

Issue 284183011: Code clean up for ScoredHistoryMatch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
20 #include "chrome/browser/autocomplete/url_prefix.h" 19 #include "chrome/browser/autocomplete/url_prefix.h"
21 #include "chrome/browser/omnibox/omnibox_field_trial.h" 20 #include "chrome/browser/omnibox/omnibox_field_trial.h"
22 #include "components/bookmarks/browser/bookmark_service.h" 21 #include "components/bookmarks/browser/bookmark_service.h"
23 #include "components/bookmarks/browser/bookmark_utils.h" 22 #include "components/bookmarks/browser/bookmark_utils.h"
24 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
25 24
26 namespace history { 25 namespace history {
27 26
28 // ScoredHistoryMatch ---------------------------------------------------------- 27 // ScoredHistoryMatch ----------------------------------------------------------
29 28
30 // static 29 // static
31 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; 30 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10;
32 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; 31 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366;
33 const int ScoredHistoryMatch::kMaxRawTermScore = 30; 32 const int ScoredHistoryMatch::kMaxRawTermScore = 30;
34 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL; 33 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL;
35 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL; 34 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL;
36 bool ScoredHistoryMatch::initialized_ = false; 35 bool ScoredHistoryMatch::initialized_ = false;
37 int ScoredHistoryMatch::bookmark_value_ = 1; 36 int ScoredHistoryMatch::bookmark_value_ = 1;
38 bool ScoredHistoryMatch::allow_tld_matches_ = false; 37 bool ScoredHistoryMatch::allow_tld_matches_ = false;
39 bool ScoredHistoryMatch::allow_scheme_matches_ = false; 38 bool ScoredHistoryMatch::allow_scheme_matches_ = false;
40 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false; 39 bool ScoredHistoryMatch::also_do_hup_like_scoring_ = false;
41 int ScoredHistoryMatch::max_assigned_score_for_non_inlineable_matches_ = -1; 40 int ScoredHistoryMatch::max_assigned_score_for_non_inlineable_matches_ = -1;
42 41
42 // These magic numbers are duplicated from HistoryURLProvider
43 const int ScoredHistoryMatch::kScoreForBestInlineableResult = 1413;
44 const int ScoredHistoryMatch::kScoreForUnvisitedIntranetResult = 1403;
45 const int ScoredHistoryMatch::kScoreForWhatYouTypedResult = 1203;
46 const int ScoredHistoryMatch::kBaseScoreForNonInlineableResult = 900;
47
43 ScoredHistoryMatch::ScoredHistoryMatch() 48 ScoredHistoryMatch::ScoredHistoryMatch()
44 : raw_score_(0), 49 : raw_score_(0),
45 can_inline_(false) { 50 can_inline_(false) {
46 Init(); 51 Init();
47 } 52 }
48 53
49 ScoredHistoryMatch::ScoredHistoryMatch( 54 ScoredHistoryMatch::ScoredHistoryMatch(
50 const URLRow& row, 55 const URLRow& row,
51 const VisitInfoVector& visits, 56 const VisitInfoVector& visits,
52 const std::string& languages, 57 const std::string& languages,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 now, (bookmark_service && bookmark_service->IsBookmarked(gurl)), visits); 161 now, (bookmark_service && bookmark_service->IsBookmarked(gurl)), visits);
157 raw_score_ = GetFinalRelevancyScore(topicality_score, frecency_score); 162 raw_score_ = GetFinalRelevancyScore(topicality_score, frecency_score);
158 raw_score_ = 163 raw_score_ =
159 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; 164 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max;
160 165
161 if (also_do_hup_like_scoring_ && can_inline_) { 166 if (also_do_hup_like_scoring_ && can_inline_) {
162 // HistoryURL-provider-like scoring gives any match that is 167 // HistoryURL-provider-like scoring gives any match that is
163 // capable of being inlined a certain minimum score. Some of these 168 // capable of being inlined a certain minimum score. Some of these
164 // are given a higher score that lets them be shown in inline. 169 // are given a higher score that lets them be shown in inline.
165 // This test here derives from the test in 170 // This test here derives from the test in
166 // HistoryURLProvider::PromoteMatchForInlineAutocomplete(). 171 // ScoredHistoryMatch::PromoteMatchForInlineAutocomplete().
167 const bool promote_to_inline = (row.typed_count() > 1) || 172 const bool promote_to_inline = (row.typed_count() > 1) ||
168 (IsHostOnly() && (row.typed_count() == 1)); 173 (IsHostOnly() && (row.typed_count() == 1));
169 int hup_like_score = promote_to_inline ? 174 int hup_like_score = promote_to_inline ?
170 HistoryURLProvider::kScoreForBestInlineableResult : 175 ScoredHistoryMatch::kScoreForBestInlineableResult :
171 HistoryURLProvider::kBaseScoreForNonInlineableResult; 176 ScoredHistoryMatch::kBaseScoreForNonInlineableResult;
172 177
173 // Also, if the user types the hostname of a host with a typed 178 // Also, if the user types the hostname of a host with a typed
174 // visit, then everything from that host get given inlineable scores 179 // visit, then everything from that host get given inlineable scores
175 // (because the URL-that-you-typed will go first and everything 180 // (because the URL-that-you-typed will go first and everything
176 // else will be assigned one minus the previous score, as coded 181 // else will be assigned one minus the previous score, as coded
177 // at the end of HistoryURLProvider::DoAutocomplete(). 182 // at the end of ScoredHistoryMatch::DoAutocomplete().
178 if (base::UTF8ToUTF16(gurl.host()) == terms[0]) 183 if (base::UTF8ToUTF16(gurl.host()) == terms[0])
179 hup_like_score = HistoryURLProvider::kScoreForBestInlineableResult; 184 hup_like_score = ScoredHistoryMatch::kScoreForBestInlineableResult;
180 185
181 // HistoryURLProvider has the function PromoteOrCreateShorterSuggestion() 186 // HistoryURLProvider has the function PromoteOrCreateShorterSuggestion()
182 // that's meant to promote prefixes of the best match (if they've 187 // that's meant to promote prefixes of the best match (if they've
183 // been visited enough related to the best match) or 188 // been visited enough related to the best match) or
184 // create/promote host-only suggestions (even if they've never 189 // create/promote host-only suggestions (even if they've never
185 // been typed). The code is complicated and we don't try to 190 // been typed). The code is complicated and we don't try to
186 // duplicate the logic here. Instead, we handle a simple case: in 191 // duplicate the logic here. Instead, we handle a simple case: in
187 // low-typed-count ranges, give host-only matches (i.e., 192 // low-typed-count ranges, give host-only matches (i.e.,
188 // http://www.foo.com/ vs. http://www.foo.com/bar.html) a boost so 193 // http://www.foo.com/ vs. http://www.foo.com/bar.html) a boost so
189 // that the host-only match outscores all the other matches that 194 // that the host-only match outscores all the other matches that
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // to beat the score of good inlineable matches. This is a problem 595 // to beat the score of good inlineable matches. This is a problem
591 // because if a non-inlineable match ends up with the highest score 596 // because if a non-inlineable match ends up with the highest score
592 // from HistoryQuick provider, all HistoryQuick matches get demoted 597 // from HistoryQuick provider, all HistoryQuick matches get demoted
593 // to non-inlineable scores (scores less than 1200). Without 598 // to non-inlineable scores (scores less than 1200). Without
594 // HUP-like-scoring, these results would actually come from the HUP 599 // HUP-like-scoring, these results would actually come from the HUP
595 // and not be demoted, thus outscoring the demoted HQP results. 600 // and not be demoted, thus outscoring the demoted HQP results.
596 // When the HQP provides these, we need to clamp the non-inlineable 601 // When the HQP provides these, we need to clamp the non-inlineable
597 // results to preserve this behavior. 602 // results to preserve this behavior.
598 if (also_do_hup_like_scoring_) { 603 if (also_do_hup_like_scoring_) {
599 max_assigned_score_for_non_inlineable_matches_ = 604 max_assigned_score_for_non_inlineable_matches_ =
600 HistoryURLProvider::kScoreForBestInlineableResult - 1; 605 ScoredHistoryMatch::kScoreForBestInlineableResult - 1;
601 } 606 }
602 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); 607 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue();
603 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); 608 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue();
604 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); 609 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue();
605 initialized_ = true; 610 initialized_ = true;
606 } 611 }
607 612
608 } // namespace history 613 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698