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

Side by Side Diff: chrome/browser/autocomplete/history_url_provider.cc

Issue 10879042: Move IsHostOnly() from HistoryURL provider to HistoryMatch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Vertical space. Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autocomplete/history_provider_util.cc ('k') | 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/autocomplete/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if ((host.spec().length() < (match.input_location + input.length()))) 85 if ((host.spec().length() < (match.input_location + input.length())))
86 return GURL(); // User typing is longer than this host suggestion. 86 return GURL(); // User typing is longer than this host suggestion.
87 87
88 const string16 spec = UTF8ToUTF16(host.spec()); 88 const string16 spec = UTF8ToUTF16(host.spec());
89 if (spec.compare(match.input_location, input.length(), input)) 89 if (spec.compare(match.input_location, input.length(), input))
90 return GURL(); // User typing is no longer a prefix. 90 return GURL(); // User typing is no longer a prefix.
91 91
92 return host; 92 return host;
93 } 93 }
94 94
95 // Returns true if |url| is just a host (e.g. "http://www.google.com/") and not
96 // some other subpage (e.g. "http://www.google.com/foo.html").
97 bool IsHostOnly(const GURL& url) {
98 DCHECK(url.is_valid());
99 return (!url.has_path() || (url.path() == "/")) && !url.has_query() &&
100 !url.has_ref();
101 }
102
103 // Acts like the > operator for URLInfo classes. 95 // Acts like the > operator for URLInfo classes.
104 bool CompareHistoryMatch(const history::HistoryMatch& a, 96 bool CompareHistoryMatch(const history::HistoryMatch& a,
105 const history::HistoryMatch& b) { 97 const history::HistoryMatch& b) {
106 // A URL that has been typed at all is better than one that has never been 98 // A URL that has been typed at all is better than one that has never been
107 // typed. (Note "!"s on each side) 99 // typed. (Note "!"s on each side)
108 if (!a.url_info.typed_count() != !b.url_info.typed_count()) 100 if (!a.url_info.typed_count() != !b.url_info.typed_count())
109 return a.url_info.typed_count() > b.url_info.typed_count(); 101 return a.url_info.typed_count() > b.url_info.typed_count();
110 102
111 // Innermost matches (matches after any scheme or "www.") are better than 103 // Innermost matches (matches after any scheme or "www.") are better than
112 // non-innermost matches. 104 // non-innermost matches.
113 if (a.innermost_match != b.innermost_match) 105 if (a.innermost_match != b.innermost_match)
114 return a.innermost_match; 106 return a.innermost_match;
115 107
116 // URLs that have been typed more often are better. 108 // URLs that have been typed more often are better.
117 if (a.url_info.typed_count() != b.url_info.typed_count()) 109 if (a.url_info.typed_count() != b.url_info.typed_count())
118 return a.url_info.typed_count() > b.url_info.typed_count(); 110 return a.url_info.typed_count() > b.url_info.typed_count();
119 111
120 // For URLs that have each been typed once, a host (alone) is better than a 112 // For URLs that have each been typed once, a host (alone) is better than a
121 // page inside. 113 // page inside.
122 if (a.url_info.typed_count() == 1) { 114 if ((a.url_info.typed_count() == 1) && (a.IsHostOnly() != b.IsHostOnly()))
123 const bool a_is_host_only = IsHostOnly(a.url_info.url()); 115 return a.IsHostOnly();
124 if (a_is_host_only != IsHostOnly(b.url_info.url()))
125 return a_is_host_only;
126 }
127 116
128 // URLs that have been visited more often are better. 117 // URLs that have been visited more often are better.
129 if (a.url_info.visit_count() != b.url_info.visit_count()) 118 if (a.url_info.visit_count() != b.url_info.visit_count())
130 return a.url_info.visit_count() > b.url_info.visit_count(); 119 return a.url_info.visit_count() > b.url_info.visit_count();
131 120
132 // URLs that have been visited more recently are better. 121 // URLs that have been visited more recently are better.
133 return a.url_info.last_visit() > b.url_info.last_visit(); 122 return a.url_info.last_visit() > b.url_info.last_visit();
134 } 123 }
135 124
136 } // namespace 125 } // namespace
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 HistoryURLProviderParams* params, 656 HistoryURLProviderParams* params,
668 const history::HistoryMatch& match) { 657 const history::HistoryMatch& match) {
669 // Promote the first match if it's been typed at least n times, where n == 1 658 // Promote the first match if it's been typed at least n times, where n == 1
670 // for "simple" (host-only) URLs and n == 2 for others. We set a higher bar 659 // for "simple" (host-only) URLs and n == 2 for others. We set a higher bar
671 // for these long URLs because it's less likely that users will want to visit 660 // for these long URLs because it's less likely that users will want to visit
672 // them again. Even though we don't increment the typed_count for pasted-in 661 // them again. Even though we don't increment the typed_count for pasted-in
673 // URLs, if the user manually edits the URL or types some long thing in by 662 // URLs, if the user manually edits the URL or types some long thing in by
674 // hand, we wouldn't want to immediately start autocompleting it. 663 // hand, we wouldn't want to immediately start autocompleting it.
675 if (!match.url_info.typed_count() || 664 if (!match.url_info.typed_count() ||
676 ((match.url_info.typed_count() == 1) && 665 ((match.url_info.typed_count() == 1) &&
677 !IsHostOnly(match.url_info.url()))) 666 !match.IsHostOnly()))
678 return false; 667 return false;
679 668
680 // In the case where the user has typed "foo.com" and visited (but not typed) 669 // In the case where the user has typed "foo.com" and visited (but not typed)
681 // "foo/", and the input is "foo", we can reach here for "foo.com" during the 670 // "foo/", and the input is "foo", we can reach here for "foo.com" during the
682 // first pass but have the second pass suggest the exact input as a better 671 // first pass but have the second pass suggest the exact input as a better
683 // URL. Since we need both passes to agree, and since during the first pass 672 // URL. Since we need both passes to agree, and since during the first pass
684 // there's no way to know about "foo/", make reaching this point prevent any 673 // there's no way to know about "foo/", make reaching this point prevent any
685 // future pass from suggesting the exact input as a better match. 674 // future pass from suggesting the exact input as a better match.
686 if (params) { 675 if (params) {
687 params->dont_suggest_exact_input = true; 676 params->dont_suggest_exact_input = true;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 info.title(), 924 info.title(),
936 ACMatchClassification::NONE, 925 ACMatchClassification::NONE,
937 &match.description_class); 926 &match.description_class);
938 927
939 match.RecordAdditionalInfo("typed count", info.typed_count()); 928 match.RecordAdditionalInfo("typed count", info.typed_count());
940 match.RecordAdditionalInfo("visit count", info.visit_count()); 929 match.RecordAdditionalInfo("visit count", info.visit_count());
941 match.RecordAdditionalInfo("last visit", info.last_visit()); 930 match.RecordAdditionalInfo("last visit", info.last_visit());
942 931
943 return match; 932 return match;
944 } 933 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_provider_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698