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

Unified Diff: chrome/browser/autocomplete/search_provider.cc

Issue 6306011: Remove wstring from autocomplete. (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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/search_provider.cc
===================================================================
--- chrome/browser/autocomplete/search_provider.cc (revision 72388)
+++ chrome/browser/autocomplete/search_provider.cc (working copy)
@@ -63,8 +63,8 @@
instant_finalized_(false) {
}
-void SearchProvider::FinalizeInstantQuery(const std::wstring& input_text,
- const std::wstring& suggest_text) {
+void SearchProvider::FinalizeInstantQuery(const string16& input_text,
+ const string16& suggest_text) {
if (done_ || instant_finalized_)
return;
@@ -80,11 +80,11 @@
default_provider_suggest_text_ = suggest_text;
- std::wstring adjusted_input_text(input_text);
+ string16 adjusted_input_text(input_text);
AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(),
&adjusted_input_text);
- const std::wstring text = adjusted_input_text + suggest_text;
+ const string16 text = adjusted_input_text + suggest_text;
// Remove any matches that are identical to |text|. We don't use the
// destination_url for comparison as it varies depending upon the index passed
// to TemplateURL::ReplaceSearchTerms.
@@ -180,8 +180,7 @@
if (default_provider) {
AutocompleteMatch match;
match.provider = this;
- match.contents.assign(UTF16ToWideHack(
- l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)));
+ match.contents.assign(l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE));
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
matches_.push_back(match);
@@ -244,12 +243,12 @@
if (response_headers) {
std::string charset;
if (response_headers->GetCharset(&charset)) {
- std::wstring wide_data;
+ string16 data_16;
// TODO(jungshik): Switch to CodePageToUTF8 after it's added.
- if (base::CodepageToWide(data, charset.c_str(),
- base::OnStringConversionError::FAIL,
- &wide_data))
- json_data = WideToUTF8(wide_data);
+ if (base::CodepageToUTF16(data, charset.c_str(),
+ base::OnStringConversionError::FAIL,
+ &data_16))
+ json_data = UTF16ToUTF8(data_16);
}
}
@@ -261,7 +260,7 @@
JSONStringValueSerializer deserializer(json_data);
deserializer.set_allow_trailing_comma(true);
scoped_ptr<Value> root_val(deserializer.Deserialize(NULL, NULL));
- const std::wstring& input_text =
+ const string16& input_text =
is_keyword_results ? keyword_input_text_ : input_.text();
have_suggest_results_ =
root_val.get() &&
@@ -296,14 +295,14 @@
if (providers_.valid_keyword_provider()) {
url_db->GetMostRecentKeywordSearchTerms(
providers_.keyword_provider().id(),
- WideToUTF16(keyword_input_text_),
+ keyword_input_text_,
static_cast<int>(kMaxMatches),
&keyword_history_results_);
}
if (providers_.valid_default_provider()) {
url_db->GetMostRecentKeywordSearchTerms(
providers_.default_provider().id(),
- WideToUTF16(input_.text()),
+ input_.text(),
static_cast<int>(kMaxMatches),
&default_history_results_);
}
@@ -373,8 +372,9 @@
// probably a URL that's being entered and happens to currently be invalid --
// in which case we again want to run our checks below. Other QUERY cases are
// less likely to be URLs and thus we assume we're OK.
- if ((input_.scheme() != L"http") && (input_.scheme() != L"https") &&
- (input_.scheme() != L"ftp"))
+ if (!LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpScheme) &&
+ !LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) &&
+ !LowerCaseEqualsASCII(input_.scheme(), chrome::kFtpScheme))
return (input_.type() == AutocompleteInput::QUERY);
// Don't send URLs with usernames, queries or refs. Some of these are
@@ -391,7 +391,8 @@
// Don't send anything for https except the hostname. Hostnames are OK
// because they are visible when the TCP connection is established, but the
// specific path may reveal private information.
- if ((input_.scheme() == L"https") && parts.path.is_nonempty())
+ if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) &&
+ parts.path.is_nonempty())
return false;
return true;
@@ -412,12 +413,12 @@
URLFetcher* SearchProvider::CreateSuggestFetcher(int id,
const TemplateURL& provider,
- const std::wstring& text) {
+ const string16& text) {
const TemplateURLRef* const suggestions_url = provider.suggestions_url();
DCHECK(suggestions_url->SupportsReplacement());
URLFetcher* fetcher = URLFetcher::Create(id,
GURL(suggestions_url->ReplaceSearchTerms(
- provider, WideToUTF16Hack(text),
+ provider, text,
TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())),
URLFetcher::GET, this);
fetcher->set_request_context(profile_->GetRequestContext());
@@ -427,7 +428,7 @@
bool SearchProvider::ParseSuggestResults(Value* root_val,
bool is_keyword,
- const std::wstring& input_text,
+ const string16& input_text,
SuggestResults* suggest_results) {
if (!root_val->IsType(Value::TYPE_LIST))
return false;
@@ -438,7 +439,7 @@
Value* result_val;
if ((root_list->GetSize() < 2) || !root_list->Get(0, &query_val) ||
!query_val->GetAsString(&query_str) ||
- (query_str != WideToUTF16Hack(input_text)) ||
+ (query_str != input_text) ||
!root_list->Get(1, &result_val) || !result_val->IsType(Value::TYPE_LIST))
return false;
@@ -503,15 +504,14 @@
GURL result_url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion_str),
std::string()));
if (result_url.is_valid()) {
- navigation_results.push_back(NavigationResult(result_url,
- UTF16ToWideHack(site_name)));
+ navigation_results.push_back(NavigationResult(result_url, site_name));
}
}
} else {
// TODO(kochi): Currently we treat a calculator result as a query, but it
// is better to have better presentation for caluculator results.
if (suggest_results->size() < kMaxMatches)
- suggest_results->push_back(UTF16ToWideHack(suggestion_str));
+ suggest_results->push_back(suggestion_str);
}
}
@@ -612,7 +612,7 @@
if (i != results.begin() && relevance >= last_relevance)
relevance = last_relevance - 1;
last_relevance = relevance;
- AddMatchToMap(UTF16ToWide(i->term),
+ AddMatchToMap(i->term,
is_keyword ? keyword_input_text_ : input_.text(),
relevance,
AutocompleteMatch::SEARCH_HISTORY, did_not_accept_suggestion,
@@ -717,8 +717,8 @@
static_cast<int>(num_results - 1 - result_number);
}
-void SearchProvider::AddMatchToMap(const std::wstring& query_string,
- const std::wstring& input_text,
+void SearchProvider::AddMatchToMap(const string16& query_string,
+ const string16& input_text,
int relevance,
AutocompleteMatch::Type type,
int accepted_suggestion,
@@ -735,7 +735,7 @@
// "youtube", so we'll bold the "tube" section: you*tube*.
if (input_text != query_string) {
size_t input_position = match.contents.find(input_text);
- if (input_position == std::wstring::npos) {
+ if (input_position == string16::npos) {
// The input text is not a substring of the query string, e.g. input
// text is "slasdot" and the query string is "slashdot", so we bold the
// whole thing.
@@ -774,12 +774,12 @@
// suggestion, non-Search results will suddenly appear.
size_t search_start = 0;
if (input_.type() == AutocompleteInput::FORCED_QUERY) {
- match.fill_into_edit.assign(L"?");
+ match.fill_into_edit.assign(ASCIIToUTF16("?"));
++search_start;
}
if (is_keyword) {
- match.fill_into_edit.append(UTF16ToWideHack(
- providers_.keyword_provider().keyword() + char16(' ')));
+ match.fill_into_edit.append(
+ providers_.keyword_provider().keyword() + char16(' '));
match.template_url = &providers_.keyword_provider();
}
match.fill_into_edit.append(query_string);
@@ -793,9 +793,9 @@
DCHECK(search_url->SupportsReplacement());
match.destination_url =
GURL(search_url->ReplaceSearchTerms(provider,
- WideToUTF16Hack(query_string),
+ query_string,
accepted_suggestion,
- WideToUTF16Hack(input_text)));
+ input_text));
// Search results don't look like URLs.
match.transition =
@@ -805,8 +805,8 @@
// |map|, replace it if |match| is more relevant.
// NOTE: Keep this ToLower() call in sync with url_database.cc.
const std::pair<MatchMap::iterator, bool> i = map->insert(
- std::pair<std::wstring, AutocompleteMatch>(
- UTF16ToWide(l10n_util::ToLower(WideToUTF16(query_string))), match));
+ std::pair<string16, AutocompleteMatch>(
+ l10n_util::ToLower(query_string), match));
// NOTE: We purposefully do a direct relevance comparison here instead of
// using AutocompleteMatch::MoreRelevant(), so that we'll prefer "items added
// first" rather than "items alphabetically first" when the scores are equal.
@@ -823,7 +823,7 @@
const NavigationResult& navigation,
int relevance,
bool is_keyword) {
- const std::wstring& input_text =
+ const string16& input_text =
is_keyword ? keyword_input_text_ : input_.text();
AutocompleteMatch match(this, relevance, false,
AutocompleteMatch::NAVSUGGEST);
@@ -843,7 +843,7 @@
// values preserve that property. Otherwise, if the user starts editing a
// suggestion, non-Search results will suddenly appear.
if (input_.type() == AutocompleteInput::FORCED_QUERY)
- match.fill_into_edit.assign(L"?");
+ match.fill_into_edit.assign(ASCIIToUTF16("?"));
match.fill_into_edit.append(
AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url,
match.contents));
@@ -870,11 +870,10 @@
case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
case AutocompleteMatch::SEARCH_HISTORY:
case AutocompleteMatch::SEARCH_SUGGEST:
- match.description.assign(
- UTF16ToWideHack(l10n_util::GetStringFUTF16(
- IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION,
- providers_.default_provider().
- AdjustedShortNameForLocaleDirection())));
+ match.description.assign(l10n_util::GetStringFUTF16(
+ IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION,
+ providers_.default_provider().
+ AdjustedShortNameForLocaleDirection()));
match.description_class.push_back(
ACMatchClassification(0, ACMatchClassification::DIM));
// Only the first search match gets a description.

Powered by Google App Engine
This is Rietveld 408576698