summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-21 01:00:22 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-21 01:00:22 +0000
commitbb97536b768ac68fcbc4605c35461a798ef6e5ff (patch)
tree479bde96cd05a9e1f9d2746dd82313e2eb715e8e
parent8731a63268015f4e5d684833c11a1b44bd9ae468 (diff)
downloadchromium_src-bb97536b768ac68fcbc4605c35461a798ef6e5ff.zip
chromium_src-bb97536b768ac68fcbc4605c35461a798ef6e5ff.tar.gz
chromium_src-bb97536b768ac68fcbc4605c35461a798ef6e5ff.tar.bz2
Make CommandLine into a normal object, with some statics for getting at the current process's command line.
One explicit goal of this change is to *not* deal with the string/wstring issues at the API on POSIX; the functions are the same as before, which means they remain as broken as before. (I did try to fix the internals, though, so migrating the callers is now possible by adding platform-appropriate hooks.) Review URL: http://codereview.chromium.org/18248 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8347 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/command_line.cc468
-rw-r--r--base/command_line.h159
-rw-r--r--base/command_line_unittest.cc73
-rw-r--r--base/logging.cc3
-rw-r--r--base/multiprocess_test.h31
-rw-r--r--base/perf_test_suite.h3
-rw-r--r--base/process_util.h2
-rw-r--r--base/process_util_linux.cc9
-rw-r--r--base/test_suite.h7
-rw-r--r--chrome/app/breakpad.cc4
-rw-r--r--chrome/app/chrome_dll_main.cc8
-rw-r--r--chrome/app/chrome_exe_main.cc2
-rw-r--r--chrome/app/chrome_main_uitest.cc2
-rw-r--r--chrome/browser/browser.cc6
-rw-r--r--chrome/browser/browser_init.cc50
-rw-r--r--chrome/browser/browser_main.cc9
-rw-r--r--chrome/browser/browser_process_impl.cc2
-rw-r--r--chrome/browser/browser_process_impl.h2
-rw-r--r--chrome/browser/browsing_instance.cc5
-rw-r--r--chrome/browser/chrome_plugin_host.cc4
-rw-r--r--chrome/browser/debugger/debugger_contents.cc3
-rwxr-xr-xchrome/browser/first_run.cc10
-rw-r--r--chrome/browser/first_run.h2
-rw-r--r--chrome/browser/images_uitest.cc6
-rw-r--r--chrome/browser/locale_tests_uitest.cc6
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc4
-rw-r--r--chrome/browser/plugin_process_host.cc42
-rw-r--r--chrome/browser/printing/printing_layout_uitest.cc7
-rw-r--r--chrome/browser/render_view_context_menu_controller.cc2
-rw-r--r--chrome/browser/render_view_host_manager.cc4
-rw-r--r--chrome/browser/render_widget_host_view_win.cc3
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc43
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database.cc4
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_unittest.cc3
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc3
-rw-r--r--chrome/browser/search_engines/template_url_prepopulate_data.cc3
-rw-r--r--chrome/browser/sessions/session_restore_uitest.cc16
-rw-r--r--chrome/browser/tab_contents/web_contents.cc2
-rw-r--r--chrome/browser/unload_uitest.cc8
-rw-r--r--chrome/browser/user_data_manager.cc9
-rw-r--r--chrome/browser/views/frame/browser_view.cc4
-rw-r--r--chrome/common/child_process.cc2
-rw-r--r--chrome/common/chrome_paths.cc4
-rw-r--r--chrome/common/chrome_plugin_lib.cc3
-rw-r--r--chrome/common/chrome_plugin_util.cc8
-rw-r--r--chrome/common/common_glue.cc2
-rw-r--r--chrome/common/debug_flags.cc17
-rw-r--r--chrome/common/debug_flags.h18
-rw-r--r--chrome/common/ipc_channel_posix.cc3
-rw-r--r--chrome/common/ipc_logging.cc2
-rw-r--r--chrome/common/ipc_tests.cc11
-rw-r--r--chrome/common/l10n_util.cc2
-rw-r--r--chrome/common/logging_chrome_uitest.cc9
-rw-r--r--chrome/common/main_function_params.h6
-rw-r--r--chrome/common/pref_service_uitest.cc5
-rw-r--r--chrome/common/temp_scaffolding_stubs.cpp2
-rw-r--r--chrome/common/temp_scaffolding_stubs.h4
-rwxr-xr-xchrome/installer/setup/main.cc3
-rwxr-xr-xchrome/installer/setup/setup.cc1
-rw-r--r--chrome/plugin/plugin_main.cc2
-rw-r--r--chrome/plugin/webplugin_delegate_stub.cc2
-rw-r--r--chrome/renderer/render_process.cc2
-rw-r--r--chrome/renderer/render_view.cc6
-rw-r--r--chrome/renderer/renderer_glue.cc2
-rw-r--r--chrome/renderer/renderer_main.cc2
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.cc12
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc12
-rw-r--r--chrome/test/memory_test/memory_test.cc15
-rw-r--r--chrome/test/page_cycler/page_cycler_test.cc5
-rw-r--r--chrome/test/plugin/plugin_test.cpp21
-rw-r--r--chrome/test/reliability/reliability_test_suite.h2
-rw-r--r--chrome/test/startup/startup_test.cc2
-rw-r--r--chrome/test/ui/inspector_controller_uitest.cc2
-rw-r--r--chrome/test/ui/omnibox_uitest.cc3
-rw-r--r--chrome/test/ui/sandbox_uitests.cc5
-rw-r--r--chrome/test/ui/ui_test.cc94
-rw-r--r--chrome/test/ui/ui_test.h7
-rw-r--r--chrome/test/ui/ui_test_suite.h2
-rw-r--r--chrome/test/unit/chrome_test_suite.h3
-rw-r--r--chrome/tools/test/image_diff/image_diff.cc22
-rw-r--r--chrome/views/window.cc2
-rw-r--r--net/disk_cache/stress_cache.cc10
-rw-r--r--net/tools/crash_cache/crash_cache.cc10
-rw-r--r--net/tools/tld_cleanup/tld_cleanup.cc4
-rw-r--r--net/url_request/url_request_http_job.cc5
-rw-r--r--net/url_request/url_request_unittest.h4
-rw-r--r--skia/ext/vector_canvas_unittest.cc3
-rw-r--r--webkit/activex_shim/activex_shared.cc4
-rw-r--r--webkit/glue/plugins/plugin_list_win.cc2
-rw-r--r--webkit/tools/test_shell/mac/main.mm16
-rw-r--r--webkit/tools/test_shell/node_leak_test.cc12
-rw-r--r--webkit/tools/test_shell/run_all_tests.cc6
-rwxr-xr-xwebkit/tools/test_shell/test_shell.cc2
-rw-r--r--webkit/tools/test_shell/test_shell_main.cc19
-rw-r--r--webkit/tools/test_shell/test_shell_win.cc2
95 files changed, 714 insertions, 745 deletions
diff --git a/base/command_line.cc b/base/command_line.cc
index 6e02e1d..cf3e36f 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -17,302 +17,228 @@
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
-using namespace std;
+CommandLine* CommandLine::current_process_commandline_ = NULL;
// Since we use a lazy match, make sure that longer versions (like L"--")
// are listed before shorter versions (like L"-") of similar prefixes.
#if defined(OS_WIN)
-const wchar_t* const CommandLine::kSwitchPrefixes[] = {L"--", L"-", L"/"};
+const wchar_t* const kSwitchPrefixes[] = {L"--", L"-", L"/"};
+const wchar_t kSwitchTerminator[] = L"--";
+const wchar_t kSwitchValueSeparator[] = L"=";
#elif defined(OS_POSIX)
// Unixes don't use slash as a switch.
-const wchar_t* const CommandLine::kSwitchPrefixes[] = {L"--", L"-"};
+const char* const kSwitchPrefixes[] = {"--", "-"};
+const char kSwitchTerminator[] = "--";
+const char kSwitchValueSeparator[] = "=";
#endif
-const wchar_t CommandLine::kSwitchValueSeparator[] = L"=";
-const wchar_t CommandLine::kSwitchTerminator[] = L"--";
-
-// Needed to avoid a typecast on the tolower() function pointer in Lowercase().
-// MSVC accepts it as-is but GCC requires the typecast.
-static int ToLower(int c) {
- return tolower(c);
-}
-
-static void Lowercase(wstring* parameter) {
- transform(parameter->begin(), parameter->end(), parameter->begin(),
- ToLower);
+#if defined(OS_WIN)
+// 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) {
+ transform(parameter->begin(), parameter->end(), parameter->begin(),
+ tolower);
}
+#endif
-// CommandLine::Data
-//
-// This object holds the parsed data for a command line. We hold this in a
-// separate object from |CommandLine| so that we can share the parsed data
-// across multiple |CommandLine| objects. When we share |Data|, we might be
-// accessing this object on multiple threads. To ensure thread safety, the
-// public interface of this object is const only.
-//
-// Do NOT add any non-const methods to this object. You have been warned.
-class CommandLine::Data {
- public:
#if defined(OS_WIN)
- Data() {
- Init(GetCommandLineW());
- }
+void CommandLine::ParseFromString(const std::wstring& command_line) {
+ TrimWhitespace(command_line, TRIM_ALL, &command_line_string_);
- Data(const wstring& command_line) {
- Init(command_line);
- }
-#elif defined(OS_POSIX)
- Data() {
- // Owner must call Init().
- }
+ if (command_line_string_.empty())
+ return;
- Data(int argc, const char* const* argv) {
- Init(argc, argv);
- }
-#endif // defined(OS_POSIX)
+ int num_args = 0;
+ wchar_t** args = NULL;
-#if defined(OS_WIN)
- // Does the actual parsing of the command line.
- void Init(const std::wstring& command_line) {
- TrimWhitespace(command_line, TRIM_ALL, &command_line_string_);
-
- if (command_line_string_.empty())
- return;
-
- int num_args = 0;
- wchar_t** args = NULL;
-
- args = CommandLineToArgvW(command_line_string_.c_str(), &num_args);
-
- // Populate program_ with the trimmed version of the first arg.
- TrimWhitespace(args[0], TRIM_ALL, &program_);
-
- bool parse_switches = true;
- for (int i = 1; i < num_args; ++i) {
- wstring arg;
- TrimWhitespace(args[i], TRIM_ALL, &arg);
-
- if (!parse_switches) {
- loose_values_.push_back(arg);
- continue;
- }
-
- if (arg == kSwitchTerminator) {
- parse_switches = false;
- continue;
- }
-
- wstring switch_string;
- wstring switch_value;
- if (IsSwitch(arg, &switch_string, &switch_value)) {
- switches_[switch_string] = switch_value;
- } else {
- loose_values_.push_back(arg);
- }
- }
+ args = CommandLineToArgvW(command_line_string_.c_str(), &num_args);
- if (args)
- LocalFree(args);
- }
-#elif defined(OS_POSIX)
- // Does the actual parsing of the command line.
- void Init(int argc, const char* const* argv) {
- if (argc < 1)
- return;
- program_ = base::SysNativeMBToWide(argv[0]);
- argv_.push_back(std::string(argv[0]));
- command_line_string_ = program_;
-
- bool parse_switches = true;
- for (int i = 1; i < argc; ++i) {
- std::wstring arg = base::SysNativeMBToWide(argv[i]);
- argv_.push_back(argv[i]);
- command_line_string_.append(L" ");
- command_line_string_.append(arg);
-
- if (!parse_switches) {
- loose_values_.push_back(arg);
- continue;
- }
-
- if (arg == kSwitchTerminator) {
- parse_switches = false;
- continue;
- }
-
- wstring switch_string;
- wstring switch_value;
- if (IsSwitch(arg, &switch_string, &switch_value)) {
- switches_[switch_string] = switch_value;
- } else {
- loose_values_.push_back(arg);
- }
+ // Populate program_ with the trimmed version of the first arg.
+ TrimWhitespace(args[0], TRIM_ALL, &program_);
+
+ bool parse_switches = true;
+ for (int i = 1; i < num_args; ++i) {
+ std::wstring arg;
+ TrimWhitespace(args[i], TRIM_ALL, &arg);
+
+ if (!parse_switches) {
+ loose_values_.push_back(arg);
+ continue;
}
- }
-#endif
- const std::wstring& command_line_string() const {
- return command_line_string_;
- }
+ if (arg == kSwitchTerminator) {
+ parse_switches = false;
+ continue;
+ }
- const std::wstring& program() const {
- return program_;
+ std::string switch_string;
+ std::wstring switch_value;
+ if (IsSwitch(arg, &switch_string, &switch_value)) {
+ switches_[switch_string] = switch_value;
+ } else {
+ loose_values_.push_back(arg);
+ }
}
- const std::map<std::wstring, std::wstring>& switches() const {
- return switches_;
+ if (args)
+ LocalFree(args);
+}
+CommandLine::CommandLine(const std::wstring& program) {
+ if (!program.empty()) {
+ program_ = program;
+ command_line_string_ = L'"' + program + L'"';
}
+}
+#elif defined(OS_POSIX)
+CommandLine::CommandLine(int argc, const char* const* argv) {
+ for (int i = 0; i < argc; ++i)
+ argv_.push_back(argv[i]);
+ InitFromArgv();
+}
+CommandLine::CommandLine(const std::vector<std::string>& argv) {
+ argv_ = argv;
+ InitFromArgv();
+}
- const std::vector<std::wstring>& loose_values() const {
- return loose_values_;
- }
+void CommandLine::InitFromArgv() {
+ bool parse_switches = true;
+ for (size_t i = 1; i < argv_.size(); ++i) {
+ const std::string& arg = argv_[i];
-#if defined(OS_POSIX)
- const std::vector<std::string>& argv() const {
- return argv_;
- }
-#endif
+ if (!parse_switches) {
+ loose_values_.push_back(arg);
+ continue;
+ }
- private:
- // Returns true if parameter_string represents a switch. If true,
- // switch_string and switch_value are set. (If false, both are
- // set to the empty string.)
- static bool IsSwitch(const wstring& parameter_string,
- wstring* switch_string,
- wstring* switch_value) {
-
- *switch_string = L"";
- *switch_value = L"";
-
- for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) {
- std::wstring prefix(kSwitchPrefixes[i]);
- if (parameter_string.find(prefix) != 0) // check prefix
- continue;
-
- const size_t switch_start = prefix.length();
- const size_t equals_position = parameter_string.find(
- kSwitchValueSeparator, switch_start);
- if (equals_position == wstring::npos) {
- *switch_string = parameter_string.substr(switch_start);
- } else {
- *switch_string = parameter_string.substr(
- switch_start, equals_position - switch_start);
- *switch_value = parameter_string.substr(equals_position + 1);
- }
- Lowercase(switch_string);
-
- return true;
+ if (arg == kSwitchTerminator) {
+ parse_switches = false;
+ continue;
}
- return false;
+ std::string switch_string;
+ std::string switch_value;
+ if (IsSwitch(arg, &switch_string, &switch_value)) {
+ switches_[switch_string] = switch_value;
+ } else {
+ loose_values_.push_back(arg);
+ }
}
+}
- std::wstring command_line_string_;
- std::wstring program_;
- std::map<std::wstring, std::wstring> switches_;
- std::vector<std::wstring> loose_values_;
- std::vector<std::string> argv_;
-
- DISALLOW_EVIL_CONSTRUCTORS(Data);
-};
-
-CommandLine::CommandLine()
- : we_own_data_(false), // The Singleton class will manage it for us.
- data_(Singleton<Data>::get()) {
- DCHECK(!data_->command_line_string().empty()) <<
- "You must call CommandLine::SetArgcArgv before making any CommandLine "
- "calls.";
+CommandLine::CommandLine(const std::wstring& program) {
+ argv_.push_back(WideToASCII(program));
}
+#endif
+// static
+bool CommandLine::IsSwitch(const StringType& parameter_string,
+ std::string* switch_string,
+ StringType* switch_value) {
+ switch_string->clear();
+ switch_value->clear();
+
+ for (size_t i = 0; i < arraysize(kSwitchPrefixes); ++i) {
+ StringType prefix(kSwitchPrefixes[i]);
+ if (parameter_string.find(prefix) != 0)
+ continue;
+
+ const size_t switch_start = prefix.length();
+ const size_t equals_position = parameter_string.find(
+ kSwitchValueSeparator, switch_start);
+ StringType switch_native;
+ if (equals_position == StringType::npos) {
+ switch_native = parameter_string.substr(switch_start);
+ } else {
+ switch_native = parameter_string.substr(
+ switch_start, equals_position - switch_start);
+ *switch_value = parameter_string.substr(equals_position + 1);
+ }
#if defined(OS_WIN)
-CommandLine::CommandLine(const wstring& command_line)
- : we_own_data_(true),
- data_(new Data(command_line)) {
-}
-#elif defined(OS_POSIX)
-CommandLine::CommandLine(const int argc, const char* const* argv)
- : we_own_data_(true),
- data_(new Data(argc, argv)) {
-}
+ Lowercase(&switch_native);
+ *switch_string = WideToASCII(switch_native);
+#else
+ *switch_string = switch_native;
+#endif
-CommandLine::CommandLine(const std::vector<std::string>& argv)
- : we_own_data_(true) {
- const char* argv_copy[argv.size()];
- for (size_t i = 0; i < argv.size(); i++) {
- argv_copy[i] = argv[i].c_str();
+ return true;
}
- data_ = new Data(argv.size(), argv_copy);
-}
-#endif
-CommandLine::~CommandLine() {
- if (we_own_data_)
- delete data_;
+ return false;
}
// static
-void CommandLine::SetArgcArgv(int argc, const char* const* argv) {
-#if !defined(OS_WIN)
- Singleton<Data>::get()->Init(argc, argv);
+void CommandLine::Init(int argc, const char* const* argv) {
+ DCHECK(current_process_commandline_ == NULL);
+#if defined(OS_WIN)
+ current_process_commandline_ = new CommandLine;
+ current_process_commandline_->ParseFromString(::GetCommandLineW());
+#elif defined(OS_POSIX)
+ current_process_commandline_ = new CommandLine(argc, argv);
#endif
}
-bool CommandLine::HasSwitch(const wstring& switch_string) const {
- wstring lowercased_switch(switch_string);
+bool CommandLine::HasSwitch(const std::wstring& switch_string) const {
+ std::wstring lowercased_switch(switch_string);
+#if defined(OS_WIN)
Lowercase(&lowercased_switch);
- return data_->switches().find(lowercased_switch) != data_->switches().end();
+#endif
+ return switches_.find(WideToASCII(lowercased_switch)) != switches_.end();
}
-wstring CommandLine::GetSwitchValue(const wstring& switch_string) const {
- wstring lowercased_switch(switch_string);
+std::wstring CommandLine::GetSwitchValue(
+ const std::wstring& switch_string) const {
+ std::wstring lowercased_switch(switch_string);
+#if defined(OS_WIN)
Lowercase(&lowercased_switch);
+#endif
- const map<wstring, wstring>::const_iterator result =
- data_->switches().find(lowercased_switch);
+ std::map<std::string, StringType>::const_iterator result =
+ switches_.find(WideToASCII(lowercased_switch));
- if (result == data_->switches().end()) {
+ if (result == switches_.end()) {
return L"";
} else {
+#if defined(OS_WIN)
return result->second;
+#else
+ return ASCIIToWide(result->second);
+#endif
}
}
-size_t CommandLine::GetLooseValueCount() const {
- return data_->loose_values().size();
-}
-
-CommandLine::LooseValueIterator CommandLine::GetLooseValuesBegin() const {
- return data_->loose_values().begin();
+#if defined(OS_WIN)
+std::vector<std::wstring> CommandLine::GetLooseValues() const {
+ return loose_values_;
}
-
-CommandLine::LooseValueIterator CommandLine::GetLooseValuesEnd() const {
- return data_->loose_values().end();
+std::wstring CommandLine::program() const {
+ return program_;
}
-
-std::wstring CommandLine::command_line_string() const {
- return data_->command_line_string();
+#else
+std::vector<std::wstring> CommandLine::GetLooseValues() const {
+ std::vector<std::wstring> values;
+ for (size_t i = 0; i < loose_values_.size(); ++i)
+ values.push_back(ASCIIToWide(loose_values_[i]));
+ return values;
}
-
-#if defined(OS_POSIX)
-const std::vector<std::string>& CommandLine::argv() const {
- return data_->argv();
+std::wstring CommandLine::program() const {
+ DCHECK(argv_.size() > 0);
+ return ASCIIToWide(argv_[0]);
}
#endif
-std::wstring CommandLine::program() const {
- return data_->program();
-}
// static
-wstring CommandLine::PrefixedSwitchString(const wstring& switch_string) {
+std::wstring CommandLine::PrefixedSwitchString(
+ const std::wstring& switch_string) {
return StringPrintf(L"%ls%ls",
kSwitchPrefixes[0],
switch_string.c_str());
}
// static
-wstring CommandLine::PrefixedSwitchStringWithValue(
- const wstring& switch_string, const wstring& value_string) {
+std::wstring CommandLine::PrefixedSwitchStringWithValue(
+ const std::wstring& switch_string, const std::wstring& value_string) {
if (value_string.empty()) {
return PrefixedSwitchString(switch_string);
}
@@ -324,20 +250,17 @@ wstring CommandLine::PrefixedSwitchStringWithValue(
value_string.c_str());
}
-// static
-void CommandLine::AppendSwitch(wstring* command_line_string,
- const wstring& switch_string) {
- DCHECK(command_line_string);
- wstring prefixed_switch_string = PrefixedSwitchString(switch_string);
- command_line_string->append(L" ");
- command_line_string->append(prefixed_switch_string);
+#if defined(OS_WIN)
+void CommandLine::AppendSwitch(const std::wstring& 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"";
}
-// static
-void CommandLine::AppendSwitchWithValue(wstring* command_line_string,
- const wstring& switch_string,
- const wstring& value_string) {
- wstring value_string_edit;
+void CommandLine::AppendSwitchWithValue(const std::wstring& switch_string,
+ const std::wstring& value_string) {
+ std::wstring value_string_edit;
// NOTE(jhughes): If the value contains a quotation mark at one
// end but not both, you may get unusable output.
@@ -351,10 +274,65 @@ void CommandLine::AppendSwitchWithValue(wstring* command_line_string,
value_string_edit = value_string;
}
- wstring combined_switch_string =
+ std::wstring combined_switch_string =
PrefixedSwitchStringWithValue(switch_string, value_string_edit);
- command_line_string->append(L" ");
- command_line_string->append(combined_switch_string);
+ command_line_string_.append(L" ");
+ command_line_string_.append(combined_switch_string);
+
+ switches_[WideToASCII(switch_string)] = value_string;
+}
+
+void CommandLine::AppendLooseValue(const std::wstring& value) {
+ // TODO(evan): quoting?
+ command_line_string_.append(L" ");
+ command_line_string_.append(value);
+}
+
+void CommandLine::AppendArguments(const CommandLine& other,
+ bool include_program) {
+ // Verify include_program is used correctly.
+ // Logic could be shorter but this is clearer.
+ DCHECK(include_program ? !other.program().empty() : other.program().empty());
+ command_line_string_ += L" " + other.command_line_string_;
+ std::map<std::string, StringType>::const_iterator i;
+ for (i = other.switches_.begin(); i != other.switches_.end(); ++i)
+ switches_[i->first] = i->second;
}
+#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::AppendSwitchWithValue(const std::wstring& switch_string,
+ const std::wstring& value_string) {
+ std::string ascii_switch = WideToASCII(switch_string);
+ std::string ascii_value = WideToASCII(value_string);
+
+ argv_.push_back(kSwitchPrefixes[0] + ascii_switch +
+ kSwitchValueSeparator + ascii_value);
+ switches_[ascii_switch] = ascii_value;
+}
+
+void CommandLine::AppendLooseValue(const std::wstring& value) {
+ argv_.push_back(WideToASCII(value));
+}
+
+void CommandLine::AppendArguments(const CommandLine& other,
+ bool include_program) {
+ // Verify include_program is used correctly.
+ // Logic could be shorter but this is clearer.
+ DCHECK(include_program ? !other.program().empty() : other.program().empty());
+
+ size_t first_arg = include_program ? 0 : 1;
+ for (size_t i = first_arg; i < other.argv_.size(); ++i)
+ argv_.push_back(other.argv_[i]);
+ std::map<std::string, StringType>::const_iterator i;
+ for (i = other.switches_.begin(); i != other.switches_.end(); ++i)
+ switches_[i->first] = i->second;
+}
+#endif
+
diff --git a/base/command_line.h b/base/command_line.h
index 56aa2fc..f1a2005 100644
--- a/base/command_line.h
+++ b/base/command_line.h
@@ -2,46 +2,60 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This file contains a class that can be used to extract the salient
-// elements of a command line in a relatively lightweight manner.
+// This class works with command lines: building and parsing.
// Switches can optionally have a value attached using an equals sign,
// as in "-switch=value". Arguments that aren't prefixed with a
-// switch prefix are considered "loose parameters". Switch names
-// are case-insensitive. An argument of "--" will terminate switch parsing,
-// causing everything after to be considered as loose parameters.
+// switch prefix are considered "loose parameters". Switch names are
+// case-insensitive. An argument of "--" will terminate switch
+// parsing, causing everything after to be considered as loose
+// parameters.
+
+// There is a singleton read-only CommandLine that represents the command
+// line that the current process was started with. It must be initialized
+// in main() (or whatever the platform's equivalent function is).
#ifndef BASE_COMMAND_LINE_H_
#define BASE_COMMAND_LINE_H_
+#include "build/build_config.h"
+
#include <map>
#include <string>
#include <vector>
#include "base/basictypes.h"
+#include "base/logging.h"
#include "base/scoped_ptr.h"
class CommandLine {
public:
- // Creates a parsed version of the command line used to launch
- // the current process.
- CommandLine();
-
#if defined(OS_WIN)
// Creates a parsed version of the given command-line string.
- // The program name is assumed to be the first item in the string.
- CommandLine(const std::wstring& command_line);
+ // The program name is assumed to be the first item in the string.
+ void ParseFromString(const std::wstring& command_line);
#elif defined(OS_POSIX)
+ // Initialize from an argv vector (or directly from main()'s argv).
CommandLine(int argc, const char* const* argv);
- CommandLine(const std::vector<std::string>& argv);
+ explicit CommandLine(const std::vector<std::string>& argv);
#endif
- ~CommandLine();
+ // Construct a new, empty command line.
+ // |program| is the name of the program to run (aka argv[0]).
+ // TODO(port): should be a FilePath.
+ 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
+ // line, but it still must be called to set up the command line.
+ static void Init(int argc, const char* const* argv);
- // On non-Windows platforms, main() must call SetArgcArgv() before accessing
- // any members of this class.
- // On Windows, this call is a no-op (we instead parse GetCommandLineW()
- // directly) because we don't trust the CRT's parsing of the command line.
- static void SetArgcArgv(int argc, const char* const* argv);
+ // Get the singleton CommandLine representing the current process's
+ // command line.
+ static const CommandLine* ForCurrentProcess() {
+ DCHECK(current_process_commandline_);
+ return current_process_commandline_;
+ }
// Returns true if this command line contains the given switch.
// (Switch names are case-insensitive.)
@@ -52,40 +66,25 @@ class CommandLine {
// the empty string.
std::wstring GetSwitchValue(const std::wstring& switch_string) const;
- // Returns the number of "loose values" found in the command line.
- // Loose values are arguments that aren't switches.
- // (The program name is also excluded from the set of loose values.)
- size_t GetLooseValueCount() const;
-
- typedef std::vector<std::wstring>::const_iterator LooseValueIterator;
-
- // Returns a const_iterator to the list of loose values.
- LooseValueIterator GetLooseValuesBegin() const;
-
- // Returns the end const_iterator for the list of loose values.
- LooseValueIterator GetLooseValuesEnd() const;
+ // Get the remaining arguments to the command.
+ // WARNING: this is incorrect on POSIX; we must do string conversions.
+ std::vector<std::wstring> GetLooseValues() const;
- // Simply returns the original command line string.
- std::wstring command_line_string() const;
-
-#if defined(OS_POSIX)
+#if defined(OS_WIN)
+ // Returns the original command line string.
+ const std::wstring& command_line_string() const {
+ return command_line_string_;
+ }
+#elif defined(OS_POSIX)
// Returns the original command line string as a vector of strings.
- const std::vector<std::string>& argv() const;
+ const std::vector<std::string>& argv() const {
+ return argv_;
+ }
#endif
// Returns the program part of the command line string (the first item).
std::wstring program() const;
- // An array containing the prefixes that identify an argument as
- // a switch.
- static const wchar_t* const kSwitchPrefixes[];
-
- // The string that's used to separate switches from their values.
- static const wchar_t kSwitchValueSeparator[];
-
- // Treat everything after this argument as loose parameters.
- static const wchar_t kSwitchTerminator[];
-
// Return a copy of the string prefixed with a switch prefix.
// Used internally.
static std::wstring PrefixedSwitchString(const std::wstring& switch_string);
@@ -98,27 +97,69 @@ class CommandLine {
// Appends the given switch string (preceded by a space and a switch
// prefix) to the given string.
- static void AppendSwitch(std::wstring* command_line_string,
- const std::wstring& switch_string);
+ void AppendSwitch(const std::wstring& switch_string);
// Appends the given switch string (preceded by a space and a switch
// prefix) to the given string, with the given value attached.
- static void AppendSwitchWithValue(std::wstring* command_line_string,
- const std::wstring& switch_string,
- const std::wstring& value_string);
+ void AppendSwitchWithValue(const std::wstring& switch_string,
+ const std::wstring& value_string);
+
+ // Append a loose value to the command line.
+ void AppendLooseValue(const std::wstring& value);
+
+ // Append the arguments from another command line to this one.
+ // If |include_program| is true, include |other|'s program as well.
+ void AppendArguments(const CommandLine& other,
+ bool include_program);
private:
- class Data;
+ CommandLine() {}
+
+ // The singleton CommandLine instance representing the current process's
+ // command line.
+ static CommandLine* current_process_commandline_;
+
+ // We store a platform-native version of the command line, used when building
+ // up a new command line to be executed. This ifdef delimits that code.
+
+#if defined(OS_WIN)
+ // The quoted, space-separated command-line string.
+ std::wstring command_line_string_;
+
+ // The name of the program.
+ std::wstring program_;
+
+ // The type of native command line arguments.
+ typedef std::wstring StringType;
+
+#elif defined(OS_POSIX)
+ // The argv array, with the program name in argv_[0].
+ std::vector<std::string> argv_;
+
+ // The type of native command line arguments.
+ typedef std::string StringType;
+
+ // Shared by the two POSIX constructor forms. Initalize from argv_.
+ void InitFromArgv();
+#endif
+
+ // Returns true and fills in |switch_string| and |switch_value|
+ // if |parameter_string| represents a switch.
+ static bool IsSwitch(const StringType& parameter_string,
+ std::string* switch_string,
+ StringType* switch_value);
+
+ // Parsed-out values.
+ std::map<std::string, StringType> switches_;
- // True if we are responsible for deleting our |data_| pointer. In some cases
- // we cache the result of parsing the command line and |data_|'s lifetime is
- // managed by someone else (e.g., the |Singleton| class).
- bool we_own_data_;
+ // Non-switch command-line arguments.
+ std::vector<StringType> loose_values_;
- // A pointer to the parsed version of the command line.
- Data* data_;
-
- DISALLOW_EVIL_CONSTRUCTORS(CommandLine);
+ // We allow copy constructors, because a common pattern is to grab a
+ // copy of the current process's command line and then add some
+ // flags to it. E.g.:
+ // CommandLine cl(*CommandLine::ForCurrentProcess());
+ // cl.AppendSwitch(...);
};
#endif // BASE_COMMAND_LINE_H_
diff --git a/base/command_line_unittest.cc b/base/command_line_unittest.cc
index 504c852..563b060 100644
--- a/base/command_line_unittest.cc
+++ b/base/command_line_unittest.cc
@@ -11,22 +11,19 @@
#include "base/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace {
- class CommandLineTest : public testing::Test {
- };
-};
-
TEST(CommandLineTest, CommandLineConstructor) {
-#ifdef OS_WIN
- CommandLine cl(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 "
- L"-- -- --not-a-switch "
- L"\"in the time of submarines...\"");
+#if defined(OS_WIN)
+ CommandLine cl(L"");
+ cl.ParseFromString(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 "
+ L"-- -- --not-a-switch "
+ L"\"in the time of submarines...\"");
+ EXPECT_FALSE(cl.command_line_string().empty());
#elif defined(OS_POSIX)
- const char* argv[] = {"program", "--foo=", "-bAr",
- "-Spaetzel=pierogi", "-Baz", "flim",
+ const char* argv[] = {"program", "--foo=", "-bar",
+ "-spaetzel=pierogi", "-baz", "flim",
"--other-switches=--dog=canine --cat=feline",
"-spaetzle=Crepe", "-=loosevalue", "flan",
"--input-translation=45--output-rotation",
@@ -34,7 +31,6 @@ TEST(CommandLineTest, CommandLineConstructor) {
"in the time of submarines..."};
CommandLine cl(arraysize(argv), argv);
#endif
- EXPECT_FALSE(cl.command_line_string().empty());
EXPECT_FALSE(cl.HasSwitch(L"cruller"));
EXPECT_FALSE(cl.HasSwitch(L"flim"));
EXPECT_FALSE(cl.HasSwitch(L"program"));
@@ -50,7 +46,9 @@ TEST(CommandLineTest, CommandLineConstructor) {
EXPECT_TRUE(cl.HasSwitch(L"bar"));
EXPECT_TRUE(cl.HasSwitch(L"baz"));
EXPECT_TRUE(cl.HasSwitch(L"spaetzle"));
+#if defined(OS_WIN)
EXPECT_TRUE(cl.HasSwitch(L"SPAETZLE"));
+#endif
EXPECT_TRUE(cl.HasSwitch(L"other-switches"));
EXPECT_TRUE(cl.HasSwitch(L"input-translation"));
@@ -61,9 +59,10 @@ TEST(CommandLineTest, CommandLineConstructor) {
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(5U, cl.GetLooseValueCount());
+ std::vector<std::wstring> loose_values = cl.GetLooseValues();
+ ASSERT_EQ(5U, loose_values.size());
- CommandLine::LooseValueIterator iter = cl.GetLooseValuesBegin();
+ std::vector<std::wstring>::const_iterator iter = loose_values.begin();
EXPECT_EQ(L"flim", *iter);
++iter;
EXPECT_EQ(L"flan", *iter);
@@ -74,9 +73,9 @@ TEST(CommandLineTest, CommandLineConstructor) {
++iter;
EXPECT_EQ(L"in the time of submarines...", *iter);
++iter;
- EXPECT_TRUE(iter == cl.GetLooseValuesEnd());
+ EXPECT_TRUE(iter == loose_values.end());
#if defined(OS_POSIX)
- std::vector<std::string> argvec = cl.argv();
+ const std::vector<std::string>& argvec = cl.argv();
for (size_t i = 0; i < argvec.size(); i++) {
EXPECT_EQ(0, argvec[i].compare(argv[i]));
@@ -84,27 +83,20 @@ TEST(CommandLineTest, CommandLineConstructor) {
#endif
}
-// These test the command line used to invoke the unit test.
-TEST(CommandLineTest, DefaultConstructor) {
- CommandLine cl;
- EXPECT_FALSE(cl.command_line_string().empty());
- EXPECT_FALSE(cl.program().empty());
-}
-
// Tests behavior with an empty input string.
TEST(CommandLineTest, EmptyString) {
#if defined(OS_WIN)
CommandLine cl(L"");
+ EXPECT_TRUE(cl.command_line_string().empty());
+ EXPECT_TRUE(cl.program().empty());
#elif defined(OS_POSIX)
CommandLine cl(0, NULL);
EXPECT_TRUE(cl.argv().size() == 0);
#endif
- EXPECT_TRUE(cl.command_line_string().empty());
- EXPECT_TRUE(cl.program().empty());
- EXPECT_EQ(0U, cl.GetLooseValueCount());
+ EXPECT_EQ(0U, cl.GetLooseValues().size());
}
-// Test static functions for appending switches to a command line.
+// Test methods for appending switches to a command line.
TEST(CommandLineTest, AppendSwitches) {
std::wstring switch1 = L"switch1";
std::wstring switch2 = L"switch2";
@@ -115,31 +107,24 @@ TEST(CommandLineTest, AppendSwitches) {
std::wstring value4 = L"\"a value with quotes\"";
#if defined(OS_WIN)
- std::wstring cl_string = L"Program";
- CommandLine::AppendSwitch(&cl_string, switch1);
- CommandLine::AppendSwitchWithValue(&cl_string, switch2, value);
- CommandLine::AppendSwitchWithValue(&cl_string, switch3, value3);
- CommandLine::AppendSwitchWithValue(&cl_string, switch4, value4);
- CommandLine cl(cl_string);
+ CommandLine cl(L"Program");
#elif defined(OS_POSIX)
std::vector<std::string> argv;
argv.push_back(std::string("Program"));
- argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchString(switch1)));
- argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchStringWithValue(
- switch2, value)));
- argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchStringWithValue(
- switch3, value3)));
- argv.push_back(WideToUTF8(CommandLine::PrefixedSwitchStringWithValue(
- switch4, value4.substr(1, value4.length() - 2))));
CommandLine cl(argv);
#endif
+ cl.AppendSwitch(switch1);
+ cl.AppendSwitchWithValue(switch2, value);
+ cl.AppendSwitchWithValue(switch3, value3);
+ cl.AppendSwitchWithValue(switch4, value4);
+
EXPECT_TRUE(cl.HasSwitch(switch1));
EXPECT_TRUE(cl.HasSwitch(switch2));
EXPECT_EQ(value, cl.GetSwitchValue(switch2));
EXPECT_TRUE(cl.HasSwitch(switch3));
EXPECT_EQ(value3, cl.GetSwitchValue(switch3));
EXPECT_TRUE(cl.HasSwitch(switch4));
- EXPECT_EQ(value4.substr(1, value4.length() - 2), cl.GetSwitchValue(switch4));
+ EXPECT_EQ(value4, cl.GetSwitchValue(switch4));
}
diff --git a/base/logging.cc b/base/logging.cc
index 7ddbe15..cc9c7db 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -228,7 +228,8 @@ void InitLogMutex() {
void InitLogging(const PathChar* new_log_file, LoggingDestination logging_dest,
LogLockingState lock_log, OldFileDeletionState delete_old) {
- g_enable_dcheck = CommandLine().HasSwitch(switches::kEnableDCHECK);
+ g_enable_dcheck =
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableDCHECK);
if (log_file) {
// calling InitLogging twice or after some log call has already opened the
diff --git a/base/multiprocess_test.h b/base/multiprocess_test.h
index 4f3200e..99c2c79 100644
--- a/base/multiprocess_test.h
+++ b/base/multiprocess_test.h
@@ -81,7 +81,6 @@ class MultiProcessTest : public PlatformTest {
bool debug_on_start) {
return SpawnChildImpl(procname, fds_to_map, debug_on_start);
}
-
#endif
private:
@@ -89,37 +88,31 @@ class MultiProcessTest : public PlatformTest {
base::ProcessHandle SpawnChildImpl(
const std::wstring& procname,
bool debug_on_start) {
- CommandLine cl;
+ CommandLine cl(*CommandLine::ForCurrentProcess());
base::ProcessHandle handle = static_cast<base::ProcessHandle>(NULL);
- std::wstring clstr = cl.command_line_string();
- CommandLine::AppendSwitchWithValue(&clstr, kRunClientProcess, procname);
+ cl.AppendSwitchWithValue(kRunClientProcess, procname);
- if (debug_on_start) {
- CommandLine::AppendSwitch(&clstr, switches::kDebugOnStart);
- }
+ if (debug_on_start)
+ cl.AppendSwitch(switches::kDebugOnStart);
- base::LaunchApp(clstr, false, true, &handle);
+ base::LaunchApp(cl, false, true, &handle);
return handle;
}
#elif defined(OS_POSIX)
+ // TODO(port): with the CommandLine refactoring, this code is very similar
+ // to the Windows code. Investigate whether this can be made shorter.
base::ProcessHandle SpawnChildImpl(
const std::wstring& procname,
const base::file_handle_mapping_vector& fds_to_map,
bool debug_on_start) {
- CommandLine cl;
+ CommandLine cl(*CommandLine::ForCurrentProcess());
base::ProcessHandle handle = static_cast<base::ProcessHandle>(NULL);
+ cl.AppendSwitchWithValue(kRunClientProcess, procname);
- std::vector<std::string> clvec(cl.argv());
- std::wstring wswitchstr =
- CommandLine::PrefixedSwitchStringWithValue(kRunClientProcess,
- procname);
- if (debug_on_start) {
- CommandLine::AppendSwitch(&wswitchstr, switches::kDebugOnStart);
- }
+ if (debug_on_start)
+ cl.AppendSwitch(switches::kDebugOnStart);
- std::string switchstr = WideToUTF8(wswitchstr);
- clvec.push_back(switchstr.c_str());
- base::LaunchApp(clvec, fds_to_map, false, &handle);
+ base::LaunchApp(cl.argv(), fds_to_map, false, &handle);
return handle;
}
#endif
diff --git a/base/perf_test_suite.h b/base/perf_test_suite.h
index 444a099..ea6846a 100644
--- a/base/perf_test_suite.h
+++ b/base/perf_test_suite.h
@@ -23,7 +23,8 @@ class PerfTestSuite : public TestSuite {
// Initialize the perf timer log
FilePath log_path;
- std::wstring log_file = CommandLine().GetSwitchValue(L"log-file");
+ std::wstring log_file =
+ CommandLine::ForCurrentProcess()->GetSwitchValue(L"log-file");
if (log_file.empty()) {
FilePath exe;
PathService::Get(base::FILE_EXE, &exe);
diff --git a/base/process_util.h b/base/process_util.h
index 7eabdbe..ae38c5a 100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -91,8 +91,6 @@ bool LaunchApp(const std::wstring& cmdline,
bool wait, bool start_hidden, ProcessHandle* process_handle);
#elif defined(OS_POSIX)
// Runs the application specified in argv[0] with the command line argv.
-// Both the elements of argv and argv itself must be terminated with a null
-// byte.
// Before launching all FDs open in the parent process will be marked as
// close-on-exec. |fds_to_remap| defines a mapping of src fd->dest fd to
// propagate FDs into the child process.
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index aa8ba94..d23f78c 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -76,7 +76,7 @@ bool LaunchApp(const std::vector<std::string>& argv,
if (wait)
waitpid(pid, 0, 0);
- if(process_handle)
+ if (process_handle)
*process_handle = pid;
}
@@ -85,9 +85,9 @@ bool LaunchApp(const std::vector<std::string>& argv,
return retval;
}
-
bool LaunchApp(const CommandLine& cl,
- bool wait, bool start_hidden, ProcessHandle* process_handle) {
+ bool wait, bool start_hidden,
+ ProcessHandle* process_handle) {
file_handle_mapping_vector no_files;
return LaunchApp(cl.argv(), no_files, wait, process_handle);
}
@@ -101,7 +101,8 @@ bool DidProcessCrash(ProcessHandle handle) {
if (WIFSIGNALED(status)) {
int signum = WTERMSIG(status);
- return (signum == SIGSEGV || signum == SIGILL || signum == SIGABRT || signum == SIGFPE);
+ return (signum == SIGSEGV || signum == SIGILL || signum == SIGABRT ||
+ signum == SIGFPE);
}
if (WIFEXITED(status)) {
diff --git a/base/test_suite.h b/base/test_suite.h
index 01b39fa..2aacecd 100644
--- a/base/test_suite.h
+++ b/base/test_suite.h
@@ -31,7 +31,7 @@ class TestSuite {
public:
TestSuite(int argc, char** argv) {
base::EnableTerminationOnHeapCorruption();
- CommandLine::SetArgcArgv(argc, argv);
+ CommandLine::Init(argc, argv);
testing::InitGoogleTest(&argc, argv);
#if defined(OS_LINUX)
gtk_init_check(&argc, &argv);
@@ -48,7 +48,8 @@ class TestSuite {
base::ScopedNSAutoreleasePool scoped_pool;
Initialize();
- std::wstring client_func = CommandLine().GetSwitchValue(kRunClientProcess);
+ std::wstring client_func =
+ CommandLine::ForCurrentProcess()->GetSwitchValue(kRunClientProcess);
// Check to see if we are being run as a client process.
if (!client_func.empty()) {
// Convert our function name to a usable string for GetProcAddress.
@@ -101,7 +102,7 @@ class TestSuite {
#if defined(OS_WIN)
// In some cases, we do not want to see standard error dialogs.
if (!IsDebuggerPresent() &&
- !CommandLine().HasSwitch(L"show-error-dialogs")) {
+ !CommandLine::ForCurrentProcess()->HasSwitch(L"show-error-dialogs")) {
SuppressErrorDialogs();
logging::SetLogAssertHandler(UnitTestAssertHandler);
}
diff --git a/chrome/app/breakpad.cc b/chrome/app/breakpad.cc
index c0245ad..70aaf97 100644
--- a/chrome/app/breakpad.cc
+++ b/chrome/app/breakpad.cc
@@ -163,7 +163,7 @@ static DWORD __stdcall InitCrashReporterThread(void* param) {
// we do it here so it can run in a separate thread.
info->custom_info = GetCustomInfo(info->dll_path, info->process_type);
- CommandLine command;
+ const CommandLine& command = *CommandLine::ForCurrentProcess();
bool full_dump = command.HasSwitch(switches::kFullMemoryCrashReport);
bool use_crash_service = command.HasSwitch(switches::kNoErrorDialogs) ||
GetEnvironmentVariable(L"CHROME_HEADLESS", NULL, 0);
@@ -238,7 +238,7 @@ void InitDefaultCrashCallback() {
}
void InitCrashReporter(std::wstring dll_path) {
- CommandLine command;
+ const CommandLine& command = *CommandLine::ForCurrentProcess();
if (!command.HasSwitch(switches::kDisableBreakpad)) {
// Disable the message box for assertions.
_CrtSetReportMode(_CRT_ASSERT, 0);
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index 48d5b21..29429d0 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -204,10 +204,12 @@ int ChromeMain(int argc, const char** argv) {
base::ScopedNSAutoreleasePool autorelease_pool;
// Initialize the command line.
-#if defined(OS_POSIX)
- CommandLine::SetArgcArgv(argc, argv);
+#if defined(OS_WIN)
+ CommandLine::Init(0, NULL);
+#else
+ CommandLine::Init(argc, argv);
#endif
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
SetupCRT(parsed_command_line);
diff --git a/chrome/app/chrome_exe_main.cc b/chrome/app/chrome_exe_main.cc
index 85a3462..6399198 100644
--- a/chrome/app/chrome_exe_main.cc
+++ b/chrome/app/chrome_exe_main.cc
@@ -42,6 +42,8 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
if (!sandbox_info.broker_services)
sandbox_info.target_services = sandbox::SandboxFactory::GetTargetServices();
+ CommandLine::Init(0, NULL);
+
const wchar_t* dll_name = L"chrome.dll";
#if defined(GOOGLE_CHROME_BUILD)
google_update::GoogleUpdateClient client;
diff --git a/chrome/app/chrome_main_uitest.cc b/chrome/app/chrome_main_uitest.cc
index 4217c3b..4689d27 100644
--- a/chrome/app/chrome_main_uitest.cc
+++ b/chrome/app/chrome_main_uitest.cc
@@ -35,7 +35,7 @@ TEST_F(ChromeMainTest, SecondLaunch) {
include_testing_id_ = false;
use_existing_browser_ = true;
- LaunchBrowser(std::wstring(), false);
+ LaunchBrowser(CommandLine(L""), false);
int window_count;
ASSERT_TRUE(automation()->WaitForWindowCountToChange(1, &window_count,
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 54f3789..3e12603 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -321,7 +321,7 @@ void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) {
}
gfx::Rect Browser::GetSavedWindowBounds() const {
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode);
if (record_mode || playback_mode) {
@@ -343,7 +343,7 @@ gfx::Rect Browser::GetSavedWindowBounds() const {
// TODO(beng): obtain maximized state some other way so we don't need to go
// through all this hassle.
bool Browser::GetSavedMaximizedState() const {
- if (CommandLine().HasSwitch(switches::kStartMaximized))
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized))
return true;
gfx::Rect restored_bounds;
@@ -1489,7 +1489,7 @@ void Browser::OpenURLFromTab(TabContents* source,
// TODO(creis): should this apply to applications?
SiteInstance* instance = NULL;
// Don't use this logic when "--process-per-tab" is specified.
- if (!CommandLine().HasSwitch(switches::kProcessPerTab)) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab)) {
if (current_tab) {
const WebContents* const web_contents = current_tab->AsWebContents();
if (web_contents) {
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index eba5365..3a0794e 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -403,7 +403,8 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
DCHECK(profile);
profile_ = profile;
- CommandLine parsed_command_line(command_line_);
+ CommandLine parsed_command_line(L"");
+ parsed_command_line.ParseFromString(command_line_);
if (parsed_command_line.HasSwitch(switches::kDnsLogDetails))
chrome_browser_net::EnableDnsDetailedLog(true);
if (parsed_command_line.HasSwitch(switches::kDnsPrefetchDisable))
@@ -569,30 +570,27 @@ void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary(
std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine(
const CommandLine& command_line, Profile* profile) {
std::vector<GURL> urls;
- if (command_line.GetLooseValueCount() > 0) {
- for (CommandLine::LooseValueIterator iter =
- command_line.GetLooseValuesBegin();
- iter != command_line.GetLooseValuesEnd(); ++iter) {
- std::wstring value = *iter;
- // Handle Vista way of searching - "? <search-term>"
- if (value.find(L"? ") == 0) {
- const TemplateURL* const default_provider =
- profile->GetTemplateURLModel()->GetDefaultSearchProvider();
- if (!default_provider || !default_provider->url()) {
- // No search provider available. Just treat this as regular URL.
- urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_,
- value)));
- continue;
- }
- const TemplateURLRef* const search_url = default_provider->url();
- DCHECK(search_url->SupportsReplacement());
- urls.push_back(GURL(search_url->ReplaceSearchTerms(*default_provider,
- value.substr(2), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- std::wstring())));
- } else {
- // This will create a file URL or a regular URL.
- urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_, value)));
+ std::vector<std::wstring> params = command_line.GetLooseValues();
+ for (size_t i = 0; i < params.size(); ++i) {
+ const std::wstring& value = params[i];
+ // Handle Vista way of searching - "? <search-term>"
+ if (value.find(L"? ") == 0) {
+ const TemplateURL* const default_provider =
+ profile->GetTemplateURLModel()->GetDefaultSearchProvider();
+ if (!default_provider || !default_provider->url()) {
+ // No search provider available. Just treat this as regular URL.
+ urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_,
+ value)));
+ continue;
}
+ const TemplateURLRef* const search_url = default_provider->url();
+ DCHECK(search_url->SupportsReplacement());
+ urls.push_back(GURL(search_url->ReplaceSearchTerms(*default_provider,
+ value.substr(2), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
+ std::wstring())));
+ } else {
+ // This will create a file URL or a regular URL.
+ urls.push_back(GURL(URLFixerUpper::FixupRelativeFile(cur_dir_, value)));
}
}
return urls;
@@ -633,7 +631,7 @@ bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line,
CreateAutomationProvider<TestingAutomationProvider>(
testing_channel_id,
profile,
- std::max(static_cast<int>(parsed_command_line.GetLooseValueCount()),
+ std::max(static_cast<int>(parsed_command_line.GetLooseValues().size()),
1));
}
}
@@ -651,7 +649,7 @@ bool BrowserInit::ProcessCommandLine(const CommandLine& parsed_command_line,
// If there are any loose parameters, we expect each one to generate a
// new tab; if there are none then we have no tabs
size_t expected_tabs =
- std::max(static_cast<int>(parsed_command_line.GetLooseValueCount()),
+ std::max(static_cast<int>(parsed_command_line.GetLooseValues().size()),
0);
if (expected_tabs == 0) {
silent_launch = true;
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 2645013..29d984e 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -176,7 +176,7 @@ StringPiece NetResourceProvider(int key) {
// Main routine for running as the Browser process.
int BrowserMain(const MainFunctionParams& parameters) {
- CommandLine& parsed_command_line = parameters.command_line_;
+ const CommandLine& parsed_command_line = parameters.command_line_;
// WARNING: If we get a WM_ENDSESSION objects created on the stack here
// are NOT deleted. If you need something to run during WM_ENDSESSION add it
@@ -327,10 +327,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
// --user-data-dir switch. The last flag of the same name wins.
// TODO(tc): It would be nice to remove the flag we don't want, but that
// sounds risky if we parse differently than CommandLineToArgvW.
- std::wstring new_command_line =
- parsed_command_line.command_line_string();
- CommandLine::AppendSwitchWithValue(&new_command_line,
- switches::kUserDataDir, user_data_dir);
+ CommandLine new_command_line = parsed_command_line;
+ new_command_line.AppendSwitchWithValue(switches::kUserDataDir,
+ user_data_dir);
base::LaunchApp(new_command_line, false, false, NULL);
}
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 20188cc1..3fa75d5 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -82,7 +82,7 @@ class BrowserProcessSubThread : public ChromeThread {
} // namespace
-BrowserProcessImpl::BrowserProcessImpl(CommandLine& command_line)
+BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
: created_resource_dispatcher_host_(false),
created_metrics_service_(false),
created_io_thread_(false),
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 3b8732c..bcbb862 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -28,7 +28,7 @@ class NotificationService;
// Real implementation of BrowserProcess that creates and returns the services.
class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
public:
- BrowserProcessImpl(CommandLine& command_line);
+ BrowserProcessImpl(const CommandLine& command_line);
virtual ~BrowserProcessImpl();
virtual void EndSession();
diff --git a/chrome/browser/browsing_instance.cc b/chrome/browser/browsing_instance.cc
index 527feb1a..f15deca 100644
--- a/chrome/browser/browsing_instance.cc
+++ b/chrome/browser/browsing_instance.cc
@@ -17,10 +17,11 @@ bool BrowsingInstance::ShouldUseProcessPerSite(const GURL& url) {
// the case if the --process-per-site switch is specified, or in
// process-per-site-instance for particular sites (e.g., the new tab page).
- if (CommandLine().HasSwitch(switches::kProcessPerSite))
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(switches::kProcessPerSite))
return true;
- if (!CommandLine().HasSwitch(switches::kProcessPerTab)) {
+ if (!command_line.HasSwitch(switches::kProcessPerTab)) {
// We are not in process-per-site or process-per-tab, so we must be in the
// default (process-per-site-instance). Only use the process-per-site
// logic for particular sites that we want to consolidate.
diff --git a/chrome/browser/chrome_plugin_host.cc b/chrome/browser/chrome_plugin_host.cc
index 55f1dd1..f501764 100644
--- a/chrome/browser/chrome_plugin_host.cc
+++ b/chrome/browser/chrome_plugin_host.cc
@@ -640,8 +640,8 @@ CPProcessType STDCALL CPB_GetProcessType(CPID id) {
}
CPError STDCALL CPB_SendMessage(CPID id, const void *data, uint32 data_len) {
- CommandLine cmd;
- if (cmd.HasSwitch(switches::kGearsInRenderer)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kGearsInRenderer)) {
ChromePluginLib* plugin = ChromePluginLib::FromCPID(id);
CHECK(plugin);
diff --git a/chrome/browser/debugger/debugger_contents.cc b/chrome/browser/debugger/debugger_contents.cc
index a6dd254..c3d2e4b 100644
--- a/chrome/browser/debugger/debugger_contents.cc
+++ b/chrome/browser/debugger/debugger_contents.cc
@@ -40,7 +40,8 @@ class DebuggerHTMLSource : public ChromeURLDataManager::DataSource {
}
std::wstring debugger_path =
- CommandLine().GetSwitchValue(switches::kJavaScriptDebuggerPath);
+ CommandLine::ForCurrentProcess()->GetSwitchValue(
+ switches::kJavaScriptDebuggerPath);
std::string data_str;
if (!debugger_path.empty() && file_util::PathExists(debugger_path)) {
if (path.empty())
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index c6f4f29..8522a8b 100755
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -450,8 +450,8 @@ bool DecodeImportParams(const std::wstring& encoded,
bool FirstRun::ImportSettings(Profile* profile, int browser,
int items_to_import, HWND parent_window) {
- CommandLine cmdline;
- std::wstring import_cmd(cmdline.program());
+ const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
+ CommandLine import_cmd(cmdline.program());
// Propagate the following switches to the importer command line.
static const wchar_t* const switch_names[] = {
switches::kUserDataDir,
@@ -459,12 +459,12 @@ bool FirstRun::ImportSettings(Profile* profile, int browser,
};
for (int i = 0; i < arraysize(switch_names); ++i) {
if (cmdline.HasSwitch(switch_names[i])) {
- CommandLine::AppendSwitchWithValue(
- &import_cmd, switch_names[i],
+ import_cmd.AppendSwitchWithValue(
+ switch_names[i],
cmdline.GetSwitchValue(switch_names[i]));
}
}
- CommandLine::AppendSwitchWithValue(&import_cmd, switches::kImport,
+ import_cmd.CommandLine::AppendSwitchWithValue(switches::kImport,
EncodeImportParams(browser, items_to_import, parent_window));
// Time to launch the process that is going to do the import.
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h
index 4332b8b..676bd49 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -105,7 +105,7 @@ class Upgrade {
// so we don't fetch as we have no IO thread (see bug #1292702).
class FirstRunBrowserProcess : public BrowserProcessImpl {
public:
- FirstRunBrowserProcess(CommandLine& command_line)
+ FirstRunBrowserProcess(const CommandLine& command_line)
: BrowserProcessImpl(command_line) {
}
virtual ~FirstRunBrowserProcess() { }
diff --git a/chrome/browser/images_uitest.cc b/chrome/browser/images_uitest.cc
index cfe0938..0b5a4be 100644
--- a/chrome/browser/images_uitest.cc
+++ b/chrome/browser/images_uitest.cc
@@ -9,8 +9,10 @@
class ImagesTest : public UITest {
protected:
ImagesTest() : UITest() {
- launch_arguments_ = test_data_directory_;
- file_util::AppendToPath(&launch_arguments_, L"animated-gifs.html");
+ std::wstring path = test_data_directory_;
+ file_util::AppendToPath(&path, L"animated-gifs.html");
+ launch_arguments_ = CommandLine(L"");
+ launch_arguments_.AppendLooseValue(path);
}
};
diff --git a/chrome/browser/locale_tests_uitest.cc b/chrome/browser/locale_tests_uitest.cc
index 5c20f76..d707705 100644
--- a/chrome/browser/locale_tests_uitest.cc
+++ b/chrome/browser/locale_tests_uitest.cc
@@ -7,21 +7,21 @@
class LocaleTestsDa : public UITest {
public:
LocaleTestsDa() : UITest() {
- launch_arguments_.append(L" --lang=da");
+ launch_arguments_.AppendSwitchWithValue(L"lang", L"da");
}
};
class LocaleTestsHe : public UITest {
public:
LocaleTestsHe() : UITest() {
- launch_arguments_.append(L" --lang=he");
+ launch_arguments_.AppendSwitchWithValue(L"lang", L"he");
}
};
class LocaleTestsZhTw : public UITest {
public:
LocaleTestsZhTw() : UITest() {
- launch_arguments_.append(L" --lang=zh-tw");
+ launch_arguments_.AppendSwitchWithValue(L"lang", L"zh-tw");
}
};
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 5ba3f63..d834e57 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -23,7 +23,7 @@
static net::ProxyInfo* CreateProxyInfo() {
net::ProxyInfo* proxy_info = NULL;
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kProxyServer)) {
proxy_info = new net::ProxyInfo();
const std::wstring& proxy_server =
@@ -47,7 +47,7 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
net::HttpCache* cache =
new net::HttpCache(context->proxy_service_, disk_cache_path, 0);
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
bool record_mode = chrome::kRecordModeEnabled &&
command_line.HasSwitch(switches::kRecordMode);
bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc
index 50ca1b9..9da52d2 100644
--- a/chrome/browser/plugin_process_host.cc
+++ b/chrome/browser/plugin_process_host.cc
@@ -461,13 +461,11 @@ bool PluginProcessHost::Init(const FilePath& plugin_path,
if (!PathService::Get(base::FILE_EXE, &exe_path))
return false;
- std::wstring cmd_line(L"\"");
- cmd_line += exe_path;
- cmd_line += L"\"";
+ CommandLine cmd_line(exe_path);
if (logging::DialogsAreSuppressed())
- CommandLine::AppendSwitch(&cmd_line, switches::kNoErrorDialogs);
+ cmd_line.AppendSwitch(switches::kNoErrorDialogs);
- CommandLine browser_command_line;
+ const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
// propagate the following switches to the plugin command line (along with
// any associated values) if present in the browser command line
@@ -492,8 +490,8 @@ bool PluginProcessHost::Init(const FilePath& plugin_path,
for (int i = 0; i < arraysize(switch_names); ++i) {
if (browser_command_line.HasSwitch(switch_names[i])) {
- CommandLine::AppendSwitchWithValue(
- &cmd_line, switch_names[i],
+ cmd_line.AppendSwitchWithValue(
+ switch_names[i],
browser_command_line.GetSwitchValue(switch_names[i]));
}
}
@@ -501,26 +499,26 @@ bool PluginProcessHost::Init(const FilePath& plugin_path,
// If specified, prepend a launcher program to the command line.
std::wstring plugin_launcher =
browser_command_line.GetSwitchValue(switches::kPluginLauncher);
- if (!plugin_launcher.empty())
- cmd_line = plugin_launcher + L" " + cmd_line;
+ if (!plugin_launcher.empty()) {
+ CommandLine new_cmd_line = CommandLine(plugin_launcher);
+ new_cmd_line.AppendArguments(cmd_line, true);
+ cmd_line = new_cmd_line;
+ }
if (!locale.empty()) {
// Pass on the locale so the null plugin will use the right language in the
// prompt to install the desired plugin.
- CommandLine::AppendSwitchWithValue(&cmd_line, switches::kLang, locale);
+ cmd_line.AppendSwitchWithValue(switches::kLang, locale);
}
- CommandLine::AppendSwitchWithValue(&cmd_line,
- switches::kProcessType,
- switches::kPluginProcess);
+ cmd_line.AppendSwitchWithValue(switches::kProcessType,
+ switches::kPluginProcess);
- CommandLine::AppendSwitchWithValue(&cmd_line,
- switches::kProcessChannelID,
- channel_id_);
+ cmd_line.AppendSwitchWithValue(switches::kProcessChannelID,
+ channel_id_);
- CommandLine::AppendSwitchWithValue(&cmd_line,
- switches::kPluginPath,
- plugin_path.ToWStringHack());
+ cmd_line.AppendSwitchWithValue(switches::kPluginPath,
+ plugin_path.ToWStringHack());
bool in_sandbox = !browser_command_line.HasSwitch(switches::kNoSandbox) &&
browser_command_line.HasSwitch(switches::kSafePlugins);
@@ -550,8 +548,10 @@ bool PluginProcessHost::Init(const FilePath& plugin_path,
return false;
}
- result = broker_service->SpawnTarget(exe_path.c_str(),
- cmd_line.c_str(), policy, &target);
+ result =
+ broker_service->SpawnTarget(exe_path.c_str(),
+ cmd_line.command_line_string().c_str(),
+ policy, &target);
policy->Release();
if (sandbox::SBOX_ALL_OK != result)
return false;
diff --git a/chrome/browser/printing/printing_layout_uitest.cc b/chrome/browser/printing/printing_layout_uitest.cc
index 086c2b9..038ee5d 100644
--- a/chrome/browser/printing/printing_layout_uitest.cc
+++ b/chrome/browser/printing/printing_layout_uitest.cc
@@ -204,10 +204,7 @@ class PrintingLayoutTest : public PrintingTest<UITest> {
PrintingLayoutTest() {
emf_path_ = browser_directory_;
file_util::AppendToPath(&emf_path_, L"emf_dumps");
- std::wstring arg(L" --debug-print=\"");
- arg += emf_path_;
- arg += L"\"";
- launch_arguments_.append(arg);
+ launch_arguments_.AppendSwitchWithValue(L"debug-print", L'"' + emf_path_ + L'"');
show_window_ = true;
}
@@ -371,7 +368,7 @@ class PrintingLayoutTest : public PrintingTest<UITest> {
}
static bool GenerateFiles() {
- return CommandLine().HasSwitch(kGenerateSwitch);
+ return CommandLine::ForCurrentProcess()->HasSwitch(kGenerateSwitch);
}
const std::wstring& emf_path() const { return emf_path_; }
diff --git a/chrome/browser/render_view_context_menu_controller.cc b/chrome/browser/render_view_context_menu_controller.cc
index bdb34e7..307bae4 100644
--- a/chrome/browser/render_view_context_menu_controller.cc
+++ b/chrome/browser/render_view_context_menu_controller.cc
@@ -475,7 +475,7 @@ void RenderViewContextMenuController::ExecuteCommand(int id) {
}
bool RenderViewContextMenuController::IsDevCommandEnabled(int id) const {
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kAlwaysEnableDevTools))
return true;
diff --git a/chrome/browser/render_view_host_manager.cc b/chrome/browser/render_view_host_manager.cc
index 622df9e..05d07f5 100644
--- a/chrome/browser/render_view_host_manager.cc
+++ b/chrome/browser/render_view_host_manager.cc
@@ -232,7 +232,7 @@ void RenderViewHostManager::OnJavaScriptMessageBoxClosed(
bool RenderViewHostManager::ShouldTransitionCrossSite() {
// True if we are using process-per-site-instance (default) or
// process-per-site (kProcessPerSite).
- return !CommandLine().HasSwitch(switches::kProcessPerTab);
+ return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerTab);
}
SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry(
@@ -254,7 +254,7 @@ SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry(
// NOTE: This can be removed once we have a way to transition between
// RenderViews in response to a link click.
//
- if (CommandLine().HasSwitch(switches::kProcessPerSite) &&
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerSite) &&
entry.transition_type() == PageTransition::GENERATED)
return curr_instance;
diff --git a/chrome/browser/render_widget_host_view_win.cc b/chrome/browser/render_widget_host_view_win.cc
index 4fd0f18..0aa756d 100644
--- a/chrome/browser/render_widget_host_view_win.cc
+++ b/chrome/browser/render_widget_host_view_win.cc
@@ -79,7 +79,8 @@ RenderWidgetHostViewWin::RenderWidgetHostViewWin(RenderWidgetHost* widget)
activatable_(true) {
render_widget_host_->set_view(this);
renderer_accessible_ =
- CommandLine().HasSwitch(switches::kEnableRendererAccessibility);
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableRendererAccessibility);
}
RenderWidgetHostViewWin::~RenderWidgetHostViewWin() {
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 198d886..cb43eb9 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -167,7 +167,7 @@ bool BrowserRenderProcessHost::Init() {
widget_helper_,
profile()->GetSpellChecker());
- CommandLine browser_command_line;
+ const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
// setup IPC channel
std::wstring channel_id = GenerateRandomChannelID(this);
@@ -188,10 +188,9 @@ bool BrowserRenderProcessHost::Init() {
if (renderer_path.empty())
if (!GetRendererPath(&renderer_path))
return false;
- std::wstring cmd_line;
- cmd_line = L"\"" + renderer_path + L"\"";
+ CommandLine cmd_line(renderer_path);
if (logging::DialogsAreSuppressed())
- CommandLine::AppendSwitch(&cmd_line, switches::kNoErrorDialogs);
+ cmd_line.AppendSwitch(switches::kNoErrorDialogs);
// propagate the following switches to the renderer command line
// (along with any associated values) if present in the browser command line
@@ -229,15 +228,14 @@ bool BrowserRenderProcessHost::Init() {
for (int i = 0; i < arraysize(switch_names); ++i) {
if (browser_command_line.HasSwitch(switch_names[i])) {
- CommandLine::AppendSwitchWithValue(
- &cmd_line, switch_names[i],
+ cmd_line.AppendSwitchWithValue(switch_names[i],
browser_command_line.GetSwitchValue(switch_names[i]));
}
}
// Pass on the browser locale.
const std::wstring locale = g_browser_process->GetApplicationLocale();
- CommandLine::AppendSwitchWithValue(&cmd_line, switches::kLang, locale);
+ cmd_line.AppendSwitchWithValue(switches::kLang, locale);
bool in_sandbox = !browser_command_line.HasSwitch(switches::kNoSandbox);
if (browser_command_line.HasSwitch(switches::kInProcessPlugins)) {
@@ -249,19 +247,17 @@ bool BrowserRenderProcessHost::Init() {
DebugFlags::ProcessDebugFlags(&cmd_line,
DebugFlags::RENDERER,
in_sandbox);
- CommandLine::AppendSwitchWithValue(&cmd_line,
- switches::kProcessType,
- switches::kRendererProcess);
+ cmd_line.AppendSwitchWithValue(switches::kProcessType,
+ switches::kRendererProcess);
- CommandLine::AppendSwitchWithValue(&cmd_line,
- switches::kProcessChannelID,
- channel_id);
+ cmd_line.AppendSwitchWithValue(switches::kProcessChannelID,
+ channel_id);
const std::wstring& profile_path =
browser_command_line.GetSwitchValue(switches::kUserDataDir);
if (!profile_path.empty())
- CommandLine::AppendSwitchWithValue(&cmd_line, switches::kUserDataDir,
- profile_path);
+ cmd_line.AppendSwitchWithValue(switches::kUserDataDir,
+ profile_path);
bool run_in_process = run_renderer_in_process();
if (run_in_process) {
@@ -286,7 +282,8 @@ bool BrowserRenderProcessHost::Init() {
g_browser_process->local_state()->GetBoolean(
prefs::kStartRenderersManually)) {
std::wstring message =
- L"Please start a renderer process using:\n" + cmd_line;
+ L"Please start a renderer process using:\n" +
+ cmd_line.command_line_string();
// We don't know the owner window for BrowserRenderProcessHost and therefore we
// pass a NULL HWND argument.
@@ -328,8 +325,7 @@ bool BrowserRenderProcessHost::Init() {
return false;
}
- CommandLine command_line;
- if (command_line.HasSwitch(switches::kGearsInRenderer)) {
+ if (browser_command_line.HasSwitch(switches::kGearsInRenderer)) {
if (!AddPolicyForGearsInRenderer(policy)) {
NOTREACHED();
return false;
@@ -341,9 +337,10 @@ bool BrowserRenderProcessHost::Init() {
return false;
}
- result = broker_service->SpawnTarget(renderer_path.c_str(),
- cmd_line.c_str(),
- policy, &target);
+ result =
+ broker_service->SpawnTarget(renderer_path.c_str(),
+ cmd_line.command_line_string().c_str(),
+ policy, &target);
policy->Release();
if (desktop)
@@ -465,8 +462,8 @@ void BrowserRenderProcessHost::InitVisitedLinks() {
}
void BrowserRenderProcessHost::InitUserScripts() {
- CommandLine command_line;
- if (!command_line.HasSwitch(switches::kEnableUserScripts)) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableUserScripts)) {
return;
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.cc b/chrome/browser/safe_browsing/safe_browsing_database.cc
index fc3254d..174c867 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database.cc
@@ -20,8 +20,10 @@ static const wchar_t kBloomFilterFile[] = L" Filter";
// Factory method.
SafeBrowsingDatabase* SafeBrowsingDatabase::Create() {
- if (CommandLine().HasSwitch(switches::kUseOldSafeBrowsing))
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kUseOldSafeBrowsing)) {
return new SafeBrowsingDatabaseImpl;
+ }
return new SafeBrowsingDatabaseBloom;
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
index 9e3f5e7..62910c5 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
@@ -909,7 +909,8 @@ TEST(SafeBrowsingDatabase, HashCaching) {
// Test receiving a full add chunk. The old implementation doesn't support
// this test, so we bail here.
- if (CommandLine().HasSwitch(switches::kUseOldSafeBrowsing)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kUseOldSafeBrowsing)) {
TearDownTestDatabase(database);
return;
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index 60da2b5..14f31bc 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -36,7 +36,8 @@ SafeBrowsingService::SafeBrowsingService()
resetting_(false),
database_loaded_(false),
update_in_progress_(false) {
- new_safe_browsing_ = !CommandLine().HasSwitch(switches::kUseOldSafeBrowsing);
+ new_safe_browsing_ = !CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kUseOldSafeBrowsing);
base::SystemMonitor* monitor = base::SystemMonitor::Get();
DCHECK(monitor);
if (monitor)
diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.cc b/chrome/browser/search_engines/template_url_prepopulate_data.cc
index 826787b..a8d242b 100644
--- a/chrome/browser/search_engines/template_url_prepopulate_data.cc
+++ b/chrome/browser/search_engines/template_url_prepopulate_data.cc
@@ -2680,9 +2680,8 @@ LONG GetCurrentGeoID() {
int GetGeoIDFromPrefs(PrefService* prefs) {
// See if the user overrode the GeoID on the command line.
- CommandLine parsed_command_line;
const std::wstring geoID(
- parsed_command_line.GetSwitchValue(switches::kGeoID));
+ CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kGeoID));
if (!geoID.empty())
return _wtoi(geoID.c_str());
diff --git a/chrome/browser/sessions/session_restore_uitest.cc b/chrome/browser/sessions/session_restore_uitest.cc
index 85bb5fd..ae8803e 100644
--- a/chrome/browser/sessions/session_restore_uitest.cc
+++ b/chrome/browser/sessions/session_restore_uitest.cc
@@ -38,8 +38,7 @@ class SessionRestoreUITest : public UITest {
clear_profile_ = false;
- CommandLine::AppendSwitch(&launch_arguments_,
- switches::kRestoreLastSession);
+ launch_arguments_.AppendSwitch(switches::kRestoreLastSession);
UITest::SetUp();
}
@@ -283,7 +282,7 @@ TEST_F(SessionRestoreUITest, DISABLED_DontRestoreWhileIncognito) {
include_testing_id_ = false;
use_existing_browser_ = true;
clear_profile_ = false;
- CommandLine::AppendSwitch(&launch_arguments_, switches::kRestoreLastSession);
+ launch_arguments_.AppendSwitch(switches::kRestoreLastSession);
LaunchBrowser(launch_arguments_, false);
// A new window should appear;
@@ -345,9 +344,9 @@ TEST_F(SessionRestoreUITest,
include_testing_id_ = false;
use_existing_browser_ = true;
clear_profile_ = false;
- std::wstring app_launch_arguments = launch_arguments_;
- CommandLine::AppendSwitchWithValue(
- &app_launch_arguments, switches::kApp, UTF8ToWide(url2.spec()));
+ CommandLine app_launch_arguments = launch_arguments_;
+ app_launch_arguments.AppendSwitchWithValue(switches::kApp,
+ UTF8ToWide(url2.spec()));
LaunchBrowser(app_launch_arguments, false);
int window_count;
ASSERT_TRUE(automation()->WaitForWindowCountToChange(1, &window_count,
@@ -358,9 +357,8 @@ TEST_F(SessionRestoreUITest,
CloseWindow(0, 2);
// Restore it, which should bring back the first window with url1.
- std::wstring restore_launch_arguments = launch_arguments_;
- CommandLine::AppendSwitch(&restore_launch_arguments,
- switches::kRestoreLastSession);
+ CommandLine restore_launch_arguments = launch_arguments_;
+ restore_launch_arguments.AppendSwitch(switches::kRestoreLastSession);
LaunchBrowser(restore_launch_arguments, false);
ASSERT_TRUE(automation()->WaitForWindowCountToChange(1, &window_count,
action_timeout_ms()));
diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc
index c73fc2e..9062894 100644
--- a/chrome/browser/tab_contents/web_contents.cc
+++ b/chrome/browser/tab_contents/web_contents.cc
@@ -1218,7 +1218,7 @@ WebPreferences WebContents::GetWebkitPrefs() {
prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
{ // Command line switches are used for preferences with no user interface.
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
web_prefs.developer_extras_enabled =
!command_line.HasSwitch(switches::kDisableDevTools) &&
prefs->GetBoolean(prefs::kWebKitDeveloperExtrasEnabled);
diff --git a/chrome/browser/unload_uitest.cc b/chrome/browser/unload_uitest.cc
index 471a3e8..3089e82 100644
--- a/chrome/browser/unload_uitest.cc
+++ b/chrome/browser/unload_uitest.cc
@@ -153,7 +153,7 @@ class UnloadTest : public UITest {
// we don't get confused and think we're closing the tab.
TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) {
// Tests makes no sense in single-process mode since the renderer is hung.
- if (CommandLine().HasSwitch(switches::kSingleProcess))
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
return;
NavigateToDataURL(INFINITE_UNLOAD_HTML, L"infiniteunload");
@@ -167,7 +167,7 @@ TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) {
// we correctly nav to each one.
TEST_F(UnloadTest, CrossSiteInfiniteUnloadSync) {
// Tests makes no sense in single-process mode since the renderer is hung.
- if (CommandLine().HasSwitch(switches::kSingleProcess))
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
return;
NavigateToDataURL(INFINITE_UNLOAD_HTML, L"infiniteunload");
@@ -181,7 +181,7 @@ TEST_F(UnloadTest, CrossSiteInfiniteUnloadSync) {
// we don't get confused and think we're closing the tab.
TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadAsync) {
// Tests makes no sense in single-process mode since the renderer is hung.
- if (CommandLine().HasSwitch(switches::kSingleProcess))
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
return;
NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, L"infinitebeforeunload");
@@ -195,7 +195,7 @@ TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadAsync) {
// we correctly nav to each one.
TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadSync) {
// Tests makes no sense in single-process mode since the renderer is hung.
- if (CommandLine().HasSwitch(switches::kSingleProcess))
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
return;
NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML, L"infinitebeforeunload");
diff --git a/chrome/browser/user_data_manager.cc b/chrome/browser/user_data_manager.cc
index 3353016..554c53f 100644
--- a/chrome/browser/user_data_manager.cc
+++ b/chrome/browser/user_data_manager.cc
@@ -177,15 +177,14 @@ std::wstring UserDataManager::GetCommandForProfile(
std::wstring user_data_dir = GetUserDataFolderForProfile(profile_name);
std::wstring command;
PathService::Get(base::FILE_EXE, &command);
- CommandLine::AppendSwitchWithValue(&command,
- switches::kUserDataDir,
+ CommandLine command_line(command);
+ command_line.AppendSwitchWithValue(switches::kUserDataDir,
user_data_dir);
std::wstring local_state_path;
PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
- CommandLine::AppendSwitchWithValue(&command,
- switches::kParentProfile,
+ command_line.AppendSwitchWithValue(switches::kParentProfile,
local_state_path);
- return command;
+ return command_line.command_line_string();
}
void UserDataManager::LaunchChromeForProfile(
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index 7bf7156e..6dae951 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -327,8 +327,10 @@ void BrowserView::Init() {
// Start a hung plugin window detector for this browser object (as long as
// hang detection is not disabled).
- if (!CommandLine().HasSwitch(switches::kDisableHangMonitor))
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableHangMonitor)) {
InitHangMonitor();
+ }
LoadAccelerators();
SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME));
diff --git a/chrome/common/child_process.cc b/chrome/common/child_process.cc
index 112fceb..b64984c 100644
--- a/chrome/common/child_process.cc
+++ b/chrome/common/child_process.cc
@@ -77,7 +77,7 @@ bool ChildProcess::GlobalInit(const std::wstring &channel_name,
child_process_ = factory->Create(channel_name);
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kUserAgent)) {
#if defined(OS_WIN)
// TODO(port): calling this connects an, otherwise disconnected, subgraph
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc
index 297b963..e842cbc 100644
--- a/chrome/common/chrome_paths.cc
+++ b/chrome/common/chrome_paths.cc
@@ -49,8 +49,8 @@ bool GetDefaultUserDataDirectory(std::wstring* result) {
bool GetGearsPluginPathFromCommandLine(std::wstring *path) {
#ifndef NDEBUG
// for debugging, support a cmd line based override
- CommandLine command_line;
- *path = command_line.GetSwitchValue(switches::kGearsPluginPathOverride);
+ *path = CommandLine::ForCurrentProcess()->GetSwitchValue(
+ switches::kGearsPluginPathOverride);
return !path->empty();
#else
return false;
diff --git a/chrome/common/chrome_plugin_lib.cc b/chrome/common/chrome_plugin_lib.cc
index 4af7a558..1587a2d 100644
--- a/chrome/common/chrome_plugin_lib.cc
+++ b/chrome/common/chrome_plugin_lib.cc
@@ -44,8 +44,7 @@ CPError STDCALL Gears_CP_Initialize(CPID id, const CPBrowserFuncs *bfuncs,
static bool IsSingleProcessMode() {
// We don't support ChromePlugins in single-process mode.
- CommandLine command_line;
- return command_line.HasSwitch(switches::kSingleProcess);
+ return CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess);
}
// static
diff --git a/chrome/common/chrome_plugin_util.cc b/chrome/common/chrome_plugin_util.cc
index 56b1f54..610c0b9 100644
--- a/chrome/common/chrome_plugin_util.cc
+++ b/chrome/common/chrome_plugin_util.cc
@@ -121,7 +121,7 @@ int PluginResponseUtils::GetResponseInfo(
CPError CPB_GetCommandLineArgumentsCommon(const char* url,
std::string* arguments) {
- CommandLine cmd;
+ const CommandLine cmd = *CommandLine::ForCurrentProcess();
std::wstring arguments_w;
// Use the same UserDataDir for new launches that we currently have set.
@@ -131,8 +131,8 @@ CPError CPB_GetCommandLineArgumentsCommon(const char* url,
wchar_t user_data_dir_full[MAX_PATH];
if (_wfullpath(user_data_dir_full, user_data_dir.c_str(), MAX_PATH) &&
file_util::PathExists(user_data_dir_full)) {
- CommandLine::AppendSwitchWithValue(
- &arguments_w, switches::kUserDataDir, user_data_dir_full);
+ arguments_w += std::wstring(L"--") + switches::kUserDataDir +
+ L'=' + user_data_dir_full;
}
}
@@ -140,7 +140,7 @@ CPError CPB_GetCommandLineArgumentsCommon(const char* url,
// chrome.
// Note: Do not change this flag! Old Gears shortcuts will break if you do!
std::wstring url_w = UTF8ToWide(url);
- CommandLine::AppendSwitchWithValue(&arguments_w, switches::kApp, url_w);
+ arguments_w += std::wstring(L"--") + switches::kApp + L'=' + url_w;
*arguments = WideToUTF8(arguments_w);
diff --git a/chrome/common/common_glue.cc b/chrome/common/common_glue.cc
index 6c33f1e..7d32310 100644
--- a/chrome/common/common_glue.cc
+++ b/chrome/common/common_glue.cc
@@ -29,7 +29,7 @@ std::wstring GetWebKitLocale() {
// The browser process should have passed the locale to the renderer via the
// --lang command line flag. In single process mode, this will return the
// wrong value. TODO(tc): Fix this for single process mode.
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
const std::wstring& lang =
parsed_command_line.GetSwitchValue(switches::kLang);
DCHECK(!lang.empty() ||
diff --git a/chrome/common/debug_flags.cc b/chrome/common/debug_flags.cc
index 1e10b78..9f62cbe 100644
--- a/chrome/common/debug_flags.cc
+++ b/chrome/common/debug_flags.cc
@@ -8,11 +8,11 @@
#include "base/command_line.h"
#include "chrome/common/chrome_switches.h"
-bool DebugFlags::ProcessDebugFlags(std::wstring* command_line,
+bool DebugFlags::ProcessDebugFlags(CommandLine* command_line,
ChildProcessType type,
bool is_in_sandbox) {
bool should_help_child = false;
- CommandLine current_cmd_line;
+ const CommandLine& current_cmd_line = *CommandLine::ForCurrentProcess();
if (current_cmd_line.HasSwitch(switches::kDebugChildren)) {
// Look to pass-on the kDebugOnStart flag.
std::wstring value;
@@ -20,12 +20,10 @@ bool DebugFlags::ProcessDebugFlags(std::wstring* command_line,
if (value.empty() ||
(type == RENDERER && value == switches::kRendererProcess) ||
(type == PLUGIN && value == switches::kPluginProcess)) {
- CommandLine::AppendSwitch(command_line, switches::kDebugOnStart);
+ command_line->AppendSwitch(switches::kDebugOnStart);
should_help_child = true;
}
- CommandLine::AppendSwitchWithValue(command_line,
- switches::kDebugChildren,
- value);
+ command_line->AppendSwitchWithValue(switches::kDebugChildren, value);
} else if (current_cmd_line.HasSwitch(switches::kWaitForDebuggerChildren)) {
// Look to pass-on the kWaitForDebugger flag.
std::wstring value;
@@ -33,11 +31,10 @@ bool DebugFlags::ProcessDebugFlags(std::wstring* command_line,
if (value.empty() ||
(type == RENDERER && value == switches::kRendererProcess) ||
(type == PLUGIN && value == switches::kPluginProcess)) {
- CommandLine::AppendSwitch(command_line, switches::kWaitForDebugger);
+ command_line->AppendSwitch(switches::kWaitForDebugger);
}
- CommandLine::AppendSwitchWithValue(command_line,
- switches::kWaitForDebuggerChildren,
- value);
+ command_line->AppendSwitchWithValue(switches::kWaitForDebuggerChildren,
+ value);
}
return should_help_child;
}
diff --git a/chrome/common/debug_flags.h b/chrome/common/debug_flags.h
index 9d4ebba..c2115a9 100644
--- a/chrome/common/debug_flags.h
+++ b/chrome/common/debug_flags.h
@@ -5,7 +5,7 @@
#ifndef CHROME_COMMON_DEBUG_FLAGS_H__
#define CHROME_COMMON_DEBUG_FLAGS_H__
-#include <string>
+class CommandLine;
class DebugFlags {
public:
@@ -15,13 +15,15 @@ class DebugFlags {
UNKNOWN
};
- // Updates the command line arguments with debug-related flags. If debug flags
- // have been used with this process, they will be filtered and added to
- // command_line as needed. is_in_sandbox must be true if the child process will
- // be in a sandbox.
- // Returns true if the caller should "help" the child process by calling the JIT
- // debugger on it. It may only happen if is_in_sandbox is true.
- static bool ProcessDebugFlags(std::wstring* command_line,
+ // Updates the command line arguments with debug-related flags. If
+ // debug flags have been used with this process, they will be
+ // filtered and added to command_line as needed. is_in_sandbox must
+ // be true if the child process will be in a sandbox.
+ //
+ // Returns true if the caller should "help" the child process by
+ // calling the JIT debugger on it. It may only happen if
+ // is_in_sandbox is true.
+ static bool ProcessDebugFlags(CommandLine* command_line,
ChildProcessType type,
bool is_in_sandbox);
};
diff --git a/chrome/common/ipc_channel_posix.cc b/chrome/common/ipc_channel_posix.cc
index 57d30bf..6c6f17c 100644
--- a/chrome/common/ipc_channel_posix.cc
+++ b/chrome/common/ipc_channel_posix.cc
@@ -244,7 +244,8 @@ Channel::ChannelImpl::ChannelImpl(const std::wstring& channel_id, Mode mode,
: mode_(mode),
is_blocked_on_write_(false),
message_send_bytes_written_(0),
- uses_fifo_(CommandLine().HasSwitch(switches::kTestingChannelID)),
+ uses_fifo_(CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kTestingChannelID)),
server_listen_pipe_(-1),
pipe_(-1),
client_pipe_(-1),
diff --git a/chrome/common/ipc_logging.cc b/chrome/common/ipc_logging.cc
index db8bf84..ec2fe82 100644
--- a/chrome/common/ipc_logging.cc
+++ b/chrome/common/ipc_logging.cc
@@ -45,7 +45,7 @@ Logging::Logging()
// enabled, so child processes can know when logging is enabled.
int browser_pid;
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
std::wstring process_type =
parsed_command_line.GetSwitchValue(switches::kProcessType);
if (process_type.empty()) {
diff --git a/chrome/common/ipc_tests.cc b/chrome/common/ipc_tests.cc
index be3b0d9..b0add18 100644
--- a/chrome/common/ipc_tests.cc
+++ b/chrome/common/ipc_tests.cc
@@ -52,7 +52,8 @@ void IPCChannelTest::TearDown() {
base::ProcessHandle IPCChannelTest::SpawnChild(ChildType child_type,
IPC::Channel *channel) {
// kDebugChildren support.
- bool debug_on_start = CommandLine().HasSwitch(switches::kDebugChildren);
+ bool debug_on_start =
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren);
switch (child_type) {
case TEST_CLIENT:
@@ -73,7 +74,8 @@ base::ProcessHandle IPCChannelTest::SpawnChild(ChildType child_type,
base::ProcessHandle IPCChannelTest::SpawnChild(ChildType child_type,
IPC::Channel *channel) {
// kDebugChildren support.
- bool debug_on_start = CommandLine().HasSwitch(switches::kDebugChildren);
+ bool debug_on_start =
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kDebugChildren);
base::file_handle_mapping_vector fds_to_map;
int src_fd;
@@ -225,9 +227,10 @@ TEST_F(IPCChannelTest, ChannelProxyTest) {
channel_listener.Init(&chan);
#if defined(OS_WIN)
- base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT, NULL);
+ base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT, NULL);
#elif defined(OS_POSIX)
- bool debug_on_start = CommandLine().HasSwitch(switches::kDebugChildren);
+ bool debug_on_start = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDebugChildren);
base::file_handle_mapping_vector fds_to_map;
int src_fd;
int dest_fd;
diff --git a/chrome/common/l10n_util.cc b/chrome/common/l10n_util.cc
index d9fb299..86a36eb 100644
--- a/chrome/common/l10n_util.cc
+++ b/chrome/common/l10n_util.cc
@@ -261,7 +261,7 @@ std::wstring GetApplicationLocale(const std::wstring& pref_locale) {
std::wstring resolved_locale;
// First, check to see if there's a --lang flag.
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
const std::wstring& lang_arg =
parsed_command_line.GetSwitchValue(switches::kLang);
if (!lang_arg.empty()) {
diff --git a/chrome/common/logging_chrome_uitest.cc b/chrome/common/logging_chrome_uitest.cc
index f1a121c..b88deb6 100644
--- a/chrome/common/logging_chrome_uitest.cc
+++ b/chrome/common/logging_chrome_uitest.cc
@@ -72,8 +72,7 @@ class AssertionTest : public UITest {
// We're testing the renderer rather than the browser assertion here,
// because the browser assertion would flunk the test during SetUp()
// (since TAU wouldn't be able to find the browser window).
- CommandLine::AppendSwitch(&launch_arguments_,
- switches::kRendererAssertTest);
+ launch_arguments_.AppendSwitch(switches::kRendererAssertTest);
}
};
@@ -98,8 +97,7 @@ class RendererCrashTest : public UITest {
// Initial loads will never complete due to crash.
wait_for_initial_loads_ = false;
- CommandLine::AppendSwitch(&launch_arguments_,
- switches::kRendererCrashTest);
+ launch_arguments_.AppendSwitch(switches::kRendererCrashTest);
}
};
@@ -123,8 +121,7 @@ class BrowserCrashTest : public UITest {
// Initial loads will never complete due to crash.
wait_for_initial_loads_ = false;
- CommandLine::AppendSwitch(&launch_arguments_,
- switches::kBrowserCrashTest);
+ launch_arguments_.AppendSwitch(switches::kBrowserCrashTest);
}
};
diff --git a/chrome/common/main_function_params.h b/chrome/common/main_function_params.h
index b8156ae..e3a1c55 100644
--- a/chrome/common/main_function_params.h
+++ b/chrome/common/main_function_params.h
@@ -12,12 +12,10 @@
#include "base/command_line.h"
#include "chrome/common/sandbox_init_wrapper.h"
-// TODO(pinkerton): |cl| should be const, but can't be due to bug 6144.
-
struct MainFunctionParams {
- MainFunctionParams(CommandLine& cl, const SandboxInitWrapper& sb)
+ MainFunctionParams(const CommandLine& cl, const SandboxInitWrapper& sb)
: command_line_(cl), sandbox_info_(sb) { }
- CommandLine& command_line_;
+ const CommandLine& command_line_;
const SandboxInitWrapper& sandbox_info_;
};
diff --git a/chrome/common/pref_service_uitest.cc b/chrome/common/pref_service_uitest.cc
index 0ecd114..4ffd4e7 100644
--- a/chrome/common/pref_service_uitest.cc
+++ b/chrome/common/pref_service_uitest.cc
@@ -43,9 +43,8 @@ public:
ASSERT_TRUE(::SetFileAttributesW(tmp_pref_file_.c_str(),
FILE_ATTRIBUTE_NORMAL));
- CommandLine::AppendSwitchWithValue(&launch_arguments_,
- switches::kUserDataDir,
- tmp_profile_);
+ launch_arguments_.AppendSwitchWithValue(switches::kUserDataDir,
+ tmp_profile_);
}
bool LaunchAppWithProfile() {
diff --git a/chrome/common/temp_scaffolding_stubs.cpp b/chrome/common/temp_scaffolding_stubs.cpp
index 756c8c2..af74d6d 100644
--- a/chrome/common/temp_scaffolding_stubs.cpp
+++ b/chrome/common/temp_scaffolding_stubs.cpp
@@ -14,7 +14,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_service.h"
-BrowserProcessImpl::BrowserProcessImpl(CommandLine& command_line)
+BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line)
: created_local_state_(), created_metrics_service_(),
created_profile_manager_() {
g_browser_process = this;
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index f7f2bbb..603e7ca 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -83,7 +83,7 @@ class GoogleUpdateSettings {
class BrowserProcessImpl : public BrowserProcess {
public:
- BrowserProcessImpl(CommandLine& command_line);
+ BrowserProcessImpl(const CommandLine& command_line);
virtual ~BrowserProcessImpl();
virtual void EndSession() { }
@@ -126,7 +126,7 @@ class BrowserProcessImpl : public BrowserProcess {
class FirstRunBrowserProcess : public BrowserProcessImpl {
public:
- FirstRunBrowserProcess(CommandLine& command_line)
+ FirstRunBrowserProcess(const CommandLine& command_line)
: BrowserProcessImpl(command_line) {
}
virtual ~FirstRunBrowserProcess() { }
diff --git a/chrome/installer/setup/main.cc b/chrome/installer/setup/main.cc
index e888f0b..8f57e06 100755
--- a/chrome/installer/setup/main.cc
+++ b/chrome/installer/setup/main.cc
@@ -457,7 +457,8 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
wchar_t* command_line, int show_command) {
// The exit manager is in charge of calling the dtors of singletons.
base::AtExitManager exit_manager;
- CommandLine parsed_command_line;
+ CommandLine::Init(0, NULL);
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
installer::InitInstallerLogging(parsed_command_line);
int options = GetInstallOptions(parsed_command_line);
if (options & installer_util::VERBOSE_LOGGING)
diff --git a/chrome/installer/setup/setup.cc b/chrome/installer/setup/setup.cc
index 27475242..0fe3afb 100755
--- a/chrome/installer/setup/setup.cc
+++ b/chrome/installer/setup/setup.cc
@@ -51,7 +51,6 @@ void DoFirstInstallTasks(std::wstring install_path, int options) {
// will work only if current user has admin rights.
std::wstring chrome_exe(install_path);
file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe);
- CommandLine cmd_line;
LOG(INFO) << "Registering Chrome as browser";
ShellUtil::RegisterStatus ret = ShellUtil::FAILURE;
if (options & installer_util::MAKE_CHROME_DEFAULT) {
diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc
index ac9fd90..e2416f0 100644
--- a/chrome/plugin/plugin_main.cc
+++ b/chrome/plugin/plugin_main.cc
@@ -16,7 +16,7 @@
// mainline routine for running as the plugin process
int PluginMain(const MainFunctionParams& parameters) {
- CommandLine& parsed_command_line = parameters.command_line_;
+ const CommandLine& parsed_command_line = parameters.command_line_;
sandbox::TargetServices* target_services =
parameters.sandbox_info_.TargetServices();
diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc
index 28c0e63..31444b6 100644
--- a/chrome/plugin/webplugin_delegate_stub.cc
+++ b/chrome/plugin/webplugin_delegate_stub.cc
@@ -123,7 +123,7 @@ void WebPluginDelegateStub::OnInit(const PluginMsg_Init_Params& params,
argv[i] = const_cast<char*>(params.arg_values[i].c_str());
}
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
FilePath path =
FilePath(command_line.GetSwitchValue(switches::kPluginPath));
delegate_ = WebPluginDelegateImpl::Create(
diff --git a/chrome/renderer/render_process.cc b/chrome/renderer/render_process.cc
index b2b4606..2fe1af7 100644
--- a/chrome/renderer/render_process.cc
+++ b/chrome/renderer/render_process.cc
@@ -63,7 +63,7 @@ bool RenderProcess::GlobalInit(const std::wstring &channel_name) {
}
}
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
webkit_glue::SetJavaScriptFlags(
command_line.GetSwitchValue(switches::kJavaScriptFlags));
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 9927171..8f08add 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -289,7 +289,7 @@ void RenderView::Init(HWND parent_hwnd,
host_window_ = parent_hwnd;
modal_dialog_event_.reset(modal_dialog_event);
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
enable_dom_automation_ =
command_line.HasSwitch(switches::kDomAutomationController);
disable_popup_blocking_ =
@@ -1834,8 +1834,8 @@ static bool ShouldLoadPluginInProcess(const std::string& mime_type,
if (mime_type == "application/x-googlegears") {
*is_gears = true;
- CommandLine cmd;
- return cmd.HasSwitch(switches::kGearsInRenderer);
+ return CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kGearsInRenderer);
}
return false;
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index 7516ace..3bc7c63 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -136,7 +136,7 @@ ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
namespace webkit_glue {
bool IsMediaPlayerAvailable() {
- return CommandLine().HasSwitch(switches::kEnableVideo);
+ return CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableVideo);
}
void PrefetchDns(const std::string& hostname) {
diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc
index 476e4f7..b3d9fec 100644
--- a/chrome/renderer/renderer_main.cc
+++ b/chrome/renderer/renderer_main.cc
@@ -46,7 +46,7 @@ static void HandleRendererErrorTestParameters(const CommandLine& command_line) {
// mainline routine for running as the Rendererer process
int RendererMain(const MainFunctionParams& parameters) {
- CommandLine& parsed_command_line = parameters.command_line_;
+ const CommandLine& parsed_command_line = parameters.command_line_;
sandbox::TargetServices* target_services =
parameters.sandbox_info_.TargetServices();
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc
index dcbac5b..81d0f0b 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc
@@ -79,7 +79,7 @@ AutomatedUITest::AutomatedUITest()
post_action_delay_(0) {
show_window_ = true;
GetSystemTimeAsFileTime(&test_start_time_);
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(kDebugModeSwitch))
debug_logging_enabled_ = true;
if (parsed_command_line.HasSwitch(kWaitSwitch)) {
@@ -95,7 +95,7 @@ AutomatedUITest::AutomatedUITest()
AutomatedUITest::~AutomatedUITest() {}
void AutomatedUITest::RunReproduction() {
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
xml_writer_.StartWriting();
xml_writer_.StartElement("Report");
std::string action_string =
@@ -863,7 +863,7 @@ bool AutomatedUITest::SimulateKeyPressInActiveWindow(wchar_t key, int flags) {
bool AutomatedUITest::InitXMLReader() {
std::wstring input_path;
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(kInputFilePathSwitch))
input_path = parsed_command_line.GetSwitchValue(kInputFilePathSwitch);
else
@@ -877,7 +877,7 @@ bool AutomatedUITest::InitXMLReader() {
bool AutomatedUITest::WriteReportToFile() {
std::ofstream error_file;
std::wstring path;
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(kOutputFilePathSwitch))
path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch);
else
@@ -897,7 +897,7 @@ bool AutomatedUITest::WriteReportToFile() {
void AutomatedUITest::AppendToOutputFile(const std::string &append_string) {
std::ofstream error_file;
std::wstring path;
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(kOutputFilePathSwitch))
path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch);
else
@@ -1001,7 +1001,7 @@ bool AutomatedUITest::DidCrash(bool update_total_crashes) {
}
TEST_F(AutomatedUITest, TheOneAndOnlyTest) {
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(kReproSwitch))
RunReproduction();
else
diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc
index 33c6a30..add33f4 100644
--- a/chrome/test/automation/automation_proxy_uitest.cc
+++ b/chrome/test/automation/automation_proxy_uitest.cc
@@ -25,9 +25,8 @@ class AutomationProxyTest : public UITest {
protected:
AutomationProxyTest() {
dom_automation_enabled_ = true;
- CommandLine::AppendSwitchWithValue(&launch_arguments_,
- switches::kLang,
- L"en-us");
+ launch_arguments_.AppendSwitchWithValue(switches::kLang,
+ L"en-us");
}
};
@@ -371,7 +370,9 @@ class AutomationProxyTest2 : public AutomationProxyVisibleTest {
document2_ = test_data_directory_;
file_util::AppendToPath(&document2_, L"title2.html");
- launch_arguments_ = document1_ + L" " + document2_;
+ launch_arguments_ = CommandLine(L"");
+ launch_arguments_.AppendLooseValue(document1_);
+ launch_arguments_.AppendLooseValue(document2_);
}
std::wstring document1_;
@@ -576,7 +577,8 @@ class AutomationProxyTest3 : public UITest {
file_util::AppendToPath(&document1_, L"frame_dom_access.html");
dom_automation_enabled_ = true;
- launch_arguments_ = document1_;
+ launch_arguments_ = CommandLine(L"");
+ launch_arguments_.AppendLooseValue(document1_);
}
std::wstring document1_;
diff --git a/chrome/test/memory_test/memory_test.cc b/chrome/test/memory_test/memory_test.cc
index 23cb072..2ef79d1 100644
--- a/chrome/test/memory_test/memory_test.cc
+++ b/chrome/test/memory_test/memory_test.cc
@@ -32,17 +32,17 @@ class MemoryTest : public UITest {
// For now, turn off plugins because they crash like crazy.
// TODO(mbelshe): Fix Chrome to not crash with plugins.
- CommandLine::AppendSwitch(&launch_arguments_, switches::kDisablePlugins);
+ launch_arguments_.AppendSwitch(switches::kDisablePlugins);
- CommandLine::AppendSwitch(&launch_arguments_, switches::kEnableLogging);
+ launch_arguments_.AppendSwitch(switches::kEnableLogging);
// Use the playback cache, but don't use playback events.
- CommandLine::AppendSwitch(&launch_arguments_, switches::kPlaybackMode);
- CommandLine::AppendSwitch(&launch_arguments_, switches::kNoEvents);
+ launch_arguments_.AppendSwitch(switches::kPlaybackMode);
+ launch_arguments_.AppendSwitch(switches::kNoEvents);
// Get the specified user data dir (optional)
std::wstring profile_dir =
- CommandLine().GetSwitchValue(switches::kUserDataDir);
+ CommandLine::ForCurrentProcess()->GetSwitchValue(switches::kUserDataDir);
if (profile_dir.length() == 0) {
// Compute the user-data-dir which contains our test cache.
@@ -63,9 +63,8 @@ class MemoryTest : public UITest {
}
}
- CommandLine::AppendSwitchWithValue(&launch_arguments_,
- switches::kUserDataDir,
- user_data_dir_);
+ launch_arguments_.AppendSwitchWithValue(switches::kUserDataDir,
+ user_data_dir_);
}
~MemoryTest() {
diff --git a/chrome/test/page_cycler/page_cycler_test.cc b/chrome/test/page_cycler/page_cycler_test.cc
index e42cf14..8f5fead 100644
--- a/chrome/test/page_cycler/page_cycler_test.cc
+++ b/chrome/test/page_cycler/page_cycler_test.cc
@@ -38,9 +38,8 @@ class PageCyclerTest : public UITest {
show_window_ = true;
// Expose garbage collection for the page cycler tests.
- CommandLine::AppendSwitchWithValue(&launch_arguments_,
- switches::kJavaScriptFlags,
- L"--expose_gc");
+ launch_arguments_.AppendSwitchWithValue(switches::kJavaScriptFlags,
+ L"--expose_gc");
}
// For HTTP tests, the name must be safe for use in a URL without escaping.
diff --git a/chrome/test/plugin/plugin_test.cpp b/chrome/test/plugin/plugin_test.cpp
index d458662..0faaf8e 100644
--- a/chrome/test/plugin/plugin_test.cpp
+++ b/chrome/test/plugin/plugin_test.cpp
@@ -76,27 +76,16 @@ class PluginTest : public UITest {
KEY_WRITE)) {
regkey.CreateKey(L"CHROME.EXE", KEY_READ);
}
- if (!launch_arguments_.empty())
- launch_arguments_.append(L" ");
- launch_arguments_.append(L"--" kNoNativeActiveXShimSwitch);
+ launch_arguments_.AppendSwitch(kNoNativeActiveXShimSwitch);
} else if (strcmp(test_info->name(), "MediaPlayerOld") == 0) {
// When testing the old WMP plugin, we need to force Chrome to not load
// the new plugin.
- if (!launch_arguments_.empty())
- launch_arguments_.append(L" ");
-
- launch_arguments_.append(L"--" kUseOldWMPPluginSwitch);
- launch_arguments_.append(L" ");
- launch_arguments_.append(L"--" kNoNativeActiveXShimSwitch);
+ launch_arguments_.AppendSwitch(kUseOldWMPPluginSwitch);
+ launch_arguments_.AppendSwitch(kNoNativeActiveXShimSwitch);
} else if (strcmp(test_info->name(), "FlashSecurity") == 0) {
- if (!launch_arguments_.empty())
- launch_arguments_.append(L" ");
-
- launch_arguments_.append(L"--");
- launch_arguments_.append(switches::kTestSandbox);
- launch_arguments_.append(L"=");
- launch_arguments_.append(L"security_tests.dll");
+ launch_arguments_.AppendSwitchWithValue(switches::kTestSandbox,
+ L"security_tests.dll");
}
UITest::SetUp();
diff --git a/chrome/test/reliability/reliability_test_suite.h b/chrome/test/reliability/reliability_test_suite.h
index 6170d63..809ca52 100644
--- a/chrome/test/reliability/reliability_test_suite.h
+++ b/chrome/test/reliability/reliability_test_suite.h
@@ -18,7 +18,7 @@ protected:
virtual void Initialize() {
UITestSuite::Initialize();
- SetPageRange(CommandLine());
+ SetPageRange(CommandLine(L""));
}
};
diff --git a/chrome/test/startup/startup_test.cc b/chrome/test/startup/startup_test.cc
index 34f91b9..70b54de 100644
--- a/chrome/test/startup/startup_test.cc
+++ b/chrome/test/startup/startup_test.cc
@@ -110,7 +110,7 @@ class StartupFileTest : public StartupTest {
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &file_url));
file_util::AppendToPath(&file_url, L"empty.html");
ASSERT_TRUE(file_util::PathExists(file_url));
- launch_arguments_ += file_url;
+ launch_arguments_.AppendLooseValue(file_url);
pages_ = WideToUTF8(file_url);
}
diff --git a/chrome/test/ui/inspector_controller_uitest.cc b/chrome/test/ui/inspector_controller_uitest.cc
index 29b1489..289cca0 100644
--- a/chrome/test/ui/inspector_controller_uitest.cc
+++ b/chrome/test/ui/inspector_controller_uitest.cc
@@ -34,7 +34,7 @@ TEST_F(InspectorControllerTest, DISABLED_InspectElement) {
if (IsTestCaseDisabled())
return;
- if (CommandLine().HasSwitch(switches::kSingleProcess))
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
return;
scoped_refptr<HTTPTestServer> server =
diff --git a/chrome/test/ui/omnibox_uitest.cc b/chrome/test/ui/omnibox_uitest.cc
index 83e14fd..7b317af 100644
--- a/chrome/test/ui/omnibox_uitest.cc
+++ b/chrome/test/ui/omnibox_uitest.cc
@@ -133,7 +133,8 @@ void OmniboxTest::RunQueryChain(const std::wstring& input_text) {
// </omnibox_tests>
TEST_F(OmniboxTest, Measure) {
- if (!CommandLine().HasSwitch(kRunOmniboxTest)) return;
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunOmniboxTest))
+ return;
std::wstring omnibox_tests_path;
PathService::Get(chrome::DIR_TEST_DATA, &omnibox_tests_path);
diff --git a/chrome/test/ui/sandbox_uitests.cc b/chrome/test/ui/sandbox_uitests.cc
index cbfaa65..d898cf5 100644
--- a/chrome/test/ui/sandbox_uitests.cc
+++ b/chrome/test/ui/sandbox_uitests.cc
@@ -14,9 +14,8 @@ class SandboxTest : public UITest {
protected:
// Launches chrome with the --test-sandbox=security_tests.dll flag.
SandboxTest() : UITest() {
- CommandLine::AppendSwitchWithValue(&launch_arguments_,
- switches::kTestSandbox,
- L"security_tests.dll");
+ launch_arguments_.AppendSwitchWithValue(switches::kTestSandbox,
+ L"security_tests.dll");
}
};
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index 06591ec..597b0af 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/test/ui/ui_test.h"
+
#include <set>
#include <vector>
-#include "chrome/test/ui/ui_test.h"
-
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/file_util.h"
@@ -92,6 +92,7 @@ bool UITest::DieFileDie(const std::wstring& file, bool recurse) {
UITest::UITest()
: testing::Test(),
+ launch_arguments_(L""),
expected_errors_(0),
expected_crashes_(0),
homepage_(L"about:blank"),
@@ -177,28 +178,29 @@ void UITest::TearDown() {
// Pick up the various test time out values from the command line.
void UITest::InitializeTimeouts() {
- if (CommandLine().HasSwitch(kUiTestTimeout)) {
- std::wstring timeout_str = CommandLine().GetSwitchValue(kUiTestTimeout);
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(kUiTestTimeout)) {
+ std::wstring timeout_str = command_line.GetSwitchValue(kUiTestTimeout);
int timeout = StringToInt(timeout_str);
command_execution_timeout_ms_ = std::max(kMaxTestExecutionTime, timeout);
}
- if (CommandLine().HasSwitch(kUiTestActionTimeout)) {
- std::wstring act_str = CommandLine().GetSwitchValue(kUiTestActionTimeout);
+ if (command_line.HasSwitch(kUiTestActionTimeout)) {
+ std::wstring act_str = command_line.GetSwitchValue(kUiTestActionTimeout);
int act_timeout = StringToInt(act_str);
action_timeout_ms_ = std::max(kWaitForActionMsec, act_timeout);
}
- if (CommandLine().HasSwitch(kUiTestActionMaxTimeout)) {
+ if (command_line.HasSwitch(kUiTestActionMaxTimeout)) {
std::wstring action_max_str =
- CommandLine().GetSwitchValue(kUiTestActionMaxTimeout);
+ command_line.GetSwitchValue(kUiTestActionMaxTimeout);
int max_timeout = StringToInt(action_max_str);
action_max_timeout_ms_ = std::max(kWaitForActionMaxMsec, max_timeout);
}
- if (CommandLine().HasSwitch(kUiTestSleepTimeout)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestSleepTimeout)) {
std::wstring sleep_timeout_str =
- CommandLine().GetSwitchValue(kUiTestSleepTimeout);
+ CommandLine::ForCurrentProcess()->GetSwitchValue(kUiTestSleepTimeout);
int sleep_timeout = StringToInt(sleep_timeout_str);
sleep_timeout_ms_ = std::max(kWaitForActionMsec, sleep_timeout);
}
@@ -235,23 +237,29 @@ void UITest::CloseBrowserAndServer() {
#endif
}
-void UITest::LaunchBrowser(const std::wstring& arguments, bool clear_profile) {
- std::wstring command_line(browser_directory_);
- file_util::AppendToPath(&command_line,
+void UITest::LaunchBrowser(const CommandLine& arguments, bool clear_profile) {
+ std::wstring command = browser_directory_;
+ file_util::AppendToPath(&command,
chrome::kBrowserProcessExecutableName);
+ CommandLine command_line(command);
// Add any explict command line flags passed to the process.
std::wstring extra_chrome_flags =
- CommandLine().GetSwitchValue(kExtraChromeFlagsSwitch);
- if (!extra_chrome_flags.empty())
- command_line.append(L" " + extra_chrome_flags);
+ CommandLine::ForCurrentProcess()->GetSwitchValue(kExtraChromeFlagsSwitch);
+ if (!extra_chrome_flags.empty()) {
+#if defined(OS_WIN)
+ command_line.AppendLooseValue(extra_chrome_flags);
+#else
+ // TODO(port): figure out how to pass through extra flags via a string.
+ NOTIMPLEMENTED();
+#endif
+ }
// We need cookies on file:// for things like the page cycler.
- CommandLine::AppendSwitch(&command_line, switches::kEnableFileCookies);
+ command_line.AppendSwitch(switches::kEnableFileCookies);
if (dom_automation_enabled_)
- CommandLine::AppendSwitch(&command_line,
- switches::kDomAutomationController);
+ command_line.AppendSwitch(switches::kDomAutomationController);
#if defined(OS_WIN)
if (include_testing_id_) {
@@ -261,12 +269,10 @@ void UITest::LaunchBrowser(const std::wstring& arguments, bool clear_profile) {
// this by passing an url (e.g. about:blank) on the command line, but
// I decided to keep using the old switch in the existing use case to
// minimize changes in behavior.
- CommandLine::AppendSwitchWithValue(&command_line,
- switches::kAutomationClientChannelID,
+ command_line.AppendSwitchWithValue(switches::kAutomationClientChannelID,
server_->channel_id());
} else {
- CommandLine::AppendSwitchWithValue(&command_line,
- switches::kTestingChannelID,
+ command_line.AppendSwitchWithValue(switches::kTestingChannelID,
server_->channel_id());
}
}
@@ -276,56 +282,52 @@ void UITest::LaunchBrowser(const std::wstring& arguments, bool clear_profile) {
#endif
if (!show_error_dialogs_)
- CommandLine::AppendSwitch(&command_line, switches::kNoErrorDialogs);
+ command_line.AppendSwitch(switches::kNoErrorDialogs);
if (in_process_renderer_)
- CommandLine::AppendSwitch(&command_line, switches::kSingleProcess);
+ command_line.AppendSwitch(switches::kSingleProcess);
if (in_process_plugins_)
- CommandLine::AppendSwitch(&command_line, switches::kInProcessPlugins);
+ command_line.AppendSwitch(switches::kInProcessPlugins);
if (no_sandbox_)
- CommandLine::AppendSwitch(&command_line, switches::kNoSandbox);
+ command_line.AppendSwitch(switches::kNoSandbox);
if (full_memory_dump_)
- CommandLine::AppendSwitch(&command_line, switches::kFullMemoryCrashReport);
+ command_line.AppendSwitch(switches::kFullMemoryCrashReport);
if (safe_plugins_)
- CommandLine::AppendSwitch(&command_line, switches::kSafePlugins);
+ command_line.AppendSwitch(switches::kSafePlugins);
if (enable_dcheck_)
- CommandLine::AppendSwitch(&command_line, switches::kEnableDCHECK);
+ command_line.AppendSwitch(switches::kEnableDCHECK);
if (silent_dump_on_dcheck_)
- CommandLine::AppendSwitch(&command_line, switches::kSilentDumpOnDCHECK);
+ command_line.AppendSwitch(switches::kSilentDumpOnDCHECK);
if (disable_breakpad_)
- CommandLine::AppendSwitch(&command_line, switches::kDisableBreakpad);
+ command_line.AppendSwitch(switches::kDisableBreakpad);
if (!homepage_.empty())
- CommandLine::AppendSwitchWithValue(&command_line,
- switches::kHomePage,
+ command_line.AppendSwitchWithValue(switches::kHomePage,
homepage_);
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
if (!user_data_dir_.empty())
- CommandLine::AppendSwitchWithValue(&command_line,
- switches::kUserDataDir,
+ command_line.AppendSwitchWithValue(switches::kUserDataDir,
user_data_dir_);
if (!js_flags_.empty())
- CommandLine::AppendSwitchWithValue(&command_line,
- switches::kJavaScriptFlags,
+ command_line.AppendSwitchWithValue(switches::kJavaScriptFlags,
js_flags_);
- CommandLine::AppendSwitch(&command_line, switches::kMetricsRecordingOnly);
+ command_line.AppendSwitch(switches::kMetricsRecordingOnly);
// We always want to enable chrome logging
- CommandLine::AppendSwitch(&command_line, switches::kEnableLogging);
+ command_line.AppendSwitch(switches::kEnableLogging);
if (dump_histograms_on_exit_)
- CommandLine::AppendSwitch(&command_line, switches::kDumpHistogramsOnExit);
+ command_line.AppendSwitch(switches::kDumpHistogramsOnExit);
#ifdef WAIT_FOR_DEBUGGER_ON_OPEN
- CommandLine::AppendSwitch(&command_line, switches::kDebugOnStart);
+ command_line.AppendSwitch(switches::kDebugOnStart);
#endif
if (!ui_test_name_.empty())
- CommandLine::AppendSwitchWithValue(&command_line,
- switches::kTestName,
+ command_line.AppendSwitchWithValue(switches::kTestName,
ui_test_name_);
DebugFlags::ProcessDebugFlags(&command_line, DebugFlags::UNKNOWN, false);
- command_line.append(L" " + arguments);
+ command_line.AppendArguments(arguments, false);
// Clear user data directory to make sure test environment is consistent
// We balk on really short (absolute) user_data_dir directory names, because
@@ -356,7 +358,7 @@ void UITest::LaunchBrowser(const std::wstring& arguments, bool clear_profile) {
if (use_existing_browser_) {
DWORD pid = 0;
HWND hwnd = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass,
- user_data_dir_.c_str());
+ user_data_dir_.c_str());
GetWindowThreadProcessId(hwnd, &pid);
// This mode doesn't work if we wound up launching a new browser ourselves.
ASSERT_NE(pid, base::GetProcId(process_));
diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h
index 7f6c906..31ad827 100644
--- a/chrome/test/ui/ui_test.h
+++ b/chrome/test/ui/ui_test.h
@@ -24,6 +24,7 @@
#endif
#include <string>
+#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/process.h"
@@ -75,8 +76,8 @@ class UITest : public testing::Test {
// Closes the browser and IPC testing server.
void CloseBrowserAndServer();
- // Launches the browser with the given arguments.
- void LaunchBrowser(const std::wstring& arguments, bool clear_profile);
+ // Launches the browser with the given command line.
+ void LaunchBrowser(const CommandLine& cmdline, bool clear_profile);
// Exits out browser instance.
void QuitBrowser();
@@ -389,7 +390,7 @@ class UITest : public testing::Test {
// with no trailing slash
std::wstring test_data_directory_; // Path to the unit test data,
// with no trailing slash
- std::wstring launch_arguments_; // Arguments to the browser on launch.
+ CommandLine launch_arguments_; // Command to launch the browser
size_t expected_errors_; // The number of errors expected during
// the run (generally 0).
int expected_crashes_; // The number of crashes expected during
diff --git a/chrome/test/ui/ui_test_suite.h b/chrome/test/ui/ui_test_suite.h
index b3d609f..07f6c76 100644
--- a/chrome/test/ui/ui_test_suite.h
+++ b/chrome/test/ui/ui_test_suite.h
@@ -18,7 +18,7 @@ class UITestSuite : public ChromeTestSuite {
virtual void Initialize() {
ChromeTestSuite::Initialize();
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
UITest::set_in_process_renderer(
parsed_command_line.HasSwitch(switches::kSingleProcess));
UITest::set_in_process_plugins(
diff --git a/chrome/test/unit/chrome_test_suite.h b/chrome/test/unit/chrome_test_suite.h
index 8847988..b2c196b 100644
--- a/chrome/test/unit/chrome_test_suite.h
+++ b/chrome/test/unit/chrome_test_suite.h
@@ -41,7 +41,8 @@ protected:
// NOTE: The user data directory will be erased before each UI test that
// uses it, in order to ensure consistency.
std::wstring user_data_dir =
- CommandLine().GetSwitchValue(switches::kUserDataDir);
+ CommandLine::ForCurrentProcess()->GetSwitchValue(
+ switches::kUserDataDir);
if (user_data_dir.empty() &&
PathService::Get(base::DIR_EXE, &user_data_dir))
file_util::AppendToPath(&user_data_dir, L"test_user_data");
diff --git a/chrome/tools/test/image_diff/image_diff.cc b/chrome/tools/test/image_diff/image_diff.cc
index c21003d..044b89c 100644
--- a/chrome/tools/test/image_diff/image_diff.cc
+++ b/chrome/tools/test/image_diff/image_diff.cc
@@ -320,13 +320,8 @@ int DiffImages(const char* file1, const char* file2, const char* out_file) {
int main(int argc, const char* argv[]) {
base::EnableTerminationOnHeapCorruption();
- // TODO(estade): why does using the default constructor (command line
- // singleton) cause an exception when run in debug mode?
-#if defined(OS_WIN)
- CommandLine parsed_command_line(::GetCommandLine());
-#elif defined(OS_POSIX)
- CommandLine parsed_command_line(argc, argv);
-#endif
+ CommandLine::Init(argc, argv);
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(kOptionPollStdin)) {
// Watch stdin for filenames.
std::string stdin_buffer;
@@ -353,15 +348,14 @@ int main(int argc, const char* argv[]) {
return 0;
}
+ std::vector<std::wstring> values = parsed_command_line.GetLooseValues();
if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) {
- if (3 == parsed_command_line.GetLooseValueCount()) {
- CommandLine::LooseValueIterator iter =
- parsed_command_line.GetLooseValuesBegin();
- return DiffImages(WideToUTF8(*iter).c_str(),
- WideToUTF8(*(iter + 1)).c_str(),
- WideToUTF8(*(iter + 2)).c_str());
+ if (values.size() == 3) {
+ return DiffImages(WideToUTF8(values[0]).c_str(),
+ WideToUTF8(values[1]).c_str(),
+ WideToUTF8(values[2]).c_str());
}
- } else if (2 == parsed_command_line.GetLooseValueCount()) {
+ } else if (values.size() == 2) {
return CompareImages(argv[1], argv[2]);
}
diff --git a/chrome/views/window.cc b/chrome/views/window.cc
index 1a3ad56..dbc55ed 100644
--- a/chrome/views/window.cc
+++ b/chrome/views/window.cc
@@ -237,7 +237,7 @@ void Window::Observe(NotificationType type,
// This window is closed when the last app window is closed.
DCHECK(type == NOTIFY_ALL_APPWINDOWS_CLOSED);
// Only registered as an observer when we're not an app window.
- DCHECK(!IsAppWindow());
+ // XXX DCHECK(!IsAppWindow());
Close();
}
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index 03fb4c1..8ad94e2 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -36,14 +36,8 @@ int RunSlave(int iteration) {
std::wstring exe;
PathService::Get(base::FILE_EXE, &exe);
-#if defined(OS_WIN)
- CommandLine cmdline(StringPrintf(L"%ls %d", exe.c_str(), iteration));
-#elif defined(OS_POSIX)
- std::vector<std::string> cmd_argv;
- cmd_argv.push_back(WideToUTF8(exe));
- cmd_argv.push_back(IntToString(iteration));
- CommandLine cmdline(cmd_argv);
-#endif
+ CommandLine cmdline(exe);
+ cmdline.AppendLooseValue(ASCIIToWide(IntToString(iteration)));
base::ProcessHandle handle;
if (!base::LaunchApp(cmdline, false, false, &handle)) {
diff --git a/net/tools/crash_cache/crash_cache.cc b/net/tools/crash_cache/crash_cache.cc
index df641a2..9d6f3d6 100644
--- a/net/tools/crash_cache/crash_cache.cc
+++ b/net/tools/crash_cache/crash_cache.cc
@@ -40,14 +40,8 @@ int RunSlave(RankCrashes action) {
std::wstring exe;
PathService::Get(base::FILE_EXE, &exe);
-#if defined(OS_WIN)
- CommandLine cmdline(StringPrintf(L"%ls %d", exe.c_str(), action));
-#elif defined(OS_POSIX)
- std::vector<std::string> cmd_argv;
- cmd_argv.push_back(WideToUTF8(exe));
- cmd_argv.push_back(IntToString(action));
- CommandLine cmdline(cmd_argv);
-#endif
+ CommandLine cmdline(exe);
+ cmdline.AppendLooseValue(ASCIIToWide(IntToString(action)));
base::ProcessHandle handle;
if (!base::LaunchApp(cmdline, false, false, &handle)) {
diff --git a/net/tools/tld_cleanup/tld_cleanup.cc b/net/tools/tld_cleanup/tld_cleanup.cc
index 797a669..792faad 100644
--- a/net/tools/tld_cleanup/tld_cleanup.cc
+++ b/net/tools/tld_cleanup/tld_cleanup.cc
@@ -208,9 +208,7 @@ int main(int argc, const char* argv[]) {
logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG;
#endif
-#if defined(OS_LINUX)
- CommandLine::SetArgcArgv(argc, argv);
-#endif
+ CommandLine::Init(argc, argv);
FilePath log_filename;
PathService::Get(base::DIR_EXE, &log_filename);
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 2689064..7728f6c 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -42,7 +42,7 @@ URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
// We cache the value of the switch because this code path is hit on every
// network request.
static const bool kForceHTTPS =
- CommandLine().HasSwitch(switches::kForceHTTPS);
+ CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceHTTPS);
if (kForceHTTPS && scheme != "https")
return new URLRequestErrorJob(request, net::ERR_DISALLOWED_URL_SCHEME);
@@ -385,7 +385,8 @@ void URLRequestHttpJob::OnStartCompleted(int result) {
if (result == net::OK) {
NotifyHeadersComplete();
} else if (net::IsCertificateError(result) &&
- !CommandLine().HasSwitch(switches::kForceHTTPS)) {
+ !CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kForceHTTPS)) {
// We encountered an SSL certificate error. Ask our delegate to decide
// what we should do.
// TODO(wtc): also pass ssl_info.cert_status, or just pass the whole
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index c2158aa..58a0218 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -349,7 +349,9 @@ class BaseTestServer : public base::ProcessFilter,
}
#elif defined(OS_POSIX)
void LaunchApp(const std::vector<std::string>& command_line) {
- ASSERT_TRUE(base::LaunchApp(command_line, false, true, &process_handle_)) <<
+ base::file_handle_mapping_vector fds_empty;
+ ASSERT_TRUE(base::LaunchApp(command_line, fds_empty, false,
+ &process_handle_)) <<
"Failed to launch " << command_line[0] << " ...";
}
#endif
diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc
index 9fbb2d7..7f8a309 100644
--- a/skia/ext/vector_canvas_unittest.cc
+++ b/skia/ext/vector_canvas_unittest.cc
@@ -397,7 +397,8 @@ class VectorCanvasTest : public ImageTest {
// Returns COMPARE, which is the default. If kGenerateSwitch command
// line argument is used to start this process, GENERATE is returned instead.
static ProcessAction CurrentMode() {
- return CommandLine().HasSwitch(kGenerateSwitch) ? GENERATE : COMPARE;
+ return CommandLine::ForCurrentProcess()->HasSwitch(kGenerateSwitch) ?
+ GENERATE : COMPARE;
}
// Length in x and y of the square canvas.
diff --git a/webkit/activex_shim/activex_shared.cc b/webkit/activex_shim/activex_shared.cc
index 0b12b57..ee146b9 100644
--- a/webkit/activex_shim/activex_shared.cc
+++ b/webkit/activex_shim/activex_shared.cc
@@ -88,8 +88,8 @@ static bool IsAllowAllActiveX() {
static bool parsed_flag = false;
static bool allow_all_activex = false;
if (!parsed_flag) {
- CommandLine command_line;
- allow_all_activex = command_line.HasSwitch(kAllowAllActiveX);
+ allow_all_activex =
+ CommandLine::ForCurrentProcess()->HasSwitch(kAllowAllActiveX);
parsed_flag = true;
}
return allow_all_activex;
diff --git a/webkit/glue/plugins/plugin_list_win.cc b/webkit/glue/plugins/plugin_list_win.cc
index d15584c..2aaf983 100644
--- a/webkit/glue/plugins/plugin_list_win.cc
+++ b/webkit/glue/plugins/plugin_list_win.cc
@@ -195,7 +195,7 @@ namespace NPAPI
{
void PluginList::PlatformInit() {
- CommandLine command_line;
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
dont_load_new_wmp_ = command_line.HasSwitch(kUseOldWMPPluginSwitch);
use_internal_activex_shim_ =
!command_line.HasSwitch(kNoNativeActiveXShimSwitch);
diff --git a/webkit/tools/test_shell/mac/main.mm b/webkit/tools/test_shell/mac/main.mm
index 19c3507..535ac24 100644
--- a/webkit/tools/test_shell/mac/main.mm
+++ b/webkit/tools/test_shell/mac/main.mm
@@ -115,8 +115,8 @@ int main(const int argc, const char *argv[]) {
// the windows version, so that we can run the same test scripts. stop
// if we hit something that's not a switch (like, oh, a URL).
- CommandLine::SetArgcArgv(argc, argv);
- CommandLine parsed_command_line(argc, argv);
+ CommandLine::Init(argc, argv);
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(test_shell::kCheckLayoutTestSystemDeps)) {
// Always succeed the deps check, currently just used by windows port.
@@ -167,7 +167,7 @@ int main(const int argc, const char *argv[]) {
std::wstring javascript_flags =
parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags);
// Test shell always exposes the GC.
- CommandLine::AppendSwitch(&javascript_flags, L"expose-gc");
+ javascript_flags += L" --expose-gc";
webkit_glue::SetJavaScriptFlags(javascript_flags);
// Load and initialize the stats table (one per process, so that multiple
@@ -235,12 +235,10 @@ int main(const int argc, const char *argv[]) {
uri = UTF8ToWide([testShellURL UTF8String]);
}
- if (parsed_command_line.GetLooseValueCount() > 0) {
- CommandLine::LooseValueIterator iter =
- parsed_command_line.GetLooseValuesBegin();
- uri = *iter;
- }
-
+ std::vector<std::wstring> values = parsed_command_line.GetLooseValues();
+ if (values.size() > 0)
+ uri = values[0];
+
TestShell* shell;
if (TestShell::CreateNewWindow(uri, &shell)) {
#ifdef NOTYET
diff --git a/webkit/tools/test_shell/node_leak_test.cc b/webkit/tools/test_shell/node_leak_test.cc
index 97549c6..f24172a 100644
--- a/webkit/tools/test_shell/node_leak_test.cc
+++ b/webkit/tools/test_shell/node_leak_test.cc
@@ -30,11 +30,11 @@ const wchar_t kTestUrlSwitch[] = L"test-url";
class NodeLeakTest : public TestShellTest {
public:
virtual void SetUp() {
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
- std::wstring js_flags =
- parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags);
- CommandLine::AppendSwitch(&js_flags, L"expose-gc");
+ std::wstring js_flags =
+ parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags);
+ js_flags += L" --expose-gc";
webkit_glue::SetJavaScriptFlags(js_flags);
// Expose GCController to JavaScript as well.
webkit_glue::SetShouldExposeGCController(true);
@@ -66,7 +66,7 @@ class NodeLeakTest : public TestShellTest {
virtual void TearDown() {
TestShellTest::TearDown();
-
+
SimpleResourceLoaderBridge::Shutdown();
}
@@ -80,7 +80,7 @@ class NodeLeakTest : public TestShellTest {
};
TEST_F(NodeLeakTest, TestURL) {
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(kTestUrlSwitch)) {
NavigateToURL(parsed_command_line.GetSwitchValue(kTestUrlSwitch).c_str());
}
diff --git a/webkit/tools/test_shell/run_all_tests.cc b/webkit/tools/test_shell/run_all_tests.cc
index d7ff3d0..9d5cfb7 100644
--- a/webkit/tools/test_shell/run_all_tests.cc
+++ b/webkit/tools/test_shell/run_all_tests.cc
@@ -48,15 +48,13 @@ int main(int argc, char* argv[]) {
base::EnableTerminationOnHeapCorruption();
// Some unittests may use base::Singleton<>, thus we need to instanciate
// the AtExitManager or else we will leak objects.
- base::AtExitManager at_exit_manager;
+ base::AtExitManager at_exit_manager;
#if defined(OS_LINUX)
gtk_init(&argc, &argv);
#endif
-#if defined(OS_POSIX)
- CommandLine::SetArgcArgv(argc, argv);
-#endif
+ CommandLine::Init(argc, argv);
// Suppress error dialogs and do not show GP fault error box on Windows.
TestShell::InitLogging(true, false, false);
diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc
index 3247022..ced93a5 100755
--- a/webkit/tools/test_shell/test_shell.cc
+++ b/webkit/tools/test_shell/test_shell.cc
@@ -501,7 +501,7 @@ void TestShell::SetFocus(WebWidgetHost* host, bool enable) {
namespace webkit_glue {
bool IsMediaPlayerAvailable() {
- return CommandLine().HasSwitch(test_shell::kEnableVideo);
+ return CommandLine::ForCurrentProcess()->HasSwitch(test_shell::kEnableVideo);
}
void PrefetchDns(const std::string& hostname) {}
diff --git a/webkit/tools/test_shell/test_shell_main.cc b/webkit/tools/test_shell/test_shell_main.cc
index d24c42d..3e4ecf3 100644
--- a/webkit/tools/test_shell/test_shell_main.cc
+++ b/webkit/tools/test_shell/test_shell_main.cc
@@ -134,11 +134,12 @@ int main(int argc, char* argv[]) {
#if defined(OS_LINUX)
gtk_init(&argc, &argv);
- // Only parse the command line after GTK's had a crack at it.
- CommandLine::SetArgcArgv(argc, argv);
#endif
- CommandLine parsed_command_line;
+ // Only parse the command line after GTK's had a crack at it.
+ CommandLine::Init(argc, argv);
+
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(test_shell::kStartupDialog))
TestShell::ShowStartupDebuggingDialog();
@@ -265,16 +266,14 @@ int main(int argc, char* argv[]) {
file_util::AppendToPath(&uri, L"index.html");
}
- if (parsed_command_line.GetLooseValueCount() > 0) {
- CommandLine::LooseValueIterator iter(
- parsed_command_line.GetLooseValuesBegin());
- uri = *iter;
- }
+ std::vector<std::wstring> loose_values = parsed_command_line.GetLooseValues();
+ if (loose_values.size() > 0)
+ uri = loose_values[0];
- std::wstring js_flags =
+ std::wstring js_flags =
parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags);
// Test shell always exposes the GC.
- CommandLine::AppendSwitch(&js_flags, L"expose-gc");
+ js_flags += L" --expose-gc";
webkit_glue::SetJavaScriptFlags(js_flags);
// Also expose GCController to JavaScript.
webkit_glue::SetShouldExposeGCController(true);
diff --git a/webkit/tools/test_shell/test_shell_win.cc b/webkit/tools/test_shell/test_shell_win.cc
index a6ba571..81baf04 100644
--- a/webkit/tools/test_shell/test_shell_win.cc
+++ b/webkit/tools/test_shell/test_shell_win.cc
@@ -151,7 +151,7 @@ void TestShell::InitializeTestShell(bool layout_test_mode) {
DCHECK(rc != 0);
}
- CommandLine parsed_command_line;
+ const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
if (parsed_command_line.HasSwitch(test_shell::kCrashDumps)) {
std::wstring dir(
parsed_command_line.GetSwitchValue(test_shell::kCrashDumps));