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

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

Issue 58003005: Modify Entity Suggestion support and Add Profile Suggest support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
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/zero_suggest_provider.h" 5 #include "chrome/browser/autocomplete/zero_suggest_provider.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Do not blindly trust the URL coming from the server to be valid. 309 // Do not blindly trust the URL coming from the server to be valid.
310 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(result), std::string())); 310 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(result), std::string()));
311 if (url.is_valid()) { 311 if (url.is_valid()) {
312 if (descriptions != NULL) 312 if (descriptions != NULL)
313 descriptions->GetString(index, &title); 313 descriptions->GetString(index, &title);
314 navigation_results->push_back(SearchProvider::NavigationResult( 314 navigation_results->push_back(SearchProvider::NavigationResult(
315 *this, url, title, false, relevance, relevances != NULL)); 315 *this, url, title, false, relevance, relevances != NULL));
316 } 316 }
317 } else { 317 } else {
318 suggest_results->push_back(SearchProvider::SuggestResult( 318 suggest_results->push_back(SearchProvider::SuggestResult(
319 result, result, string16(), std::string(), false, relevance, 319 result, AutocompleteMatchType::SEARCH_SUGGEST, result,
320 relevances != NULL, false)); 320 ACMatchClassifications(), string16(), ACMatchClassifications(),
321 std::string(), false, relevance, relevances != NULL, false));
321 } 322 }
322 } 323 }
323 } 324 }
324 325
325 void ZeroSuggestProvider::AddSuggestResultsToMap( 326 void ZeroSuggestProvider::AddSuggestResultsToMap(
326 const SearchProvider::SuggestResults& results, 327 const SearchProvider::SuggestResults& results,
327 const TemplateURL* template_url, 328 const TemplateURL* template_url,
328 SearchProvider::MatchMap* map) { 329 SearchProvider::MatchMap* map) {
329 for (size_t i = 0; i < results.size(); ++i) { 330 for (size_t i = 0; i < results.size(); ++i) {
330 AddMatchToMap(results[i].relevance(), AutocompleteMatchType::SEARCH_SUGGEST, 331 AddMatchToMap(results[i].relevance(), AutocompleteMatchType::SEARCH_SUGGEST,
331 template_url, results[i].suggestion(), i, map); 332 template_url, results[i].suggestion(), i, map);
332 } 333 }
333 } 334 }
334 335
335 void ZeroSuggestProvider::AddMatchToMap(int relevance, 336 void ZeroSuggestProvider::AddMatchToMap(int relevance,
336 AutocompleteMatch::Type type, 337 AutocompleteMatch::Type type,
337 const TemplateURL* template_url, 338 const TemplateURL* template_url,
338 const string16& query_string, 339 const string16& query_string,
339 int accepted_suggestion, 340 int accepted_suggestion,
340 SearchProvider::MatchMap* map) { 341 SearchProvider::MatchMap* map) {
341 // Pass in query_string as the input_text since we don't want any bolding. 342 // Pass in query_string as the input_text since we don't want any bolding.
342 // TODO(samarth|melevin): use the actual omnibox margin here as well instead 343 // TODO(samarth|melevin): use the actual omnibox margin here as well instead
343 // of passing in -1. 344 // of passing in -1.
344 AutocompleteMatch match = SearchProvider::CreateSearchSuggestion( 345 AutocompleteMatch match = SearchProvider::CreateSearchSuggestion(
345 this, AutocompleteInput(), query_string, relevance, type, false, 346 this, AutocompleteInput(), query_string, relevance, type, false,
346 query_string, string16(), template_url, query_string, std::string(), 347 query_string, ACMatchClassifications(), string16(),
348 ACMatchClassifications(), template_url, query_string, std::string(),
347 accepted_suggestion, -1, true); 349 accepted_suggestion, -1, true);
348 if (!match.destination_url.is_valid()) 350 if (!match.destination_url.is_valid())
349 return; 351 return;
350 352
351 // Try to add |match| to |map|. If a match for |query_string| is already in 353 // Try to add |match| to |map|. If a match for |query_string| is already in
352 // |map|, replace it if |match| is more relevant. 354 // |map|, replace it if |match| is more relevant.
353 // NOTE: Keep this ToLower() call in sync with url_database.cc. 355 // NOTE: Keep this ToLower() call in sync with url_database.cc.
354 SearchProvider::MatchKey match_key( 356 SearchProvider::MatchKey match_key(
355 std::make_pair(base::i18n::ToLower(query_string), std::string())); 357 std::make_pair(base::i18n::ToLower(query_string), std::string()));
356 const std::pair<SearchProvider::MatchMap::iterator, bool> i(map->insert( 358 const std::pair<SearchProvider::MatchMap::iterator, bool> i(map->insert(
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 match.is_history_what_you_typed_match = false; 528 match.is_history_what_you_typed_match = false;
527 match.allowed_to_be_default_match = true; 529 match.allowed_to_be_default_match = true;
528 530
529 // The placeholder suggestion for the current URL has high relevance so 531 // The placeholder suggestion for the current URL has high relevance so
530 // that it is in the first suggestion slot and inline autocompleted. It 532 // that it is in the first suggestion slot and inline autocompleted. It
531 // gets dropped as soon as the user types something. 533 // gets dropped as soon as the user types something.
532 match.relevance = verbatim_relevance_; 534 match.relevance = verbatim_relevance_;
533 535
534 return match; 536 return match;
535 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698