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

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

Issue 471673002: Omnibox: Prevent Asynchronous Suggestions from Changing Default Match (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better resolve rebase Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/base_search_provider.h" 5 #include "chrome/browser/autocomplete/base_search_provider.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; 109 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue;
110 } 110 }
111 111
112 // static 112 // static
113 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( 113 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
114 const base::string16& suggestion, 114 const base::string16& suggestion,
115 AutocompleteMatchType::Type type, 115 AutocompleteMatchType::Type type,
116 bool from_keyword_provider, 116 bool from_keyword_provider,
117 const TemplateURL* template_url, 117 const TemplateURL* template_url,
118 const SearchTermsData& search_terms_data) { 118 const SearchTermsData& search_terms_data) {
119 // This call uses a number of default values. For instance, it assumes that
120 // if this match is from a keyword provider than the user is in keyword mode.
119 return CreateSearchSuggestion( 121 return CreateSearchSuggestion(
120 NULL, AutocompleteInput(), SearchSuggestionParser::SuggestResult( 122 NULL, AutocompleteInput(), from_keyword_provider,
123 SearchSuggestionParser::SuggestResult(
121 suggestion, type, suggestion, base::string16(), base::string16(), 124 suggestion, type, suggestion, base::string16(), base::string16(),
122 base::string16(), base::string16(), std::string(), std::string(), 125 base::string16(), base::string16(), std::string(), std::string(),
123 from_keyword_provider, 0, false, false, base::string16()), 126 from_keyword_provider, 0, false, false, base::string16()),
124 template_url, search_terms_data, 0, false); 127 template_url, search_terms_data, 0, false);
125 } 128 }
126 129
127 void BaseSearchProvider::Stop(bool clear_cached_results) { 130 void BaseSearchProvider::Stop(bool clear_cached_results) {
128 StopSuggest(); 131 StopSuggest();
129 done_ = true; 132 done_ = true;
130 133
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey, 204 match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey,
202 url.spec()); 205 url.spec());
203 match->deletable = true; 206 match->deletable = true;
204 } 207 }
205 } 208 }
206 209
207 // static 210 // static
208 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( 211 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
209 AutocompleteProvider* autocomplete_provider, 212 AutocompleteProvider* autocomplete_provider,
210 const AutocompleteInput& input, 213 const AutocompleteInput& input,
214 const bool in_keyword_mode,
211 const SearchSuggestionParser::SuggestResult& suggestion, 215 const SearchSuggestionParser::SuggestResult& suggestion,
212 const TemplateURL* template_url, 216 const TemplateURL* template_url,
213 const SearchTermsData& search_terms_data, 217 const SearchTermsData& search_terms_data,
214 int accepted_suggestion, 218 int accepted_suggestion,
215 bool append_extra_query_params) { 219 bool append_extra_query_params) {
216 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, 220 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false,
217 suggestion.type()); 221 suggestion.type());
218 222
219 if (!template_url) 223 if (!template_url)
220 return match; 224 return match;
(...skipping 12 matching lines...) Expand all
233 kACMatchPropertyContentsStartIndex, 237 kACMatchPropertyContentsStartIndex,
234 static_cast<int>( 238 static_cast<int>(
235 suggestion.suggestion().length() - match.contents.length())); 239 suggestion.suggestion().length() - match.contents.length()));
236 } 240 }
237 241
238 if (!suggestion.annotation().empty()) 242 if (!suggestion.annotation().empty())
239 match.description = suggestion.annotation(); 243 match.description = suggestion.annotation();
240 244
241 // suggestion.match_contents() should have already been collapsed. 245 // suggestion.match_contents() should have already been collapsed.
242 match.allowed_to_be_default_match = 246 match.allowed_to_be_default_match =
247 (!in_keyword_mode || suggestion.from_keyword_provider()) &&
243 (base::CollapseWhitespace(input.text(), false) == 248 (base::CollapseWhitespace(input.text(), false) ==
244 suggestion.match_contents()); 249 suggestion.match_contents());
245 250
246 // When the user forced a query, we need to make sure all the fill_into_edit 251 // When the user forced a query, we need to make sure all the fill_into_edit
247 // values preserve that property. Otherwise, if the user starts editing a 252 // values preserve that property. Otherwise, if the user starts editing a
248 // suggestion, non-Search results will suddenly appear. 253 // suggestion, non-Search results will suddenly appear.
249 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) 254 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY)
250 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); 255 match.fill_into_edit.assign(base::ASCIIToUTF16("?"));
251 if (suggestion.from_keyword_provider()) 256 if (suggestion.from_keyword_provider())
252 match.fill_into_edit.append(match.keyword + base::char16(' ')); 257 match.fill_into_edit.append(match.keyword + base::char16(' '));
253 if (!input.prevent_inline_autocomplete() && 258 // We only allow inlinable navsuggestions that were received before the
259 // last keystroke because we don't want asynchronous inline autocompletions.
260 if (!suggestion.received_after_last_keystroke() &&
261 !input.prevent_inline_autocomplete() &&
262 (!in_keyword_mode || suggestion.from_keyword_provider()) &&
254 StartsWith(suggestion.suggestion(), input.text(), false)) { 263 StartsWith(suggestion.suggestion(), input.text(), false)) {
255 match.inline_autocompletion = 264 match.inline_autocompletion =
256 suggestion.suggestion().substr(input.text().length()); 265 suggestion.suggestion().substr(input.text().length());
257 match.allowed_to_be_default_match = true; 266 match.allowed_to_be_default_match = true;
258 } 267 }
259 match.fill_into_edit.append(suggestion.suggestion()); 268 match.fill_into_edit.append(suggestion.suggestion());
260 269
261 const TemplateURLRef& search_url = template_url->url_ref(); 270 const TemplateURLRef& search_url = template_url->url_ref();
262 DCHECK(search_url.SupportsReplacement(search_terms_data)); 271 DCHECK(search_url.SupportsReplacement(search_terms_data));
263 match.search_terms_args.reset( 272 match.search_terms_args.reset(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return false; 372 return false;
364 373
365 return true; 374 return true;
366 } 375 }
367 376
368 void BaseSearchProvider::AddMatchToMap( 377 void BaseSearchProvider::AddMatchToMap(
369 const SearchSuggestionParser::SuggestResult& result, 378 const SearchSuggestionParser::SuggestResult& result,
370 const std::string& metadata, 379 const std::string& metadata,
371 int accepted_suggestion, 380 int accepted_suggestion,
372 bool mark_as_deletable, 381 bool mark_as_deletable,
382 bool in_keyword_mode,
373 MatchMap* map) { 383 MatchMap* map) {
374 AutocompleteMatch match = CreateSearchSuggestion( 384 AutocompleteMatch match = CreateSearchSuggestion(
375 this, GetInput(result.from_keyword_provider()), result, 385 this, GetInput(result.from_keyword_provider()), in_keyword_mode, result,
376 GetTemplateURL(result.from_keyword_provider()), 386 GetTemplateURL(result.from_keyword_provider()),
377 template_url_service_->search_terms_data(), accepted_suggestion, 387 template_url_service_->search_terms_data(), accepted_suggestion,
378 ShouldAppendExtraParams(result)); 388 ShouldAppendExtraParams(result));
379 if (!match.destination_url.is_valid()) 389 if (!match.destination_url.is_valid())
380 return; 390 return;
381 match.search_terms_args->bookmark_bar_pinned = 391 match.search_terms_args->bookmark_bar_pinned =
382 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 392 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
383 match.RecordAdditionalInfo(kRelevanceFromServerKey, 393 match.RecordAdditionalInfo(kRelevanceFromServerKey,
384 result.relevance_from_server() ? kTrue : kFalse); 394 result.relevance_from_server() ? kTrue : kFalse);
385 match.RecordAdditionalInfo(kShouldPrefetchKey, 395 match.RecordAdditionalInfo(kShouldPrefetchKey,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 497 }
488 498
489 void BaseSearchProvider::OnDeletionComplete( 499 void BaseSearchProvider::OnDeletionComplete(
490 bool success, SuggestionDeletionHandler* handler) { 500 bool success, SuggestionDeletionHandler* handler) {
491 RecordDeletionResult(success); 501 RecordDeletionResult(success);
492 SuggestionDeletionHandlers::iterator it = std::find( 502 SuggestionDeletionHandlers::iterator it = std::find(
493 deletion_handlers_.begin(), deletion_handlers_.end(), handler); 503 deletion_handlers_.begin(), deletion_handlers_.end(), handler);
494 DCHECK(it != deletion_handlers_.end()); 504 DCHECK(it != deletion_handlers_.end());
495 deletion_handlers_.erase(it); 505 deletion_handlers_.erase(it);
496 } 506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698