summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 02:07:25 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 02:07:25 +0000
commitb7e0a2a3ccf5aceb891d5e1dfaf9db1bbaaa5f78 (patch)
treed723b8556ad386a0b8a6e999e3a842e0bfe6f9b0 /base
parent1976d41ac728fcceb30f2df3c243cb7417f538f1 (diff)
downloadchromium_src-b7e0a2a3ccf5aceb891d5e1dfaf9db1bbaaa5f78.zip
chromium_src-b7e0a2a3ccf5aceb891d5e1dfaf9db1bbaaa5f78.tar.gz
chromium_src-b7e0a2a3ccf5aceb891d5e1dfaf9db1bbaaa5f78.tar.bz2
Use ASCII strings for switch names.
Review URL: http://codereview.chromium.org/270062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base_switches.cc16
-rw-r--r--base/base_switches.h16
-rw-r--r--base/command_line.cc54
-rw-r--r--base/command_line.h30
-rw-r--r--base/command_line_unittest.cc50
-rw-r--r--base/debug_on_start.cc6
-rw-r--r--base/debug_on_start.h2
-rw-r--r--base/multiprocess_test.h2
-rw-r--r--base/test/perf_test_suite.h2
-rw-r--r--base/test/test_suite.h2
10 files changed, 100 insertions, 80 deletions
diff --git a/base/base_switches.cc b/base/base_switches.cc
index b13517a..2613623 100644
--- a/base/base_switches.cc
+++ b/base/base_switches.cc
@@ -9,29 +9,29 @@ namespace switches {
// If the program includes chrome/common/debug_on_start.h, the process will
// start the JIT system-registered debugger on itself and will wait for 60
// seconds for the debugger to attach to itself. Then a break point will be hit.
-const wchar_t kDebugOnStart[] = L"debug-on-start";
+const char kDebugOnStart[] = "debug-on-start";
// Will wait for 60 seconds for a debugger to come to attach to the process.
-const wchar_t kWaitForDebugger[] = L"wait-for-debugger";
+const char kWaitForDebugger[] = "wait-for-debugger";
// Suppresses all error dialogs when present.
-const wchar_t kNoErrorDialogs[] = L"noerrdialogs";
+const char kNoErrorDialogs[] = "noerrdialogs";
// Disables the crash reporting.
-const wchar_t kDisableBreakpad[] = L"disable-breakpad";
+const char kDisableBreakpad[] = "disable-breakpad";
// Generates full memory crash dump.
-const wchar_t kFullMemoryCrashReport[] = L"full-memory-crash-report";
+const char kFullMemoryCrashReport[] = "full-memory-crash-report";
// The value of this switch determines whether the process is started as a
// renderer or plugin host. If it's empty, it's the browser.
-const wchar_t kProcessType[] = L"type";
+const char kProcessType[] = "type";
// Enable DCHECKs in release mode.
-const wchar_t kEnableDCHECK[] = L"enable-dcheck";
+const char kEnableDCHECK[] = "enable-dcheck";
// Disable win_util::MessageBox. This is useful when running as part of
// scripts that do not have a user interface.
-const wchar_t kNoMessageBox[] = L"no-message-box";
+const char kNoMessageBox[] = "no-message-box";
} // namespace switches
diff --git a/base/base_switches.h b/base/base_switches.h
index e708ee4..4074043 100644
--- a/base/base_switches.h
+++ b/base/base_switches.h
@@ -9,14 +9,14 @@
namespace switches {
-extern const wchar_t kDebugOnStart[];
-extern const wchar_t kWaitForDebugger[];
-extern const wchar_t kDisableBreakpad[];
-extern const wchar_t kFullMemoryCrashReport[];
-extern const wchar_t kNoErrorDialogs[];
-extern const wchar_t kProcessType[];
-extern const wchar_t kEnableDCHECK[];
-extern const wchar_t kNoMessageBox[];
+extern const char kDebugOnStart[];
+extern const char kWaitForDebugger[];
+extern const char kDisableBreakpad[];
+extern const char kFullMemoryCrashReport[];
+extern const char kNoErrorDialogs[];
+extern const char kProcessType[];
+extern const char kEnableDCHECK[];
+extern const char kNoMessageBox[];
} // namespace switches
diff --git a/base/command_line.cc b/base/command_line.cc
index a1c2c1e..1e52004 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -45,7 +45,7 @@ const char kSwitchValueSeparator[] = "=";
// Lowercase a string. This is used to lowercase switch names.
// Is this what we really want? It seems crazy to me. I've left it in
// for backwards compatibility on Windows.
-static void Lowercase(std::wstring* parameter) {
+static void Lowercase(std::string* parameter) {
transform(parameter->begin(), parameter->end(), parameter->begin(),
tolower);
}
@@ -175,8 +175,8 @@ bool CommandLine::IsSwitch(const StringType& parameter_string,
*switch_value = parameter_string.substr(equals_position + 1);
}
#if defined(OS_WIN)
- Lowercase(&switch_native);
*switch_string = WideToASCII(switch_native);
+ Lowercase(switch_string);
#else
*switch_string = switch_native;
#endif
@@ -225,23 +225,23 @@ void CommandLine::Reset() {
current_process_commandline_ = NULL;
}
-bool CommandLine::HasSwitch(const std::wstring& switch_string) const {
- std::wstring lowercased_switch(switch_string);
+bool CommandLine::HasSwitch(const std::string& switch_string) const {
+ std::string lowercased_switch(switch_string);
#if defined(OS_WIN)
Lowercase(&lowercased_switch);
#endif
- return switches_.find(WideToASCII(lowercased_switch)) != switches_.end();
+ return switches_.find(lowercased_switch) != switches_.end();
}
std::wstring CommandLine::GetSwitchValue(
- const std::wstring& switch_string) const {
- std::wstring lowercased_switch(switch_string);
+ const std::string& switch_string) const {
+ std::string lowercased_switch(switch_string);
#if defined(OS_WIN)
Lowercase(&lowercased_switch);
#endif
std::map<std::string, StringType>::const_iterator result =
- switches_.find(WideToASCII(lowercased_switch));
+ switches_.find(lowercased_switch);
if (result == switches_.end()) {
return L"";
@@ -277,39 +277,39 @@ std::wstring CommandLine::program() const {
// static
std::wstring CommandLine::PrefixedSwitchString(
- const std::wstring& switch_string) {
+ const std::string& switch_string) {
#if defined(OS_WIN)
- return kSwitchPrefixes[0] + switch_string;
+ return kSwitchPrefixes[0] + ASCIIToWide(switch_string);
#else
- return ASCIIToWide(kSwitchPrefixes[0]) + switch_string;
+ return ASCIIToWide(kSwitchPrefixes[0] + switch_string);
#endif
}
// static
std::wstring CommandLine::PrefixedSwitchStringWithValue(
- const std::wstring& switch_string, const std::wstring& value_string) {
+ const std::string& switch_string, const std::wstring& value_string) {
if (value_string.empty()) {
return PrefixedSwitchString(switch_string);
}
return PrefixedSwitchString(switch_string +
#if defined(OS_WIN)
- kSwitchValueSeparator +
+ WideToASCII(kSwitchValueSeparator)
#else
- ASCIIToWide(kSwitchValueSeparator) +
+ kSwitchValueSeparator
#endif
- value_string);
+ ) + value_string;
}
#if defined(OS_WIN)
-void CommandLine::AppendSwitch(const std::wstring& switch_string) {
+void CommandLine::AppendSwitch(const std::string& switch_string) {
std::wstring prefixed_switch_string = PrefixedSwitchString(switch_string);
command_line_string_.append(L" ");
command_line_string_.append(prefixed_switch_string);
- switches_[WideToASCII(switch_string)] = L"";
+ switches_[switch_string] = L"";
}
-void CommandLine::AppendSwitchWithValue(const std::wstring& switch_string,
+void CommandLine::AppendSwitchWithValue(const std::string& switch_string,
const std::wstring& value_string) {
std::wstring value_string_edit;
@@ -326,12 +326,12 @@ void CommandLine::AppendSwitchWithValue(const std::wstring& switch_string,
}
std::wstring combined_switch_string =
- PrefixedSwitchStringWithValue(switch_string, value_string_edit);
+ PrefixedSwitchStringWithValue(switch_string, value_string_edit);
command_line_string_.append(L" ");
command_line_string_.append(combined_switch_string);
- switches_[WideToASCII(switch_string)] = value_string;
+ switches_[switch_string] = value_string;
}
void CommandLine::AppendLooseValue(const std::wstring& value) {
@@ -361,20 +361,18 @@ void CommandLine::PrependWrapper(const std::wstring& wrapper) {
}
#elif defined(OS_POSIX)
-void CommandLine::AppendSwitch(const std::wstring& switch_string) {
- std::string ascii_switch = WideToASCII(switch_string);
- argv_.push_back(kSwitchPrefixes[0] + ascii_switch);
- switches_[ascii_switch] = "";
+void CommandLine::AppendSwitch(const std::string& switch_string) {
+ argv_.push_back(kSwitchPrefixes[0] + switch_string);
+ switches_[switch_string] = "";
}
-void CommandLine::AppendSwitchWithValue(const std::wstring& switch_string,
+void CommandLine::AppendSwitchWithValue(const std::string& switch_string,
const std::wstring& value_string) {
- std::string ascii_switch = WideToASCII(switch_string);
std::string mb_value = base::SysWideToNativeMB(value_string);
- argv_.push_back(kSwitchPrefixes[0] + ascii_switch +
+ argv_.push_back(kSwitchPrefixes[0] + switch_string +
kSwitchValueSeparator + mb_value);
- switches_[ascii_switch] = mb_value;
+ switches_[switch_string] = mb_value;
}
void CommandLine::AppendLooseValue(const std::wstring& value) {
diff --git a/base/command_line.h b/base/command_line.h
index 4fd8e4a..78adb46 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -26,6 +26,7 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/logging.h"
+#include "base/string_util.h"
class InProcessBrowserTest;
@@ -88,12 +89,25 @@ class CommandLine {
// Returns true if this command line contains the given switch.
// (Switch names are case-insensitive.)
- bool HasSwitch(const std::wstring& switch_string) const;
+ bool HasSwitch(const std::string& switch_string) const;
+
+ // Deprecated version of the above.
+ bool HasSwitch(const std::wstring& switch_string) const {
+ return HasSwitch(WideToASCII(switch_string));
+ }
// Returns the value associated with the given switch. If the
// switch has no value or isn't present, this method returns
// the empty string.
- std::wstring GetSwitchValue(const std::wstring& switch_string) const;
+ std::wstring GetSwitchValue(const std::string& switch_string) const;
+ std::string GetSwitchValueASCII(const std::string& switch_string) const {
+ return WideToASCII(GetSwitchValue(switch_string));
+ }
+
+ // Deprecated version of the above.
+ std::wstring GetSwitchValue(const std::wstring& switch_string) const {
+ return GetSwitchValue(WideToASCII(switch_string));
+ }
// Get the number of switches in this process.
size_t GetSwitchCount() const { return switches_.size(); }
@@ -125,22 +139,26 @@ class CommandLine {
// Return a copy of the string prefixed with a switch prefix.
// Used internally.
- static std::wstring PrefixedSwitchString(const std::wstring& switch_string);
+ static std::wstring PrefixedSwitchString(const std::string& switch_string);
// Return a copy of the string prefixed with a switch prefix,
// and appended with the given value. Used internally.
static std::wstring PrefixedSwitchStringWithValue(
- const std::wstring& switch_string,
+ const std::string& switch_string,
const std::wstring& value_string);
// Appends the given switch string (preceded by a space and a switch
// prefix) to the given string.
- void AppendSwitch(const std::wstring& switch_string);
+ void AppendSwitch(const std::string& switch_string);
// Appends the given switch string (preceded by a space and a switch
// prefix) to the given string, with the given value attached.
- void AppendSwitchWithValue(const std::wstring& switch_string,
+ void AppendSwitchWithValue(const std::string& switch_string,
const std::wstring& value_string);
+ void AppendSwitchWithValue(const std::string& switch_string,
+ const std::string& value_string) {
+ AppendSwitchWithValue(switch_string, ASCIIToWide(value_string));
+ }
// Append a loose value to the command line.
void AppendLooseValue(const std::wstring& value);
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index 0d89d10..bfd0a56 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -30,33 +30,33 @@ TEST(CommandLineTest, CommandLineConstructor) {
"in the time of submarines..."};
CommandLine cl(arraysize(argv), argv);
#endif
- EXPECT_FALSE(cl.HasSwitch(L"cruller"));
- EXPECT_FALSE(cl.HasSwitch(L"flim"));
- EXPECT_FALSE(cl.HasSwitch(L"program"));
- EXPECT_FALSE(cl.HasSwitch(L"dog"));
- EXPECT_FALSE(cl.HasSwitch(L"cat"));
- EXPECT_FALSE(cl.HasSwitch(L"output-rotation"));
- EXPECT_FALSE(cl.HasSwitch(L"not-a-switch"));
- EXPECT_FALSE(cl.HasSwitch(L"--"));
+ EXPECT_FALSE(cl.HasSwitch("cruller"));
+ EXPECT_FALSE(cl.HasSwitch("flim"));
+ EXPECT_FALSE(cl.HasSwitch("program"));
+ EXPECT_FALSE(cl.HasSwitch("dog"));
+ EXPECT_FALSE(cl.HasSwitch("cat"));
+ EXPECT_FALSE(cl.HasSwitch("output-rotation"));
+ EXPECT_FALSE(cl.HasSwitch("not-a-switch"));
+ EXPECT_FALSE(cl.HasSwitch("--"));
EXPECT_EQ(L"program", cl.program());
- EXPECT_TRUE(cl.HasSwitch(L"foo"));
- EXPECT_TRUE(cl.HasSwitch(L"bar"));
- EXPECT_TRUE(cl.HasSwitch(L"baz"));
- EXPECT_TRUE(cl.HasSwitch(L"spaetzle"));
+ EXPECT_TRUE(cl.HasSwitch("foo"));
+ EXPECT_TRUE(cl.HasSwitch("bar"));
+ EXPECT_TRUE(cl.HasSwitch("baz"));
+ EXPECT_TRUE(cl.HasSwitch("spaetzle"));
#if defined(OS_WIN)
- EXPECT_TRUE(cl.HasSwitch(L"SPAETZLE"));
+ EXPECT_TRUE(cl.HasSwitch("SPAETZLE"));
#endif
- EXPECT_TRUE(cl.HasSwitch(L"other-switches"));
- EXPECT_TRUE(cl.HasSwitch(L"input-translation"));
+ EXPECT_TRUE(cl.HasSwitch("other-switches"));
+ EXPECT_TRUE(cl.HasSwitch("input-translation"));
- EXPECT_EQ(L"Crepe", cl.GetSwitchValue(L"spaetzle"));
- EXPECT_EQ(L"", cl.GetSwitchValue(L"Foo"));
- EXPECT_EQ(L"", cl.GetSwitchValue(L"bar"));
- EXPECT_EQ(L"", cl.GetSwitchValue(L"cruller"));
- EXPECT_EQ(L"--dog=canine --cat=feline", cl.GetSwitchValue(L"other-switches"));
- EXPECT_EQ(L"45--output-rotation", cl.GetSwitchValue(L"input-translation"));
+ EXPECT_EQ(L"Crepe", cl.GetSwitchValue("spaetzle"));
+ EXPECT_EQ(L"", cl.GetSwitchValue("Foo"));
+ EXPECT_EQ(L"", cl.GetSwitchValue("bar"));
+ EXPECT_EQ(L"", cl.GetSwitchValue("cruller"));
+ EXPECT_EQ(L"--dog=canine --cat=feline", cl.GetSwitchValue("other-switches"));
+ EXPECT_EQ(L"45--output-rotation", cl.GetSwitchValue("input-translation"));
std::vector<std::wstring> loose_values = cl.GetLooseValues();
ASSERT_EQ(5U, loose_values.size());
@@ -97,12 +97,12 @@ TEST(CommandLineTest, EmptyString) {
// Test methods for appending switches to a command line.
TEST(CommandLineTest, AppendSwitches) {
- std::wstring switch1 = L"switch1";
- std::wstring switch2 = L"switch2";
+ std::string switch1 = "switch1";
+ std::string switch2 = "switch2";
std::wstring value = L"value";
- std::wstring switch3 = L"switch3";
+ std::string switch3 = "switch3";
std::wstring value3 = L"a value with spaces";
- std::wstring switch4 = L"switch4";
+ std::string switch4 = "switch4";
std::wstring value4 = L"\"a value with quotes\"";
#if defined(OS_WIN)
diff --git a/base/debug_on_start.cc b/base/debug_on_start.cc
index c7d4149..9011ca2 100644
--- a/base/debug_on_start.cc
+++ b/base/debug_on_start.cc
@@ -16,8 +16,12 @@
// The code is not that bright and will find things like ---argument or
// /-/argument.
// Note: command_line is non-destructively modified.
-bool DebugOnStart::FindArgument(wchar_t* command_line, const wchar_t* argument)
+bool DebugOnStart::FindArgument(wchar_t* command_line, const char* argument_c)
{
+ wchar_t argument[50];
+ for (int i = 0; argument_c[i]; ++i)
+ argument[i] = argument_c[i];
+
int argument_len = lstrlen(argument);
int command_line_len = lstrlen(command_line);
while (command_line_len > argument_len) {
diff --git a/base/debug_on_start.h b/base/debug_on_start.h
index ab823cf..e31e7eb 100644
--- a/base/debug_on_start.h
+++ b/base/debug_on_start.h
@@ -31,7 +31,7 @@ class DebugOnStart {
// Returns true if the 'argument' is present in the 'command_line'. It does
// not use the CRT, only Kernel32 functions.
- static bool FindArgument(wchar_t* command_line, const wchar_t* argument);
+ static bool FindArgument(wchar_t* command_line, const char* argument);
};
// Set the function pointer to our function to look for a crash on start. The
diff --git a/base/multiprocess_test.h b/base/multiprocess_test.h
index 99c2c79..0662689 100644
--- a/base/multiprocess_test.h
+++ b/base/multiprocess_test.h
@@ -20,7 +20,7 @@
// Command line switch to invoke a child process rather than
// to run the normal test suite.
-static const wchar_t kRunClientProcess[] = L"client";
+static const char kRunClientProcess[] = "client";
// A MultiProcessTest is a test class which makes it easier to
// write a test which requires code running out of process.
diff --git a/base/test/perf_test_suite.h b/base/test/perf_test_suite.h
index 7393544..eed3cfc 100644
--- a/base/test/perf_test_suite.h
+++ b/base/test/perf_test_suite.h
@@ -24,7 +24,7 @@ class PerfTestSuite : public TestSuite {
// Initialize the perf timer log
FilePath log_path;
std::wstring log_file =
- CommandLine::ForCurrentProcess()->GetSwitchValue(L"log-file");
+ CommandLine::ForCurrentProcess()->GetSwitchValue("log-file");
if (log_file.empty()) {
FilePath exe;
PathService::Get(base::FILE_EXE, &exe);
diff --git a/base/test/test_suite.h b/base/test/test_suite.h
index 863721a..5fd1acc 100644
--- a/base/test/test_suite.h
+++ b/base/test/test_suite.h
@@ -210,7 +210,7 @@ class TestSuite {
// In some cases, we do not want to see standard error dialogs.
if (!IsDebuggerPresent() &&
- !CommandLine::ForCurrentProcess()->HasSwitch(L"show-error-dialogs")) {
+ !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) {
SuppressErrorDialogs();
#if !defined(PURIFY)
// When the code in this file moved around, bug 6436 resurfaced.