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/bookmarks/bookmark_utils.h" |
21 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 22 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "components/bookmarks/core/browser/bookmark_service.h" | 24 #include "components/bookmarks/core/browser/bookmark_service.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 | 26 |
26 namespace history { | 27 namespace history { |
27 | 28 |
28 // ScoredHistoryMatch ---------------------------------------------------------- | 29 // ScoredHistoryMatch ---------------------------------------------------------- |
29 | 30 |
30 // static | 31 // static |
(...skipping 29 matching lines...) Expand all Loading... |
60 raw_score_(0), | 61 raw_score_(0), |
61 can_inline_(false) { | 62 can_inline_(false) { |
62 Init(); | 63 Init(); |
63 | 64 |
64 GURL gurl = row.url(); | 65 GURL gurl = row.url(); |
65 if (!gurl.is_valid()) | 66 if (!gurl.is_valid()) |
66 return; | 67 return; |
67 | 68 |
68 // Figure out where each search term appears in the URL and/or page title | 69 // Figure out where each search term appears in the URL and/or page title |
69 // so that we can score as well as provide autocomplete highlighting. | 70 // so that we can score as well as provide autocomplete highlighting. |
70 base::string16 url = CleanUpUrlForMatching(gurl, languages); | 71 base::string16 url = bookmark_utils::CleanUpUrlForMatching(gurl, languages); |
71 base::string16 title = CleanUpTitleForMatching(row.title()); | 72 base::string16 title = bookmark_utils::CleanUpTitleForMatching(row.title()); |
72 int term_num = 0; | 73 int term_num = 0; |
73 for (String16Vector::const_iterator iter = terms.begin(); iter != terms.end(); | 74 for (String16Vector::const_iterator iter = terms.begin(); iter != terms.end(); |
74 ++iter, ++term_num) { | 75 ++iter, ++term_num) { |
75 base::string16 term = *iter; | 76 base::string16 term = *iter; |
76 TermMatches url_term_matches = MatchTermInString(term, url, term_num); | 77 TermMatches url_term_matches = MatchTermInString(term, url, term_num); |
77 TermMatches title_term_matches = MatchTermInString(term, title, term_num); | 78 TermMatches title_term_matches = MatchTermInString(term, title, term_num); |
78 if (url_term_matches.empty() && title_term_matches.empty()) | 79 if (url_term_matches.empty() && title_term_matches.empty()) |
79 return; // A term was not found in either URL or title - reject. | 80 return; // A term was not found in either URL or title - reject. |
80 url_matches_.insert(url_matches_.end(), url_term_matches.begin(), | 81 url_matches_.insert(url_matches_.end(), url_term_matches.begin(), |
81 url_term_matches.end()); | 82 url_term_matches.end()); |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 max_assigned_score_for_non_inlineable_matches_ = | 591 max_assigned_score_for_non_inlineable_matches_ = |
591 HistoryURLProvider::kScoreForBestInlineableResult - 1; | 592 HistoryURLProvider::kScoreForBestInlineableResult - 1; |
592 } | 593 } |
593 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); | 594 bookmark_value_ = OmniboxFieldTrial::HQPBookmarkValue(); |
594 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); | 595 allow_tld_matches_ = OmniboxFieldTrial::HQPAllowMatchInTLDValue(); |
595 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); | 596 allow_scheme_matches_ = OmniboxFieldTrial::HQPAllowMatchInSchemeValue(); |
596 initialized_ = true; | 597 initialized_ = true; |
597 } | 598 } |
598 | 599 |
599 } // namespace history | 600 } // namespace history |
OLD | NEW |