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

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

Issue 481693004: Omnibox: Prevent Asynchronous Suggestions from Changing Default Match (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix interactive test 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 119 // These calls use a number of default values. For instance, they assume
120 // if this match is from a keyword provider than the user is in keyword mode. 120 // that if this match is from a keyword provider, then the user is in keyword
121 // mode. They also assume the caller knows what it's doing and we set
122 // this match to look as if it was received/created synchronously.
123 SearchSuggestionParser::SuggestResult suggest_result(
124 suggestion, type, suggestion, base::string16(), base::string16(),
125 base::string16(), base::string16(), std::string(), std::string(),
126 from_keyword_provider, 0, false, false, base::string16());
127 suggest_result.set_received_after_last_keystroke(false);
121 return CreateSearchSuggestion( 128 return CreateSearchSuggestion(
122 NULL, AutocompleteInput(), from_keyword_provider, 129 NULL, AutocompleteInput(), from_keyword_provider, suggest_result,
123 SearchSuggestionParser::SuggestResult(
124 suggestion, type, suggestion, base::string16(), base::string16(),
125 base::string16(), base::string16(), std::string(), std::string(),
126 from_keyword_provider, 0, false, false, base::string16()),
127 template_url, search_terms_data, 0, false); 130 template_url, search_terms_data, 0, false);
128 } 131 }
129 132
130 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { 133 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) {
131 DCHECK(match.deletable); 134 DCHECK(match.deletable);
132 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { 135 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) {
133 deletion_handlers_.push_back(new SuggestionDeletionHandler( 136 deletion_handlers_.push_back(new SuggestionDeletionHandler(
134 match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey), 137 match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey),
135 profile_, 138 profile_,
136 base::Bind(&BaseSearchProvider::OnDeletionComplete, 139 base::Bind(&BaseSearchProvider::OnDeletionComplete,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 (base::CollapseWhitespace(input.text(), false) == 242 (base::CollapseWhitespace(input.text(), false) ==
240 suggestion.match_contents()); 243 suggestion.match_contents());
241 244
242 // When the user forced a query, we need to make sure all the fill_into_edit 245 // When the user forced a query, we need to make sure all the fill_into_edit
243 // values preserve that property. Otherwise, if the user starts editing a 246 // values preserve that property. Otherwise, if the user starts editing a
244 // suggestion, non-Search results will suddenly appear. 247 // suggestion, non-Search results will suddenly appear.
245 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) 248 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY)
246 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); 249 match.fill_into_edit.assign(base::ASCIIToUTF16("?"));
247 if (suggestion.from_keyword_provider()) 250 if (suggestion.from_keyword_provider())
248 match.fill_into_edit.append(match.keyword + base::char16(' ')); 251 match.fill_into_edit.append(match.keyword + base::char16(' '));
252 // We only allow inlinable navsuggestions that were received before the
253 // last keystroke because we don't want asynchronous inline autocompletions.
249 if (!input.prevent_inline_autocomplete() && 254 if (!input.prevent_inline_autocomplete() &&
255 !suggestion.received_after_last_keystroke() &&
250 (!in_keyword_mode || suggestion.from_keyword_provider()) && 256 (!in_keyword_mode || suggestion.from_keyword_provider()) &&
251 StartsWith(suggestion.suggestion(), input.text(), false)) { 257 StartsWith(suggestion.suggestion(), input.text(), false)) {
252 match.inline_autocompletion = 258 match.inline_autocompletion =
253 suggestion.suggestion().substr(input.text().length()); 259 suggestion.suggestion().substr(input.text().length());
254 match.allowed_to_be_default_match = true; 260 match.allowed_to_be_default_match = true;
255 } 261 }
256 match.fill_into_edit.append(suggestion.suggestion()); 262 match.fill_into_edit.append(suggestion.suggestion());
257 263
258 const TemplateURLRef& search_url = template_url->url_ref(); 264 const TemplateURLRef& search_url = template_url->url_ref();
259 DCHECK(search_url.SupportsReplacement(search_terms_data)); 265 DCHECK(search_url.SupportsReplacement(search_terms_data));
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 487 }
482 488
483 void BaseSearchProvider::OnDeletionComplete( 489 void BaseSearchProvider::OnDeletionComplete(
484 bool success, SuggestionDeletionHandler* handler) { 490 bool success, SuggestionDeletionHandler* handler) {
485 RecordDeletionResult(success); 491 RecordDeletionResult(success);
486 SuggestionDeletionHandlers::iterator it = std::find( 492 SuggestionDeletionHandlers::iterator it = std::find(
487 deletion_handlers_.begin(), deletion_handlers_.end(), handler); 493 deletion_handlers_.begin(), deletion_handlers_.end(), handler);
488 DCHECK(it != deletion_handlers_.end()); 494 DCHECK(it != deletion_handlers_.end());
489 deletion_handlers_.erase(it); 495 deletion_handlers_.erase(it);
490 } 496 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/search_provider.h » ('j') | chrome/browser/autocomplete/search_provider_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698