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

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

Issue 353010: Better handling of UNKNOWN versus QUERY in a couple ways.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/histogram.h" 10 #include "base/histogram.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 params->message_loop->PostTask(FROM_HERE, NewRunnableMethod( 120 params->message_loop->PostTask(FROM_HERE, NewRunnableMethod(
121 this, &HistoryURLProvider::QueryComplete, params)); 121 this, &HistoryURLProvider::QueryComplete, params));
122 } 122 }
123 123
124 // Used by both autocomplete passes, and therefore called on multiple different 124 // Used by both autocomplete passes, and therefore called on multiple different
125 // threads (though not simultaneously). 125 // threads (though not simultaneously).
126 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, 126 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
127 history::URLDatabase* db, 127 history::URLDatabase* db,
128 HistoryURLProviderParams* params) { 128 HistoryURLProviderParams* params) {
129 // Create a What You Typed match, which we'll need below. 129 // Create a What You Typed match, which we'll need below.
130 //
131 // We display this to the user when there's a reasonable chance they actually
132 // care:
133 // * Their input can be opened as a URL, and
134 // * They hit ctrl-enter, or we parsed the input as a URL, or it starts with
135 // an explicit "http:" or "https:".
136 // Otherwise, this is just low-quality noise. In the cases where we've parsed
137 // as UNKNOWN, we'll still show an accidental search infobar if need be.
130 bool have_what_you_typed_match = 138 bool have_what_you_typed_match =
131 params->input.canonicalized_url().is_valid() && 139 params->input.canonicalized_url().is_valid() &&
132 (params->input.type() != AutocompleteInput::UNKNOWN) && 140 (params->input.type() != AutocompleteInput::QUERY) &&
133 (params->input.type() != AutocompleteInput::QUERY); 141 ((params->input.type() != AutocompleteInput::UNKNOWN) ||
142 !params->trim_http ||
143 url_util::FindAndCompareScheme(WideToUTF8(params->input.text()),
144 chrome::kHttpsScheme, NULL));
134 AutocompleteMatch what_you_typed_match(SuggestExactInput(params->input, 145 AutocompleteMatch what_you_typed_match(SuggestExactInput(params->input,
135 params->trim_http)); 146 params->trim_http));
136 147
137 // Get the matching URLs from the DB 148 // Get the matching URLs from the DB
138 typedef std::vector<history::URLRow> URLRowVector; 149 typedef std::vector<history::URLRow> URLRowVector;
139 URLRowVector url_matches; 150 URLRowVector url_matches;
140 HistoryMatches history_matches; 151 HistoryMatches history_matches;
141 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); 152 for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end();
142 ++i) { 153 ++i) {
143 if (params->cancel) 154 if (params->cancel)
144 return; // canceled in the middle of a query, give up 155 return; // Canceled in the middle of a query, give up.
145 // We only need max_matches results in the end, but before we get there we 156 // We only need max_matches results in the end, but before we get there we
146 // need to promote lower-quality matches that are prefixes of 157 // need to promote lower-quality matches that are prefixes of
147 // higher-quality matches, and remove lower-quality redirects. So we ask 158 // higher-quality matches, and remove lower-quality redirects. So we ask
148 // for more results than we need, of every prefix type, in hopes this will 159 // for more results than we need, of every prefix type, in hopes this will
149 // give us far more than enough to work with. CullRedirects() will then 160 // give us far more than enough to work with. CullRedirects() will then
150 // reduce the list to the best max_matches results. 161 // reduce the list to the best max_matches results.
151 db->AutocompleteForPrefix(i->prefix + params->input.text(), 162 db->AutocompleteForPrefix(i->prefix + params->input.text(),
152 max_matches() * 2, &url_matches); 163 max_matches() * 2, &url_matches);
153 for (URLRowVector::const_iterator j(url_matches.begin()); 164 for (URLRowVector::const_iterator j(url_matches.begin());
154 j != url_matches.end(); ++j) { 165 j != url_matches.end(); ++j) {
(...skipping 22 matching lines...) Expand all
177 FixupExactSuggestion(db, params->input, &what_you_typed_match, 188 FixupExactSuggestion(db, params->input, &what_you_typed_match,
178 &history_matches)) { 189 &history_matches)) {
179 // Got an exact match for the user's input. Treat it as the best match 190 // Got an exact match for the user's input. Treat it as the best match
180 // regardless of the input type. 191 // regardless of the input type.
181 exact_suggestion = 1; 192 exact_suggestion = 1;
182 params->matches.push_back(what_you_typed_match); 193 params->matches.push_back(what_you_typed_match);
183 } else if (params->input.prevent_inline_autocomplete() || 194 } else if (params->input.prevent_inline_autocomplete() ||
184 history_matches.empty() || 195 history_matches.empty() ||
185 !PromoteMatchForInlineAutocomplete(params, history_matches.front())) { 196 !PromoteMatchForInlineAutocomplete(params, history_matches.front())) {
186 // Failed to promote any URLs for inline autocompletion. Use the What You 197 // Failed to promote any URLs for inline autocompletion. Use the What You
187 // Typed match, if we have it and the input looked like a URL. 198 // Typed match, if we have it.
188 first_match = 0; 199 first_match = 0;
189 if (have_what_you_typed_match) 200 if (have_what_you_typed_match)
190 params->matches.push_back(what_you_typed_match); 201 params->matches.push_back(what_you_typed_match);
191 } 202 }
192 203
193 // This is the end of the synchronous pass. 204 // This is the end of the synchronous pass.
194 if (!backend) 205 if (!backend)
195 return; 206 return;
196 207
197 // Remove redirects and trim list to size. We want to provide up to 208 // Remove redirects and trim list to size. We want to provide up to
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 history_match.input_location - offset, params->input.text().length(), 848 history_match.input_location - offset, params->input.text().length(),
838 match.contents.length(), ACMatchClassification::URL, 849 match.contents.length(), ACMatchClassification::URL,
839 &match.contents_class); 850 &match.contents_class);
840 match.description = info.title(); 851 match.description = info.title();
841 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), 852 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(),
842 ACMatchClassification::NONE, 853 ACMatchClassification::NONE,
843 &match.description_class); 854 &match.description_class);
844 855
845 return match; 856 return match;
846 } 857 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698