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

Unified Diff: components/omnibox/browser/scored_history_match.cc

Issue 2355053003: Omnibox - Allow Matching in Port Number (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: components/omnibox/browser/scored_history_match.cc
diff --git a/components/omnibox/browser/scored_history_match.cc b/components/omnibox/browser/scored_history_match.cc
index df76edb89d92bbd4915f7862035f25db6b97faed..f7f7c3c55c792393ff36df897e1f41d4ce351808 100644
--- a/components/omnibox/browser/scored_history_match.cc
+++ b/components/omnibox/browser/scored_history_match.cc
@@ -468,9 +468,21 @@ float ScoredHistoryMatch::GetTopicalityScore(
const size_t end_of_hostname_pos = (colon_pos != std::string::npos)
? url.find('/', colon_pos + 3)
: url.find('/');
- size_t last_part_of_hostname_pos = (end_of_hostname_pos != std::string::npos)
- ? url.rfind('.', end_of_hostname_pos)
- : url.rfind('.');
+ const size_t last_part_of_hostname_pos =
+ (end_of_hostname_pos != std::string::npos)
+ ? url.rfind('.', end_of_hostname_pos)
+ : url.rfind('.');
+ // Find the port in the last part of the hostname if we've identified such.
+ // Otherwise, find it starting from later in the URL and looking backwards.
+ size_t port_pos = (last_part_of_hostname_pos != std::string::npos)
+ ? url.find(':', last_part_of_hostname_pos)
+ : url.rfind(':',
+ (end_of_hostname_pos != std::string::npos)
+ ? end_of_hostname_pos
+ : url.length());
+ // If we've found the colon in the scheme, that's not the port!
+ if (port_pos <= colon_pos)
+ port_pos = std::string::npos;
Peter Kasting 2016/09/20 20:44:55 I'm really uncomfortable with all this code. A cl
// Loop through all URL matches and score them appropriately.
// First, filter all matches not at a word boundary and in the path (or
// later).
@@ -504,6 +516,12 @@ float ScoredHistoryMatch::GetTopicalityScore(
// The match is in the path.
DCHECK(at_word_boundary);
term_scores[url_match.term_num] += 8;
+ } else if ((port_pos != std::string::npos) &&
+ (url_match.offset > port_pos)) {
+ // The match is in the port.
+ // (This'll also trigger for the last component of raw IPv6 addresses.
+ // This situation isn't worth worrying about.)
+ term_scores[url_match.term_num] += at_word_boundary ? 5 : 0;
} else if ((colon_pos == std::string::npos) ||
(url_match.offset > colon_pos)) {
// The match is in the hostname.
« no previous file with comments | « components/omnibox/browser/scored_history_match.h ('k') | components/omnibox/browser/scored_history_match_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698