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

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

Issue 353223002: Omnibox: Fix URL-What-You-Typed Allowed-To-Be-Default-Match Issues (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove extra << Created 6 years, 5 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
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/shortcuts_provider.h" 5 #include "chrome/browser/autocomplete/shortcuts_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 void ShortcutsProvider::GetMatches(const AutocompleteInput& input) { 134 void ShortcutsProvider::GetMatches(const AutocompleteInput& input) {
135 scoped_refptr<ShortcutsBackend> backend = 135 scoped_refptr<ShortcutsBackend> backend =
136 ShortcutsBackendFactory::GetForProfileIfExists(profile_); 136 ShortcutsBackendFactory::GetForProfileIfExists(profile_);
137 if (!backend.get()) 137 if (!backend.get())
138 return; 138 return;
139 // Get the URLs from the shortcuts database with keys that partially or 139 // Get the URLs from the shortcuts database with keys that partially or
140 // completely match the search term. 140 // completely match the search term.
141 base::string16 term_string(base::i18n::ToLower(input.text())); 141 base::string16 term_string(base::i18n::ToLower(input.text()));
142 DCHECK(!term_string.empty()); 142 DCHECK(!term_string.empty());
143 143
144 const GURL& input_as_gurl = 144 TemplateURLService* template_url_service =
145 url_fixer::FixupURL(base::UTF16ToUTF8(input.text()), std::string()); 145 TemplateURLServiceFactory::GetForProfile(profile_);
146 const base::string16 fixed_up_input(FixupUserInput(input).second); 146 const base::string16 fixed_up_input(FixupUserInput(input).second);
Peter Kasting 2014/07/09 00:46:43 Tiny nit: Really we should perhaps be computing th
Mark P 2014/07/09 19:54:17 Done.
147 147
148 int max_relevance; 148 int max_relevance;
149 if (!OmniboxFieldTrial::ShortcutsScoringMaxRelevance( 149 if (!OmniboxFieldTrial::ShortcutsScoringMaxRelevance(
150 input.current_page_classification(), &max_relevance)) 150 input.current_page_classification(), &max_relevance))
151 max_relevance = kShortcutsProviderDefaultMaxRelevance; 151 max_relevance = kShortcutsProviderDefaultMaxRelevance;
152 152
153 for (ShortcutsBackend::ShortcutMap::const_iterator it = 153 for (ShortcutsBackend::ShortcutMap::const_iterator it =
154 FindFirstMatch(term_string, backend.get()); 154 FindFirstMatch(term_string, backend.get());
155 it != backend->shortcuts_map().end() && 155 it != backend->shortcuts_map().end() &&
156 StartsWith(it->first, term_string, true); ++it) { 156 StartsWith(it->first, term_string, true); ++it) {
157 // Don't return shortcuts with zero relevance. 157 // Don't return shortcuts with zero relevance.
158 int relevance = CalculateScore(term_string, it->second, max_relevance); 158 int relevance = CalculateScore(term_string, it->second, max_relevance);
159 if (relevance) { 159 if (relevance) {
160 matches_.push_back(ShortcutToACMatch(it->second, relevance, input, 160 matches_.push_back(ShortcutToACMatch(it->second, relevance, input,
161 fixed_up_input, input_as_gurl)); 161 fixed_up_input));
162 matches_.back().ComputeStrippedDestinationURL( 162 matches_.back().ComputeStrippedDestinationURL(template_url_service);
163 TemplateURLServiceFactory::GetForProfile(profile_));
164 } 163 }
165 } 164 }
166 // Remove duplicates. Duplicates don't need to be preserved in the matches 165 // Remove duplicates. Duplicates don't need to be preserved in the matches
167 // because they are only used for deletions, and shortcuts deletes matches 166 // because they are only used for deletions, and shortcuts deletes matches
168 // based on the URL. 167 // based on the URL.
169 AutocompleteResult::DedupMatchesByDestination( 168 AutocompleteResult::DedupMatchesByDestination(
170 input.current_page_classification(), false, &matches_); 169 input.current_page_classification(), false, &matches_);
171 // Find best matches. 170 // Find best matches.
172 std::partial_sort(matches_.begin(), 171 std::partial_sort(matches_.begin(),
173 matches_.begin() + 172 matches_.begin() +
(...skipping 10 matching lines...) Expand all
184 it->relevance = max_relevance; 183 it->relevance = max_relevance;
185 if (max_relevance > 1) 184 if (max_relevance > 1)
186 --max_relevance; 185 --max_relevance;
187 } 186 }
188 } 187 }
189 188
190 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch( 189 AutocompleteMatch ShortcutsProvider::ShortcutToACMatch(
191 const history::ShortcutsDatabase::Shortcut& shortcut, 190 const history::ShortcutsDatabase::Shortcut& shortcut,
192 int relevance, 191 int relevance,
193 const AutocompleteInput& input, 192 const AutocompleteInput& input,
194 const base::string16& fixed_up_input_text, 193 const base::string16& fixed_up_input_text) {
195 const GURL& input_as_gurl) {
196 DCHECK(!input.text().empty()); 194 DCHECK(!input.text().empty());
197 AutocompleteMatch match; 195 AutocompleteMatch match;
198 match.provider = this; 196 match.provider = this;
199 match.relevance = relevance; 197 match.relevance = relevance;
200 match.deletable = true; 198 match.deletable = true;
201 match.fill_into_edit = shortcut.match_core.fill_into_edit; 199 match.fill_into_edit = shortcut.match_core.fill_into_edit;
202 match.destination_url = shortcut.match_core.destination_url; 200 match.destination_url = shortcut.match_core.destination_url;
203 DCHECK(match.destination_url.is_valid()); 201 DCHECK(match.destination_url.is_valid());
204 match.contents = shortcut.match_core.contents; 202 match.contents = shortcut.match_core.contents;
205 match.contents_class = AutocompleteMatch::ClassificationsFromString( 203 match.contents_class = AutocompleteMatch::ClassificationsFromString(
(...skipping 30 matching lines...) Expand all
236 } else { 234 } else {
237 const size_t inline_autocomplete_offset = 235 const size_t inline_autocomplete_offset =
238 URLPrefix::GetInlineAutocompleteOffset( 236 URLPrefix::GetInlineAutocompleteOffset(
239 input.text(), fixed_up_input_text, true, match.fill_into_edit); 237 input.text(), fixed_up_input_text, true, match.fill_into_edit);
240 if (inline_autocomplete_offset != base::string16::npos) { 238 if (inline_autocomplete_offset != base::string16::npos) {
241 match.inline_autocompletion = 239 match.inline_autocompletion =
242 match.fill_into_edit.substr(inline_autocomplete_offset); 240 match.fill_into_edit.substr(inline_autocomplete_offset);
243 match.allowed_to_be_default_match = 241 match.allowed_to_be_default_match =
244 !HistoryProvider::PreventInlineAutocomplete(input) || 242 !HistoryProvider::PreventInlineAutocomplete(input) ||
245 match.inline_autocompletion.empty(); 243 match.inline_autocompletion.empty();
246 } else {
247 // Also allow a user's input to be marked as default if it would be fixed
248 // up to the same thing as the fill_into_edit. This handles cases like
249 // the user input containing a trailing slash absent in fill_into_edit.
250 match.allowed_to_be_default_match =
251 (input_as_gurl ==
252 url_fixer::FixupURL(base::UTF16ToUTF8(match.fill_into_edit),
253 std::string()));
254 } 244 }
255 } 245 }
246 match.EnsureUWYTIsAllowedToBeDefault(
247 input.canonicalized_url(),
248 TemplateURLServiceFactory::GetForProfile(profile_));
256 249
257 // Try to mark pieces of the contents and description as matches if they 250 // Try to mark pieces of the contents and description as matches if they
258 // appear in |input.text()|. 251 // appear in |input.text()|.
259 const base::string16 term_string = base::i18n::ToLower(input.text()); 252 const base::string16 term_string = base::i18n::ToLower(input.text());
260 WordMap terms_map(CreateWordMapForString(term_string)); 253 WordMap terms_map(CreateWordMapForString(term_string));
261 if (!terms_map.empty()) { 254 if (!terms_map.empty()) {
262 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, 255 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map,
263 match.contents, match.contents_class); 256 match.contents, match.contents_class);
264 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, 257 match.description_class = ClassifyAllMatchesInString(term_string, terms_map,
265 match.description, match.description_class); 258 match.description, match.description_class);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. 409 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
417 const double kMaxDecaySpeedDivisor = 5.0; 410 const double kMaxDecaySpeedDivisor = 5.0;
418 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 411 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
419 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 412 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
420 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 413 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
421 kNumUsesPerDecaySpeedDivisorIncrement); 414 kNumUsesPerDecaySpeedDivisorIncrement);
422 415
423 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 416 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
424 0.5); 417 0.5);
425 } 418 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698