summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-30 08:16:10 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-30 08:16:10 +0000
commitef92dbefb269e1ca548ccb7a7fecb1d69c3a87fe (patch)
tree092af8f9dd66777c0b34975cf999d54b37d6279e /chrome/browser
parentc8884db174f04db3f766da5d3caadbd2432c6f84 (diff)
downloadchromium_src-ef92dbefb269e1ca548ccb7a7fecb1d69c3a87fe.zip
chromium_src-ef92dbefb269e1ca548ccb7a7fecb1d69c3a87fe.tar.gz
chromium_src-ef92dbefb269e1ca548ccb7a7fecb1d69c3a87fe.tar.bz2
Make various string_util functions take StringPieces instead of char[].
This allows most callers to pass string literals or results of ASCIIToUTF16(), rather than construct error-prone character arrays that must be manually nul-terminated. Also cleans up various bits of the callers. BUG=104260 TEST=none Review URL: https://codereview.chromium.org/296593003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/autocomplete_input.cc2
-rw-r--r--chrome/browser/autocomplete/builtin_provider.cc3
-rw-r--r--chrome/browser/chromeos/drive/file_system_util.cc28
-rw-r--r--chrome/browser/drive/drive_api_util.cc3
-rw-r--r--chrome/browser/errorpage_browsertest.cc5
-rw-r--r--chrome/browser/guest_view/ad_view/ad_view_guest.cc5
-rw-r--r--chrome/browser/guest_view/web_view/web_view_guest.cc11
-rw-r--r--chrome/browser/profile_resetter/resettable_settings_snapshot.cc2
-rw-r--r--chrome/browser/renderer_context_menu/render_view_context_menu.cc4
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.cc3
-rw-r--r--chrome/browser/ui/omnibox/location_bar_util.cc15
11 files changed, 33 insertions, 48 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_input.cc b/chrome/browser/autocomplete/autocomplete_input.cc
index af34933..f85b5db 100644
--- a/chrome/browser/autocomplete/autocomplete_input.cc
+++ b/chrome/browser/autocomplete/autocomplete_input.cc
@@ -133,7 +133,7 @@ AutocompleteInput::Type AutocompleteInput::Parse(
if (first_non_white == base::string16::npos)
return INVALID; // All whitespace.
- if (text.at(first_non_white) == L'?') {
+ if (text[first_non_white] == L'?') {
// If the first non-whitespace character is a '?', we magically treat this
// as a query.
return FORCED_QUERY;
diff --git a/chrome/browser/autocomplete/builtin_provider.cc b/chrome/browser/autocomplete/builtin_provider.cc
index 5b35c75..df0fc43 100644
--- a/chrome/browser/autocomplete/builtin_provider.cc
+++ b/chrome/browser/autocomplete/builtin_provider.cc
@@ -107,8 +107,7 @@ void BuiltinProvider::Start(const AutocompleteInput& input,
!url.has_query() && !url.has_ref()) {
// Include the path for sub-pages (e.g. "chrome://settings/browser").
base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path());
- base::TrimString(host_and_path, base::ASCIIToUTF16("/").c_str(),
- &host_and_path);
+ base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path);
size_t match_length = kChrome.length() + host_and_path.length();
for (Builtins::const_iterator i(builtins_.begin());
(i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) {
diff --git a/chrome/browser/chromeos/drive/file_system_util.cc b/chrome/browser/chromeos/drive/file_system_util.cc
index 5cba03b..1abe96f 100644
--- a/chrome/browser/chromeos/drive/file_system_util.cc
+++ b/chrome/browser/chromeos/drive/file_system_util.cc
@@ -48,21 +48,6 @@ namespace util {
namespace {
-const base::FilePath::CharType kSpecialMountPointRoot[] =
- FILE_PATH_LITERAL("/special");
-
-const char kDriveMountPointNameBase[] = "drive";
-
-const base::FilePath::CharType kDriveMyDriveRootPath[] =
- FILE_PATH_LITERAL("drive/root");
-
-const base::FilePath::CharType kFileCacheVersionDir[] =
- FILE_PATH_LITERAL("v1");
-
-const char kSlash[] = "/";
-const char kDot = '.';
-const char kEscapedChars[] = "_";
-
std::string ReadStringFromGDocFile(const base::FilePath& file_path,
const std::string& key) {
const int64 kMaxGDocSize = 4096;
@@ -123,12 +108,15 @@ const base::FilePath& GetDriveGrandRootPath() {
const base::FilePath& GetDriveMyDriveRootPath() {
CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_root_path,
- (kDriveMyDriveRootPath));
+ (FILE_PATH_LITERAL("drive/root")));
return drive_root_path;
}
base::FilePath GetDriveMountPointPathForUserIdHash(
const std::string user_id_hash) {
+ static const base::FilePath::CharType kSpecialMountPointRoot[] =
+ FILE_PATH_LITERAL("/special");
+ static const char kDriveMountPointNameBase[] = "drive";
return base::FilePath(kSpecialMountPointRoot).AppendASCII(
net::EscapePath(kDriveMountPointNameBase +
(user_id_hash.empty() ? "" : "-" + user_id_hash)));
@@ -267,6 +255,8 @@ base::FilePath GetCacheRootPath(Profile* profile) {
chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path);
base::FilePath cache_root_path =
cache_base_path.Append(chromeos::kDriveCacheDirname);
+ static const base::FilePath::CharType kFileCacheVersionDir[] =
+ FILE_PATH_LITERAL("v1");
return cache_root_path.Append(kFileCacheVersionDir);
}
@@ -304,9 +294,9 @@ std::string NormalizeFileName(const std::string& input) {
std::string output;
if (!base::ConvertToUtf8AndNormalize(input, base::kCodepageUTF8, &output))
output = input;
- base::ReplaceChars(output, kSlash, std::string(kEscapedChars), &output);
- if (!output.empty() && output.find_first_not_of(kDot, 0) == std::string::npos)
- output = kEscapedChars;
+ base::ReplaceChars(output, "/", "_", &output);
+ if (!output.empty() && output.find_first_not_of('.', 0) == std::string::npos)
+ output = "_";
return output;
}
diff --git a/chrome/browser/drive/drive_api_util.cc b/chrome/browser/drive/drive_api_util.cc
index b7b350a..13cefa6 100644
--- a/chrome/browser/drive/drive_api_util.cc
+++ b/chrome/browser/drive/drive_api_util.cc
@@ -66,8 +66,7 @@ std::string TranslateQuery(const std::string& original_query) {
// In order to handle non-ascii white spaces correctly, convert to UTF16.
base::string16 query = base::UTF8ToUTF16(original_query);
const base::string16 kDelimiter(
- base::kWhitespaceUTF16 +
- base::string16(1, static_cast<base::char16>('"')));
+ base::kWhitespaceUTF16 + base::ASCIIToUTF16("\""));
std::string result;
for (size_t index = query.find_first_not_of(base::kWhitespaceUTF16);
diff --git a/chrome/browser/errorpage_browsertest.cc b/chrome/browser/errorpage_browsertest.cc
index c23c7d0..025492f 100644
--- a/chrome/browser/errorpage_browsertest.cc
+++ b/chrome/browser/errorpage_browsertest.cc
@@ -89,8 +89,9 @@ bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser,
net::Error error_code) {
// Get the error as a string, and remove the leading "net::", which is not
// included on error pages.
- std::string error_string = net::ErrorToString(error_code);
- base::RemoveChars(error_string, "net:", &error_string);
+ std::string error_string(net::ErrorToString(error_code));
+ DCHECK(StartsWithASCII(error_string, "net::", true));
+ error_string.erase(0, 5);
return IsDisplayingText(browser, error_string);
}
diff --git a/chrome/browser/guest_view/ad_view/ad_view_guest.cc b/chrome/browser/guest_view/ad_view/ad_view_guest.cc
index 5144729..155e589 100644
--- a/chrome/browser/guest_view/ad_view/ad_view_guest.cc
+++ b/chrome/browser/guest_view/ad_view/ad_view_guest.cc
@@ -49,8 +49,9 @@ void AdViewGuest::DidFailProvisionalLoad(
const base::string16& error_description,
content::RenderViewHost* render_view_host) {
// Translate the |error_code| into an error string.
- std::string error_type;
- base::RemoveChars(net::ErrorToString(error_code), "net::", &error_type);
+ std::string error_type(net::ErrorToString(error_code));
+ DCHECK(StartsWithASCII(error_type, "net::", true));
+ error_type.erase(0, 5);
scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
args->SetBoolean(guestview::kIsTopLevel, is_main_frame);
diff --git a/chrome/browser/guest_view/web_view/web_view_guest.cc b/chrome/browser/guest_view/web_view/web_view_guest.cc
index bf6e50e..e1073dc 100644
--- a/chrome/browser/guest_view/web_view/web_view_guest.cc
+++ b/chrome/browser/guest_view/web_view/web_view_guest.cc
@@ -822,8 +822,9 @@ void WebViewGuest::DidFailProvisionalLoad(
const base::string16& error_description,
content::RenderViewHost* render_view_host) {
// Translate the |error_code| into an error string.
- std::string error_type;
- base::RemoveChars(net::ErrorToString(error_code), "net::", &error_type);
+ std::string error_type(net::ErrorToString(error_code));
+ DCHECK(StartsWithASCII(error_type, "net::", true));
+ error_type.erase(0, 5);
LoadAbort(is_main_frame, validated_url, error_type);
}
@@ -1076,9 +1077,9 @@ void WebViewGuest::NavigateGuest(const std::string& src) {
!url.SchemeIs(content::kAboutScheme)) ||
url.SchemeIs(url::kJavaScriptScheme);
if (scheme_is_blocked || !url.is_valid()) {
- std::string error_type;
- base::RemoveChars(net::ErrorToString(net::ERR_ABORTED), "net::",
- &error_type);
+ std::string error_type(net::ErrorToString(net::ERR_ABORTED));
+ DCHECK(StartsWithASCII(error_type, "net::", true));
+ error_type.erase(0, 5);
LoadAbort(true /* is_top_level */, url, error_type);
return;
}
diff --git a/chrome/browser/profile_resetter/resettable_settings_snapshot.cc b/chrome/browser/profile_resetter/resettable_settings_snapshot.cc
index 7ba8be2..44bee23 100644
--- a/chrome/browser/profile_resetter/resettable_settings_snapshot.cc
+++ b/chrome/browser/profile_resetter/resettable_settings_snapshot.cc
@@ -200,7 +200,7 @@ std::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot,
i != shortcuts.end(); ++i) {
base::string16 arguments;
// Replace "\"" to simplify server-side analysis.
- base::ReplaceChars(i->second, base::ASCIIToUTF16("\"").c_str(),
+ base::ReplaceChars(i->second, base::ASCIIToUTF16("\""),
base::ASCIIToUTF16("\'"), &arguments);
list->AppendString(arguments);
}
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
index be70702..2e67237 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
@@ -372,8 +372,8 @@ void AddCustomItemsToMenu(const std::vector<content::MenuItem>& items,
// Helper function to escape "&" as "&&".
void EscapeAmpersands(base::string16* text) {
- const base::char16 ampersand[] = {'&', 0};
- base::ReplaceChars(*text, ampersand, base::ASCIIToUTF16("&&"), text);
+ base::ReplaceChars(*text, base::ASCIIToUTF16("&"), base::ASCIIToUTF16("&&"),
+ text);
}
} // namespace
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.cc b/chrome/browser/safe_browsing/safe_browsing_util.cc
index 0334637..4b04c66 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_util.cc
@@ -335,9 +335,8 @@ void CanonicalizeUrl(const GURL& url,
(parsed.host.len > 0)
? url_unescaped_str.substr(parsed.host.begin, parsed.host.len)
: std::string();
- const char kCharsToTrim[] = ".";
std::string host_without_end_dots;
- base::TrimString(host, kCharsToTrim, &host_without_end_dots);
+ base::TrimString(host, ".", &host_without_end_dots);
// 4. In hostname, replace consecutive dots with a single dot.
std::string host_without_consecutive_dots(RemoveConsecutiveChars(
diff --git a/chrome/browser/ui/omnibox/location_bar_util.cc b/chrome/browser/ui/omnibox/location_bar_util.cc
index 93c8b5f..42a24f5 100644
--- a/chrome/browser/ui/omnibox/location_bar_util.cc
+++ b/chrome/browser/ui/omnibox/location_bar_util.cc
@@ -6,6 +6,7 @@
#include "base/i18n/rtl.h"
#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_action.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
@@ -18,16 +19,10 @@ namespace location_bar_util {
base::string16 CalculateMinString(const base::string16& description) {
// Chop at the first '.' or whitespace.
- const size_t dot_index = description.find('.');
- const size_t ws_index = description.find_first_of(base::kWhitespaceUTF16);
- size_t chop_index = std::min(dot_index, ws_index);
- base::string16 min_string;
- if (chop_index == base::string16::npos) {
- // No dot or whitespace, truncate to at most 3 chars.
- min_string = gfx::TruncateString(description, 3);
- } else {
- min_string = description.substr(0, chop_index);
- }
+ const size_t chop_index = description.find_first_of(
+ base::kWhitespaceUTF16 + base::ASCIIToUTF16("."));
+ base::string16 min_string((chop_index == base::string16::npos) ?
+ gfx::TruncateString(description, 3) : description.substr(0, chop_index));
base::i18n::AdjustStringForLocaleDirection(&min_string);
return min_string;
}