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

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: Moving out from class variables 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
25 namespace {
26
27 // These magic numbers are duplicated from HistoryURLProvider
28 const int kScoreForBestInlineableResult = 1413;
29 const int kScoreForUnvisitedIntranetResult = 1403;
30 const int kScoreForWhatYouTypedResult = 1203;
31 const int kBaseScoreForNonInlineableResult = 900;
32
33 } // namespace
34
26 namespace history { 35 namespace history {
27 36
28 // ScoredHistoryMatch ---------------------------------------------------------- 37 // ScoredHistoryMatch ----------------------------------------------------------
29 38
30 // static 39 // static
31 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10; 40 const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10;
32 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366; 41 const int ScoredHistoryMatch::kDaysToPrecomputeRecencyScoresFor = 366;
33 const int ScoredHistoryMatch::kMaxRawTermScore = 30; 42 const int ScoredHistoryMatch::kMaxRawTermScore = 30;
34 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL; 43 float* ScoredHistoryMatch::raw_term_score_to_topicality_score_ = NULL;
35 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL; 44 float* ScoredHistoryMatch::days_ago_to_recency_score_ = NULL;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 raw_score_ = GetFinalRelevancyScore(topicality_score, frecency_score); 166 raw_score_ = GetFinalRelevancyScore(topicality_score, frecency_score);
158 raw_score_ = 167 raw_score_ =
159 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max; 168 (raw_score_ <= kint32max) ? static_cast<int>(raw_score_) : kint32max;
160 169
161 if (also_do_hup_like_scoring_ && can_inline_) { 170 if (also_do_hup_like_scoring_ && can_inline_) {
162 // HistoryURL-provider-like scoring gives any match that is 171 // HistoryURL-provider-like scoring gives any match that is
163 // capable of being inlined a certain minimum score. Some of these 172 // capable of being inlined a certain minimum score. Some of these
164 // are given a higher score that lets them be shown in inline. 173 // are given a higher score that lets them be shown in inline.
165 // This test here derives from the test in 174 // This test here derives from the test in
166 // HistoryURLProvider::PromoteMatchForInlineAutocomplete(). 175 // HistoryURLProvider::PromoteMatchForInlineAutocomplete().
167 const bool promote_to_inline = (row.typed_count() > 1) || 176 const bool promote_to_inline = (row.typed_count() > 1) ||
blundell 2014/05/26 06:58:35 This whole function feels like it should be abstra
sdefresne 2014/05/30 15:22:25 No, I had not thought of that, but it makes sense
blundell 2014/06/02 11:11:49 Note: I think that we should come up with a more a
168 (IsHostOnly() && (row.typed_count() == 1)); 177 (IsHostOnly() && (row.typed_count() == 1));
169 int hup_like_score = promote_to_inline ? 178 int hup_like_score = promote_to_inline ?
170 HistoryURLProvider::kScoreForBestInlineableResult : 179 kScoreForBestInlineableResult :
171 HistoryURLProvider::kBaseScoreForNonInlineableResult; 180 kBaseScoreForNonInlineableResult;
172 181
173 // Also, if the user types the hostname of a host with a typed 182 // Also, if the user types the hostname of a host with a typed
174 // visit, then everything from that host get given inlineable scores 183 // visit, then everything from that host get given inlineable scores
175 // (because the URL-that-you-typed will go first and everything 184 // (because the URL-that-you-typed will go first and everything
176 // else will be assigned one minus the previous score, as coded 185 // else will be assigned one minus the previous score, as coded
177 // at the end of HistoryURLProvider::DoAutocomplete(). 186 // at the end of HistoryURLProvider::DoAutocomplete().
178 if (base::UTF8ToUTF16(gurl.host()) == terms[0]) 187 if (base::UTF8ToUTF16(gurl.host()) == terms[0])
179 hup_like_score = HistoryURLProvider::kScoreForBestInlineableResult; 188 hup_like_score = kScoreForBestInlineableResult;
180 189
181 // HistoryURLProvider has the function PromoteOrCreateShorterSuggestion() 190 // HistoryURLProvider has the function PromoteOrCreateShorterSuggestion()
182 // that's meant to promote prefixes of the best match (if they've 191 // that's meant to promote prefixes of the best match (if they've
183 // been visited enough related to the best match) or 192 // been visited enough related to the best match) or
184 // create/promote host-only suggestions (even if they've never 193 // create/promote host-only suggestions (even if they've never
185 // been typed). The code is complicated and we don't try to 194 // been typed). The code is complicated and we don't try to
186 // duplicate the logic here. Instead, we handle a simple case: in 195 // duplicate the logic here. Instead, we handle a simple case: in
187 // low-typed-count ranges, give host-only matches (i.e., 196 // 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 197 // 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 198 // that the host-only match outscores all the other matches that
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 also_do_hup_like_scoring_ = false; 597 also_do_hup_like_scoring_ = false;
589 // When doing HUP-like scoring, don't allow a non-inlineable match 598 // When doing HUP-like scoring, don't allow a non-inlineable match
590 // to beat the score of good inlineable matches. This is a problem 599 // 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 600 // because if a non-inlineable match ends up with the highest score
592 // from HistoryQuick provider, all HistoryQuick matches get demoted 601 // from HistoryQuick provider, all HistoryQuick matches get demoted
593 // to non-inlineable scores (scores less than 1200). Without 602 // to non-inlineable scores (scores less than 1200). Without
594 // HUP-like-scoring, these results would actually come from the HUP 603 // HUP-like-scoring, these results would actually come from the HUP
595 // and not be demoted, thus outscoring the demoted HQP results. 604 // and not be demoted, thus outscoring the demoted HQP results.
596 // When the HQP provides these, we need to clamp the non-inlineable 605 // When the HQP provides these, we need to clamp the non-inlineable
597 // results to preserve this behavior. 606 // results to preserve this behavior.
598 if (also_do_hup_like_scoring_) { 607 if (also_do_hup_like_scoring_) {
blundell 2014/05/26 06:58:35 Am I missing something, or is this dead code? Line
599 max_assigned_score_for_non_inlineable_matches_ = 608 max_assigned_score_for_non_inlineable_matches_ =
600 HistoryURLProvider::kScoreForBestInlineableResult - 1; 609 kScoreForBestInlineableResult - 1;
601 } 610 }
602 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); 611 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue();
603 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); 612 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue();
604 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); 613 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue();
605 initialized_ = true; 614 initialized_ = true;
606 } 615 }
607 616
608 } // namespace history 617 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698