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

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

Issue 6322001: Remove wstring from TemplateURL and friends.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 have_suggest_results_ = false; 410 have_suggest_results_ = false;
411 } 411 }
412 412
413 URLFetcher* SearchProvider::CreateSuggestFetcher(int id, 413 URLFetcher* SearchProvider::CreateSuggestFetcher(int id,
414 const TemplateURL& provider, 414 const TemplateURL& provider,
415 const std::wstring& text) { 415 const std::wstring& text) {
416 const TemplateURLRef* const suggestions_url = provider.suggestions_url(); 416 const TemplateURLRef* const suggestions_url = provider.suggestions_url();
417 DCHECK(suggestions_url->SupportsReplacement()); 417 DCHECK(suggestions_url->SupportsReplacement());
418 URLFetcher* fetcher = URLFetcher::Create(id, 418 URLFetcher* fetcher = URLFetcher::Create(id,
419 GURL(suggestions_url->ReplaceSearchTerms( 419 GURL(suggestions_url->ReplaceSearchTerms(
420 provider, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 420 provider, WideToUTF16Hack(text),
421 std::wstring())), 421 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())),
422 URLFetcher::GET, this); 422 URLFetcher::GET, this);
423 fetcher->set_request_context(profile_->GetRequestContext()); 423 fetcher->set_request_context(profile_->GetRequestContext());
424 fetcher->Start(); 424 fetcher->Start();
425 return fetcher; 425 return fetcher;
426 } 426 }
427 427
428 bool SearchProvider::ParseSuggestResults(Value* root_val, 428 bool SearchProvider::ParseSuggestResults(Value* root_val,
429 bool is_keyword, 429 bool is_keyword,
430 const std::wstring& input_text, 430 const std::wstring& input_text,
431 SuggestResults* suggest_results) { 431 SuggestResults* suggest_results) {
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 771
772 // When the user forced a query, we need to make sure all the fill_into_edit 772 // When the user forced a query, we need to make sure all the fill_into_edit
773 // values preserve that property. Otherwise, if the user starts editing a 773 // values preserve that property. Otherwise, if the user starts editing a
774 // suggestion, non-Search results will suddenly appear. 774 // suggestion, non-Search results will suddenly appear.
775 size_t search_start = 0; 775 size_t search_start = 0;
776 if (input_.type() == AutocompleteInput::FORCED_QUERY) { 776 if (input_.type() == AutocompleteInput::FORCED_QUERY) {
777 match.fill_into_edit.assign(L"?"); 777 match.fill_into_edit.assign(L"?");
778 ++search_start; 778 ++search_start;
779 } 779 }
780 if (is_keyword) { 780 if (is_keyword) {
781 match.fill_into_edit.append(providers_.keyword_provider().keyword() + L" "); 781 match.fill_into_edit.append(UTF16ToWideHack(
782 providers_.keyword_provider().keyword() + char16(' ')));
782 match.template_url = &providers_.keyword_provider(); 783 match.template_url = &providers_.keyword_provider();
783 } 784 }
784 match.fill_into_edit.append(query_string); 785 match.fill_into_edit.append(query_string);
785 // Not all suggestions start with the original input. 786 // Not all suggestions start with the original input.
786 if (!prevent_inline_autocomplete && 787 if (!prevent_inline_autocomplete &&
787 !match.fill_into_edit.compare(search_start, input_text.length(), 788 !match.fill_into_edit.compare(search_start, input_text.length(),
788 input_text)) 789 input_text))
789 match.inline_autocomplete_offset = search_start + input_text.length(); 790 match.inline_autocomplete_offset = search_start + input_text.length();
790 791
791 const TemplateURLRef* const search_url = provider.url(); 792 const TemplateURLRef* const search_url = provider.url();
792 DCHECK(search_url->SupportsReplacement()); 793 DCHECK(search_url->SupportsReplacement());
793 match.destination_url = 794 match.destination_url =
794 GURL(search_url->ReplaceSearchTerms(provider, 795 GURL(search_url->ReplaceSearchTerms(provider,
795 query_string, 796 WideToUTF16Hack(query_string),
796 accepted_suggestion, 797 accepted_suggestion,
797 input_text)); 798 WideToUTF16Hack(input_text)));
798 799
799 // Search results don't look like URLs. 800 // Search results don't look like URLs.
800 match.transition = 801 match.transition =
801 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED; 802 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED;
802 803
803 // Try to add |match| to |map|. If a match for |query_string| is already in 804 // Try to add |match| to |map|. If a match for |query_string| is already in
804 // |map|, replace it if |match| is more relevant. 805 // |map|, replace it if |match| is more relevant.
805 // NOTE: Keep this ToLower() call in sync with url_database.cc. 806 // NOTE: Keep this ToLower() call in sync with url_database.cc.
806 const std::pair<MatchMap::iterator, bool> i = map->insert( 807 const std::pair<MatchMap::iterator, bool> i = map->insert(
807 std::pair<std::wstring, AutocompleteMatch>( 808 std::pair<std::wstring, AutocompleteMatch>(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 866
866 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { 867 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) {
867 AutocompleteMatch& match = *i; 868 AutocompleteMatch& match = *i;
868 switch (match.type) { 869 switch (match.type) {
869 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: 870 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
870 case AutocompleteMatch::SEARCH_HISTORY: 871 case AutocompleteMatch::SEARCH_HISTORY:
871 case AutocompleteMatch::SEARCH_SUGGEST: 872 case AutocompleteMatch::SEARCH_SUGGEST:
872 match.description.assign( 873 match.description.assign(
873 UTF16ToWideHack(l10n_util::GetStringFUTF16( 874 UTF16ToWideHack(l10n_util::GetStringFUTF16(
874 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, 875 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION,
875 WideToUTF16Hack(providers_.default_provider(). 876 providers_.default_provider().
876 AdjustedShortNameForLocaleDirection())))); 877 AdjustedShortNameForLocaleDirection())));
877 match.description_class.push_back( 878 match.description_class.push_back(
878 ACMatchClassification(0, ACMatchClassification::DIM)); 879 ACMatchClassification(0, ACMatchClassification::DIM));
879 // Only the first search match gets a description. 880 // Only the first search match gets a description.
880 return; 881 return;
881 882
882 default: 883 default:
883 break; 884 break;
884 } 885 }
885 } 886 }
886 } 887 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/keyword_provider_unittest.cc ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698