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

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

Issue 476263002: Omnibox - Search Provider - Cleanup Keyword Mode's Legal Matches (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 115 }
116 116
117 // static 117 // static
118 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( 118 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
119 const base::string16& suggestion, 119 const base::string16& suggestion,
120 AutocompleteMatchType::Type type, 120 AutocompleteMatchType::Type type,
121 bool from_keyword_provider, 121 bool from_keyword_provider,
122 const TemplateURL* template_url, 122 const TemplateURL* template_url,
123 const SearchTermsData& search_terms_data) { 123 const SearchTermsData& search_terms_data) {
124 return CreateSearchSuggestion( 124 return CreateSearchSuggestion(
125 NULL, AutocompleteInput(), SearchSuggestionParser::SuggestResult( 125 NULL, AutocompleteInput(), from_keyword_provider,
msw 2014/08/15 18:32:00 You're passing |from_keyword_provider| as |in_keyw
Mark P 2014/08/15 18:47:07 I hoped the warning by this function's declaration
msw 2014/08/15 19:06:06 I saw the warning in the header, it's not bad, but
126 SearchSuggestionParser::SuggestResult(
126 suggestion, type, suggestion, base::string16(), base::string16(), 127 suggestion, type, suggestion, base::string16(), base::string16(),
127 base::string16(), base::string16(), std::string(), std::string(), 128 base::string16(), base::string16(), std::string(), std::string(),
128 from_keyword_provider, 0, false, false, base::string16()), 129 from_keyword_provider, 0, false, false, base::string16()),
129 template_url, search_terms_data, 0, false); 130 template_url, search_terms_data, 0, false);
130 } 131 }
131 132
132 void BaseSearchProvider::Stop(bool clear_cached_results) { 133 void BaseSearchProvider::Stop(bool clear_cached_results) {
133 StopSuggest(); 134 StopSuggest();
134 done_ = true; 135 done_ = true;
135 136
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey, 209 match->RecordAdditionalInfo(BaseSearchProvider::kDeletionUrlKey,
209 url.spec()); 210 url.spec());
210 match->deletable = true; 211 match->deletable = true;
211 } 212 }
212 } 213 }
213 214
214 // static 215 // static
215 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( 216 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion(
216 AutocompleteProvider* autocomplete_provider, 217 AutocompleteProvider* autocomplete_provider,
217 const AutocompleteInput& input, 218 const AutocompleteInput& input,
219 const bool in_keyword_mode,
218 const SearchSuggestionParser::SuggestResult& suggestion, 220 const SearchSuggestionParser::SuggestResult& suggestion,
219 const TemplateURL* template_url, 221 const TemplateURL* template_url,
220 const SearchTermsData& search_terms_data, 222 const SearchTermsData& search_terms_data,
221 int accepted_suggestion, 223 int accepted_suggestion,
222 bool append_extra_query_params) { 224 bool append_extra_query_params) {
223 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false, 225 AutocompleteMatch match(autocomplete_provider, suggestion.relevance(), false,
224 suggestion.type()); 226 suggestion.type());
225 227
226 if (!template_url) 228 if (!template_url)
227 return match; 229 return match;
(...skipping 12 matching lines...) Expand all
240 kACMatchPropertyContentsStartIndex, 242 kACMatchPropertyContentsStartIndex,
241 static_cast<int>( 243 static_cast<int>(
242 suggestion.suggestion().length() - match.contents.length())); 244 suggestion.suggestion().length() - match.contents.length()));
243 } 245 }
244 246
245 if (!suggestion.annotation().empty()) 247 if (!suggestion.annotation().empty())
246 match.description = suggestion.annotation(); 248 match.description = suggestion.annotation();
247 249
248 // suggestion.match_contents() should have already been collapsed. 250 // suggestion.match_contents() should have already been collapsed.
249 match.allowed_to_be_default_match = 251 match.allowed_to_be_default_match =
252 (!in_keyword_mode || suggestion.from_keyword_provider()) &&
250 (base::CollapseWhitespace(input.text(), false) == 253 (base::CollapseWhitespace(input.text(), false) ==
251 suggestion.match_contents()); 254 suggestion.match_contents());
252 255
253 // When the user forced a query, we need to make sure all the fill_into_edit 256 // When the user forced a query, we need to make sure all the fill_into_edit
254 // values preserve that property. Otherwise, if the user starts editing a 257 // values preserve that property. Otherwise, if the user starts editing a
255 // suggestion, non-Search results will suddenly appear. 258 // suggestion, non-Search results will suddenly appear.
256 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) 259 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY)
257 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); 260 match.fill_into_edit.assign(base::ASCIIToUTF16("?"));
258 if (suggestion.from_keyword_provider()) 261 if (suggestion.from_keyword_provider())
259 match.fill_into_edit.append(match.keyword + base::char16(' ')); 262 match.fill_into_edit.append(match.keyword + base::char16(' '));
260 if (!input.prevent_inline_autocomplete() && 263 if (!input.prevent_inline_autocomplete() &&
264 (!in_keyword_mode || suggestion.from_keyword_provider()) &&
261 StartsWith(suggestion.suggestion(), input.text(), false)) { 265 StartsWith(suggestion.suggestion(), input.text(), false)) {
262 match.inline_autocompletion = 266 match.inline_autocompletion =
263 suggestion.suggestion().substr(input.text().length()); 267 suggestion.suggestion().substr(input.text().length());
264 match.allowed_to_be_default_match = true; 268 match.allowed_to_be_default_match = true;
265 } 269 }
266 match.fill_into_edit.append(suggestion.suggestion()); 270 match.fill_into_edit.append(suggestion.suggestion());
267 271
268 const TemplateURLRef& search_url = template_url->url_ref(); 272 const TemplateURLRef& search_url = template_url->url_ref();
269 DCHECK(search_url.SupportsReplacement(search_terms_data)); 273 DCHECK(search_url.SupportsReplacement(search_terms_data));
270 match.search_terms_args.reset( 274 match.search_terms_args.reset(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 UpdateMatches(); 405 UpdateMatches();
402 if (done_ || results_updated) 406 if (done_ || results_updated)
403 listener_->OnProviderUpdate(results_updated); 407 listener_->OnProviderUpdate(results_updated);
404 } 408 }
405 409
406 void BaseSearchProvider::AddMatchToMap( 410 void BaseSearchProvider::AddMatchToMap(
407 const SearchSuggestionParser::SuggestResult& result, 411 const SearchSuggestionParser::SuggestResult& result,
408 const std::string& metadata, 412 const std::string& metadata,
409 int accepted_suggestion, 413 int accepted_suggestion,
410 bool mark_as_deletable, 414 bool mark_as_deletable,
415 bool in_keyword_mode,
411 MatchMap* map) { 416 MatchMap* map) {
412 AutocompleteMatch match = CreateSearchSuggestion( 417 AutocompleteMatch match = CreateSearchSuggestion(
413 this, GetInput(result.from_keyword_provider()), result, 418 this, GetInput(result.from_keyword_provider()), in_keyword_mode, result,
414 GetTemplateURL(result.from_keyword_provider()), 419 GetTemplateURL(result.from_keyword_provider()),
415 UIThreadSearchTermsData(profile_), accepted_suggestion, 420 UIThreadSearchTermsData(profile_), accepted_suggestion,
416 ShouldAppendExtraParams(result)); 421 ShouldAppendExtraParams(result));
417 if (!match.destination_url.is_valid()) 422 if (!match.destination_url.is_valid())
418 return; 423 return;
419 match.search_terms_args->bookmark_bar_pinned = 424 match.search_terms_args->bookmark_bar_pinned =
420 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 425 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
421 match.RecordAdditionalInfo(kRelevanceFromServerKey, 426 match.RecordAdditionalInfo(kRelevanceFromServerKey,
422 result.relevance_from_server() ? kTrue : kFalse); 427 result.relevance_from_server() ? kTrue : kFalse);
423 match.RecordAdditionalInfo(kShouldPrefetchKey, 428 match.RecordAdditionalInfo(kShouldPrefetchKey,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 541 }
537 542
538 void BaseSearchProvider::OnDeletionComplete( 543 void BaseSearchProvider::OnDeletionComplete(
539 bool success, SuggestionDeletionHandler* handler) { 544 bool success, SuggestionDeletionHandler* handler) {
540 RecordDeletionResult(success); 545 RecordDeletionResult(success);
541 SuggestionDeletionHandlers::iterator it = std::find( 546 SuggestionDeletionHandlers::iterator it = std::find(
542 deletion_handlers_.begin(), deletion_handlers_.end(), handler); 547 deletion_handlers_.begin(), deletion_handlers_.end(), handler);
543 DCHECK(it != deletion_handlers_.end()); 548 DCHECK(it != deletion_handlers_.end());
544 deletion_handlers_.erase(it); 549 deletion_handlers_.erase(it);
545 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698