summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-26 22:39:33 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-26 22:39:33 +0000
commit51343d5ae5d463fc4f84f4af79b44962a580cd4f (patch)
tree8d53ff6a0097950f2732ee5376bf0c83297c9c87 /base
parent7b9db43fbc1731cabc985f6e026a07a2ceaafc28 (diff)
downloadchromium_src-51343d5ae5d463fc4f84f4af79b44962a580cd4f.zip
chromium_src-51343d5ae5d463fc4f84f4af79b44962a580cd4f.tar.gz
chromium_src-51343d5ae5d463fc4f84f4af79b44962a580cd4f.tar.bz2
Remove deprecated CommandLine(std::wstring) ctor.
Add a ctor for creating a CommandLine for carrying arguments; convert all the users to either that or the FilePath version. BUG=24672 Review URL: http://codereview.chromium.org/329017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30117 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/command_line.cc19
-rw-r--r--base/command_line.h12
-rw-r--r--base/command_line_unittest.cc14
-rw-r--r--base/process_util_unittest.cc8
4 files changed, 25 insertions, 28 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index 1e52004..4e3bb3a 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -52,6 +52,9 @@ static void Lowercase(std::string* parameter) {
#endif
#if defined(OS_WIN)
+CommandLine::CommandLine(ArgumentsOnly args_only) {
+}
+
void CommandLine::ParseFromString(const std::wstring& command_line) {
TrimWhitespace(command_line, TRIM_ALL, &command_line_string_);
@@ -101,14 +104,12 @@ CommandLine::CommandLine(const FilePath& program) {
}
}
-// Deprecated version
-CommandLine::CommandLine(const std::wstring& program) {
- if (!program.empty()) {
- program_ = program;
- command_line_string_ = L'"' + program + L'"';
- }
-}
#elif defined(OS_POSIX)
+CommandLine::CommandLine(ArgumentsOnly args_only) {
+ // Push an empty argument, because we always assume argv_[0] is a program.
+ argv_.push_back("");
+}
+
void CommandLine::InitFromArgv(int argc, const char* const* argv) {
for (int i = 0; i < argc; ++i)
argv_.push_back(argv[i]);
@@ -145,10 +146,6 @@ CommandLine::CommandLine(const FilePath& program) {
argv_.push_back(program.value());
}
-// Deprecated version
-CommandLine::CommandLine(const std::wstring& program) {
- argv_.push_back(base::SysWideToNativeMB(program));
-}
#endif
// static
diff --git a/base/command_line.h b/base/command_line.h
index 91eb892..37a6a4e 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -32,10 +32,19 @@ class InProcessBrowserTest;
class CommandLine {
public:
+ // A constructor for CommandLines that are used only to carry arguments.
+ enum ArgumentsOnly { ARGUMENTS_ONLY };
+ explicit CommandLine(ArgumentsOnly args_only);
+
#if defined(OS_WIN)
// Initialize by parsing the given command-line string.
// The program name is assumed to be the first item in the string.
void ParseFromString(const std::wstring& command_line);
+ static CommandLine FromString(const std::wstring& command_line) {
+ CommandLine cmd;
+ cmd.ParseFromString(command_line);
+ return cmd;
+ }
#elif defined(OS_POSIX)
// Initialize from an argv vector.
void InitFromArgv(int argc, const char* const* argv);
@@ -53,9 +62,6 @@ class CommandLine {
// |program| is the name of the program to run (aka argv[0]).
explicit CommandLine(const FilePath& program);
- // Deprecated in favor of FilePath version.
- explicit CommandLine(const std::wstring& program);
-
// Initialize the current process CommandLine singleton. On Windows,
// ignores its arguments (we instead parse GetCommandLineW()
// directly) because we don't trust the CRT's parsing of the command
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index bfd0a56..7ab8f79 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -12,8 +12,8 @@
TEST(CommandLineTest, CommandLineConstructor) {
#if defined(OS_WIN)
- CommandLine cl(L"");
- cl.ParseFromString(L"program --foo= -bAr /Spaetzel=pierogi /Baz flim "
+ CommandLine cl = CommandLine::FromString(
+ L"program --foo= -bAr /Spaetzel=pierogi /Baz flim "
L"--other-switches=\"--dog=canine --cat=feline\" "
L"-spaetzle=Crepe -=loosevalue flan "
L"--input-translation=\"45\"--output-rotation "
@@ -85,7 +85,7 @@ TEST(CommandLineTest, CommandLineConstructor) {
// Tests behavior with an empty input string.
TEST(CommandLineTest, EmptyString) {
#if defined(OS_WIN)
- CommandLine cl(L"");
+ CommandLine cl = CommandLine::FromString(L"");
EXPECT_TRUE(cl.command_line_string().empty());
EXPECT_TRUE(cl.program().empty());
#elif defined(OS_POSIX)
@@ -105,13 +105,7 @@ TEST(CommandLineTest, AppendSwitches) {
std::string switch4 = "switch4";
std::wstring value4 = L"\"a value with quotes\"";
-#if defined(OS_WIN)
- CommandLine cl(L"Program");
-#elif defined(OS_POSIX)
- std::vector<std::string> argv;
- argv.push_back(std::string("Program"));
- CommandLine cl(argv);
-#endif
+ CommandLine cl(FilePath(FILE_PATH_LITERAL("Program")));
cl.AppendSwitch(switch1);
cl.AppendSwitchWithValue(switch2, value);
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 0dfcd2b..eff8fae 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -151,7 +151,7 @@ TEST_F(ProcessUtilTest, GetAppOutput) {
.Append(FILE_PATH_LITERAL("python_24"))
.Append(FILE_PATH_LITERAL("python.exe"));
- CommandLine cmd_line(python_runtime.value());
+ CommandLine cmd_line(python_runtime);
cmd_line.AppendLooseValue(L"-c");
cmd_line.AppendLooseValue(L"\"import sys; sys.stdout.write('" +
ASCIIToWide(message) + L"');\"");
@@ -160,7 +160,7 @@ TEST_F(ProcessUtilTest, GetAppOutput) {
EXPECT_EQ(message, output);
// Let's make sure stderr is ignored.
- CommandLine other_cmd_line(python_runtime.value());
+ CommandLine other_cmd_line(python_runtime);
other_cmd_line.AppendLooseValue(L"-c");
other_cmd_line.AppendLooseValue(
L"\"import sys; sys.stderr.write('Hello!');\"");
@@ -260,10 +260,10 @@ TEST_F(ProcessUtilTest, FDRemapping) {
TEST_F(ProcessUtilTest, GetAppOutput) {
std::string output;
- EXPECT_TRUE(GetAppOutput(CommandLine(L"true"), &output));
+ EXPECT_TRUE(GetAppOutput(CommandLine(FilePath("true")), &output));
EXPECT_STREQ("", output.c_str());
- EXPECT_FALSE(GetAppOutput(CommandLine(L"false"), &output));
+ EXPECT_FALSE(GetAppOutput(CommandLine(FilePath("false")), &output));
std::vector<std::string> argv;
argv.push_back("/bin/echo");