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

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

Issue 54203008: Store xsrf token received with psuggest results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added test case 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 | 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/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, result, string16(), std::string(), std::string(), false,
320 relevances != NULL, false)); 320 relevance, relevances != NULL, false));
321 } 321 }
322 } 322 }
323 } 323 }
324 324
325 void ZeroSuggestProvider::AddSuggestResultsToMap( 325 void ZeroSuggestProvider::AddSuggestResultsToMap(
326 const SearchProvider::SuggestResults& results, 326 const SearchProvider::SuggestResults& results,
327 const TemplateURL* template_url, 327 const TemplateURL* template_url,
328 SearchProvider::MatchMap* map) { 328 SearchProvider::MatchMap* map) {
329 for (size_t i = 0; i < results.size(); ++i) { 329 for (size_t i = 0; i < results.size(); ++i) {
330 AddMatchToMap(results[i].relevance(), AutocompleteMatchType::SEARCH_SUGGEST, 330 AddMatchToMap(results[i].relevance(), AutocompleteMatchType::SEARCH_SUGGEST,
331 template_url, results[i].suggestion(), i, map); 331 template_url, results[i].suggestion(), i, map);
332 } 332 }
333 } 333 }
334 334
335 void ZeroSuggestProvider::AddMatchToMap(int relevance, 335 void ZeroSuggestProvider::AddMatchToMap(int relevance,
336 AutocompleteMatch::Type type, 336 AutocompleteMatch::Type type,
337 const TemplateURL* template_url, 337 const TemplateURL* template_url,
338 const string16& query_string, 338 const string16& query_string,
339 int accepted_suggestion, 339 int accepted_suggestion,
340 SearchProvider::MatchMap* map) { 340 SearchProvider::MatchMap* map) {
341 // Pass in query_string as the input_text since we don't want any bolding. 341 // 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 342 // TODO(samarth|melevin): use the actual omnibox margin here as well instead
343 // of passing in -1. 343 // of passing in -1.
344 AutocompleteMatch match = SearchProvider::CreateSearchSuggestion( 344 AutocompleteMatch match = SearchProvider::CreateSearchSuggestion(
345 this, AutocompleteInput(), query_string, relevance, type, false, 345 this, AutocompleteInput(), query_string, relevance, type, false,
346 query_string, string16(), template_url, query_string, std::string(), 346 query_string, string16(), template_url, query_string, std::string(),
347 accepted_suggestion, -1, true); 347 std::string(), accepted_suggestion, -1, true);
348 if (!match.destination_url.is_valid()) 348 if (!match.destination_url.is_valid())
349 return; 349 return;
350 350
351 // Try to add |match| to |map|. If a match for |query_string| is already in 351 // Try to add |match| to |map|. If a match for |query_string| is already in
352 // |map|, replace it if |match| is more relevant. 352 // |map|, replace it if |match| is more relevant.
353 // NOTE: Keep this ToLower() call in sync with url_database.cc. 353 // NOTE: Keep this ToLower() call in sync with url_database.cc.
354 SearchProvider::MatchKey match_key( 354 SearchProvider::MatchKey match_key(
355 std::make_pair(base::i18n::ToLower(query_string), std::string())); 355 std::make_pair(base::i18n::ToLower(query_string), std::string()));
356 const std::pair<SearchProvider::MatchMap::iterator, bool> i(map->insert( 356 const std::pair<SearchProvider::MatchMap::iterator, bool> i(map->insert(
357 std::make_pair(match_key, match))); 357 std::make_pair(match_key, match)));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 match.is_history_what_you_typed_match = false; 526 match.is_history_what_you_typed_match = false;
527 match.allowed_to_be_default_match = true; 527 match.allowed_to_be_default_match = true;
528 528
529 // The placeholder suggestion for the current URL has high relevance so 529 // The placeholder suggestion for the current URL has high relevance so
530 // that it is in the first suggestion slot and inline autocompleted. It 530 // that it is in the first suggestion slot and inline autocompleted. It
531 // gets dropped as soon as the user types something. 531 // gets dropped as soon as the user types something.
532 match.relevance = verbatim_relevance_; 532 match.relevance = verbatim_relevance_;
533 533
534 return match; 534 return match;
535 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698