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

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

Issue 109013006: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/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 "base/callback.h" 10 #include "base/callback.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 420
421 if (!annotation.empty()) 421 if (!annotation.empty())
422 match.description = annotation; 422 match.description = annotation;
423 423
424 match.allowed_to_be_default_match = (input_text == match_contents); 424 match.allowed_to_be_default_match = (input_text == match_contents);
425 425
426 // When the user forced a query, we need to make sure all the fill_into_edit 426 // When the user forced a query, we need to make sure all the fill_into_edit
427 // values preserve that property. Otherwise, if the user starts editing a 427 // values preserve that property. Otherwise, if the user starts editing a
428 // suggestion, non-Search results will suddenly appear. 428 // suggestion, non-Search results will suddenly appear.
429 if (input.type() == AutocompleteInput::FORCED_QUERY) 429 if (input.type() == AutocompleteInput::FORCED_QUERY)
430 match.fill_into_edit.assign(ASCIIToUTF16("?")); 430 match.fill_into_edit.assign(base::ASCIIToUTF16("?"));
431 if (is_keyword) 431 if (is_keyword)
432 match.fill_into_edit.append(match.keyword + char16(' ')); 432 match.fill_into_edit.append(match.keyword + char16(' '));
433 if (!input.prevent_inline_autocomplete() && 433 if (!input.prevent_inline_autocomplete() &&
434 StartsWith(query_string, input_text, false)) { 434 StartsWith(query_string, input_text, false)) {
435 match.inline_autocompletion = query_string.substr(input_text.length()); 435 match.inline_autocompletion = query_string.substr(input_text.length());
436 match.allowed_to_be_default_match = true; 436 match.allowed_to_be_default_match = true;
437 } 437 }
438 match.fill_into_edit.append(query_string); 438 match.fill_into_edit.append(query_string);
439 439
440 const TemplateURLRef& search_url = template_url->url_ref(); 440 const TemplateURLRef& search_url = template_url->url_ref();
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 // JSON files in non-UTF-8 encodings. The actual encoding is usually 719 // JSON files in non-UTF-8 encodings. The actual encoding is usually
720 // specified in the Content-Type header field. 720 // specified in the Content-Type header field.
721 if (response_headers) { 721 if (response_headers) {
722 std::string charset; 722 std::string charset;
723 if (response_headers->GetCharset(&charset)) { 723 if (response_headers->GetCharset(&charset)) {
724 base::string16 data_16; 724 base::string16 data_16;
725 // TODO(jungshik): Switch to CodePageToUTF8 after it's added. 725 // TODO(jungshik): Switch to CodePageToUTF8 after it's added.
726 if (base::CodepageToUTF16(json_data, charset.c_str(), 726 if (base::CodepageToUTF16(json_data, charset.c_str(),
727 base::OnStringConversionError::FAIL, 727 base::OnStringConversionError::FAIL,
728 &data_16)) 728 &data_16))
729 json_data = UTF16ToUTF8(data_16); 729 json_data = base::UTF16ToUTF8(data_16);
730 } 730 }
731 } 731 }
732 732
733 scoped_ptr<base::Value> data(DeserializeJsonData(json_data)); 733 scoped_ptr<base::Value> data(DeserializeJsonData(json_data));
734 results_updated = data.get() && ParseSuggestResults(data.get(), is_keyword); 734 results_updated = data.get() && ParseSuggestResults(data.get(), is_keyword);
735 } 735 }
736 736
737 UpdateMatches(); 737 UpdateMatches();
738 if (done_ || results_updated) 738 if (done_ || results_updated)
739 listener_->OnProviderUpdate(results_updated); 739 listener_->OnProviderUpdate(results_updated);
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 // Google search may return empty suggestions for weird input characters, 1166 // Google search may return empty suggestions for weird input characters,
1167 // they make no sense at all and can cause problems in our code. 1167 // they make no sense at all and can cause problems in our code.
1168 if (suggestion.empty()) 1168 if (suggestion.empty())
1169 continue; 1169 continue;
1170 1170
1171 // Apply valid suggested relevance scores; discard invalid lists. 1171 // Apply valid suggested relevance scores; discard invalid lists.
1172 if (relevances != NULL && !relevances->GetInteger(index, &relevance)) 1172 if (relevances != NULL && !relevances->GetInteger(index, &relevance))
1173 relevances = NULL; 1173 relevances = NULL;
1174 if (types && types->GetString(index, &type) && (type == "NAVIGATION")) { 1174 if (types && types->GetString(index, &type) && (type == "NAVIGATION")) {
1175 // Do not blindly trust the URL coming from the server to be valid. 1175 // Do not blindly trust the URL coming from the server to be valid.
1176 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion), std::string())); 1176 GURL url(URLFixerUpper::FixupURL(
1177 base::UTF16ToUTF8(suggestion), std::string()));
1177 if (url.is_valid() && allow_navsuggest) { 1178 if (url.is_valid() && allow_navsuggest) {
1178 base::string16 title; 1179 base::string16 title;
1179 if (descriptions != NULL) 1180 if (descriptions != NULL)
1180 descriptions->GetString(index, &title); 1181 descriptions->GetString(index, &title);
1181 results->navigation_results.push_back(NavigationResult( 1182 results->navigation_results.push_back(NavigationResult(
1182 *this, url, title, is_keyword, relevance, true)); 1183 *this, url, title, is_keyword, relevance, true));
1183 } 1184 }
1184 } else { 1185 } else {
1185 AutocompleteMatchType::Type match_type = GetAutocompleteMatchType(type); 1186 AutocompleteMatchType::Type match_type = GetAutocompleteMatchType(type);
1186 bool should_prefetch = static_cast<int>(index) == prefetch_index; 1187 bool should_prefetch = static_cast<int>(index) == prefetch_index;
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 const net::FormatUrlTypes format_types = 1889 const net::FormatUrlTypes format_types =
1889 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP); 1890 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP);
1890 match.fill_into_edit += 1891 match.fill_into_edit +=
1891 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(), 1892 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(),
1892 net::FormatUrl(navigation.url(), languages, format_types, 1893 net::FormatUrl(navigation.url(), languages, format_types,
1893 net::UnescapeRule::SPACES, NULL, NULL, 1894 net::UnescapeRule::SPACES, NULL, NULL,
1894 &inline_autocomplete_offset)); 1895 &inline_autocomplete_offset));
1895 // Preserve the forced query '?' prefix in |match.fill_into_edit|. 1896 // Preserve the forced query '?' prefix in |match.fill_into_edit|.
1896 // Otherwise, user edits to a suggestion would show non-Search results. 1897 // Otherwise, user edits to a suggestion would show non-Search results.
1897 if (input_.type() == AutocompleteInput::FORCED_QUERY) { 1898 if (input_.type() == AutocompleteInput::FORCED_QUERY) {
1898 match.fill_into_edit.insert(0, ASCIIToUTF16("?")); 1899 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?"));
1899 if (inline_autocomplete_offset != base::string16::npos) 1900 if (inline_autocomplete_offset != base::string16::npos)
1900 ++inline_autocomplete_offset; 1901 ++inline_autocomplete_offset;
1901 } 1902 }
1902 if (!input_.prevent_inline_autocomplete() && 1903 if (!input_.prevent_inline_autocomplete() &&
1903 (inline_autocomplete_offset != base::string16::npos)) { 1904 (inline_autocomplete_offset != base::string16::npos)) {
1904 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); 1905 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length());
1905 // A navsuggestion can only be the default match when there is no 1906 // A navsuggestion can only be the default match when there is no
1906 // keyword provider active, lest it appear first and break the user 1907 // keyword provider active, lest it appear first and break the user
1907 // out of keyword mode. 1908 // out of keyword mode.
1908 match.allowed_to_be_default_match = 1909 match.allowed_to_be_default_match =
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() || 2038 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial() ||
2038 service == NULL || 2039 service == NULL ||
2039 !service->IsSyncEnabledAndLoggedIn() || 2040 !service->IsSyncEnabledAndLoggedIn() ||
2040 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has( 2041 !sync_prefs.GetPreferredDataTypes(syncer::UserTypes()).Has(
2041 syncer::PROXY_TABS) || 2042 syncer::PROXY_TABS) ||
2042 service->GetEncryptedDataTypes().Has(syncer::SESSIONS)) 2043 service->GetEncryptedDataTypes().Has(syncer::SESSIONS))
2043 return false; 2044 return false;
2044 2045
2045 return true; 2046 return true;
2046 } 2047 }
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