Skip to content

Commit

Permalink
Use GetSwitchValueASCII.
Browse files Browse the repository at this point in the history
BUG=24672
TEST=None

Original patch by Thiago Farina <thiago.farina@gmail.com> at
http://codereview.chromium.org/296004

Review URL: http://codereview.chromium.org/373013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31269 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tony@chromium.org committed Nov 6, 2009
1 parent 2fd94bb commit c4e52f0
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 88 deletions.
13 changes: 7 additions & 6 deletions base/command_line_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ TEST(CommandLineTest, CommandLineConstructor) {
EXPECT_TRUE(cl.HasSwitch("other-switches"));
EXPECT_TRUE(cl.HasSwitch("input-translation"));

EXPECT_EQ(L"Crepe", cl.GetSwitchValue("spaetzle"));
EXPECT_EQ(L"", cl.GetSwitchValue("Foo"));
EXPECT_EQ(L"", cl.GetSwitchValue("bar"));
EXPECT_EQ(L"", cl.GetSwitchValue("cruller"));
EXPECT_EQ(L"--dog=canine --cat=feline", cl.GetSwitchValue("other-switches"));
EXPECT_EQ(L"45--output-rotation", cl.GetSwitchValue("input-translation"));
EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle"));
EXPECT_EQ("", cl.GetSwitchValueASCII("Foo"));
EXPECT_EQ("", cl.GetSwitchValueASCII("bar"));
EXPECT_EQ("", cl.GetSwitchValueASCII("cruller"));
EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII(
"other-switches"));
EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation"));

std::vector<std::wstring> loose_values = cl.GetLooseValues();
ASSERT_EQ(5U, loose_values.size());
Expand Down
49 changes: 24 additions & 25 deletions chrome/browser/browser_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,

if (command_line_.HasSwitch(switches::kRemoteShellPort)) {
if (!RenderProcessHost::run_renderer_in_process()) {
std::wstring port_str =
command_line_.GetSwitchValue(switches::kRemoteShellPort);
int64 port = StringToInt64(WideToUTF16Hack(port_str));
std::string port_str =
command_line_.GetSwitchValueASCII(switches::kRemoteShellPort);
int64 port = StringToInt64(port_str);
if (port > 0 && port < 65535) {
g_browser_process->InitDebuggerWrapper(static_cast<int>(port));
} else {
Expand All @@ -419,8 +419,8 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
}

if (command_line_.HasSwitch(switches::kUserAgent)) {
webkit_glue::SetUserAgent(WideToUTF8(
command_line_.GetSwitchValue(switches::kUserAgent)));
webkit_glue::SetUserAgent(command_line_.GetSwitchValueASCII(
switches::kUserAgent));
}

// Open the required browser windows and tabs.
Expand Down Expand Up @@ -479,7 +479,7 @@ bool BrowserInit::LaunchWithProfile::OpenApplicationURL(Profile* profile) {
if (!command_line_.HasSwitch(switches::kApp))
return false;

GURL url(WideToUTF8(command_line_.GetSwitchValue(switches::kApp)));
GURL url(command_line_.GetSwitchValueASCII(switches::kApp));
if (!url.is_empty() && url.is_valid()) {
Browser::OpenApplicationWindow(profile, url);
return true;
Expand Down Expand Up @@ -551,10 +551,10 @@ Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(

int pin_count = 0;
if (!browser) {
std::wstring pin_count_string =
command_line_.GetSwitchValue(switches::kPinnedTabCount);
std::string pin_count_string =
command_line_.GetSwitchValueASCII(switches::kPinnedTabCount);
if (!pin_count_string.empty())
pin_count = StringToInt(WideToUTF16Hack(pin_count_string));
pin_count = StringToInt(pin_count_string);
}
if (!browser || browser->type() != Browser::TYPE_NORMAL)
browser = Browser::Create(profile_);
Expand Down Expand Up @@ -687,11 +687,11 @@ bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line,
BrowserInit* browser_init) {
DCHECK(profile);
if (process_startup) {
const std::wstring popup_count_string =
command_line.GetSwitchValue(switches::kOmniBoxPopupCount);
const std::string popup_count_string =
command_line.GetSwitchValueASCII(switches::kOmniBoxPopupCount);
if (!popup_count_string.empty()) {
int count = 0;
if (StringToInt(WideToUTF16Hack(popup_count_string), &count)) {
if (StringToInt(popup_count_string, &count)) {
const int popup_count = std::max(0, count);
AutocompleteResult::set_max_matches(popup_count);
AutocompleteProvider::set_max_matches(popup_count / 2);
Expand All @@ -701,30 +701,29 @@ bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line,
if (command_line.HasSwitch(switches::kDisablePromptOnRepost))
NavigationController::DisablePromptOnRepost();

const std::wstring tab_count_string =
command_line.GetSwitchValue(switches::kTabCountToLoadOnSessionRestore);
const std::string tab_count_string = command_line.GetSwitchValueASCII(
switches::kTabCountToLoadOnSessionRestore);
if (!tab_count_string.empty()) {
int count = 0;
if (StringToInt(WideToUTF16Hack(tab_count_string), &count)) {
if (StringToInt(tab_count_string, &count)) {
const int tab_count = std::max(0, count);
SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count);
}
}

// Look for the testing channel ID ONLY during process startup
if (command_line.HasSwitch(switches::kTestingChannelID)) {
std::string testing_channel_id = WideToASCII(
command_line.GetSwitchValue(switches::kTestingChannelID));
std::string testing_channel_id = command_line.GetSwitchValueASCII(
switches::kTestingChannelID);
// TODO(sanjeevr) Check if we need to make this a singleton for
// compatibility with the old testing code
// If there are any loose parameters, we expect each one to generate a
// new tab; if there are none then we get one homepage tab.
int expected_tab_count = 1;
if (command_line.HasSwitch(switches::kRestoreLastSession)) {
std::wstring restore_session_value(
command_line.GetSwitchValue(switches::kRestoreLastSession));
StringToInt(WideToUTF16Hack(restore_session_value),
&expected_tab_count);
std::string restore_session_value(
command_line.GetSwitchValueASCII(switches::kRestoreLastSession));
StringToInt(restore_session_value, &expected_tab_count);
} else {
expected_tab_count =
std::max(1, static_cast<int>(command_line.GetLooseValues().size()));
Expand All @@ -741,8 +740,8 @@ bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line,
switches::kPackExtension));
FilePath private_key_path;
if (command_line.HasSwitch(switches::kPackExtensionKey)) {
private_key_path = FilePath::FromWStringHack(
command_line.GetSwitchValue(switches::kPackExtensionKey));
private_key_path = command_line.GetSwitchValuePath(
switches::kPackExtensionKey);
}

// Output Paths.
Expand Down Expand Up @@ -792,8 +791,8 @@ bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line,

bool silent_launch = false;
if (command_line.HasSwitch(switches::kAutomationClientChannelID)) {
std::string automation_channel_id = WideToASCII(
command_line.GetSwitchValue(switches::kAutomationClientChannelID));
std::string automation_channel_id = command_line.GetSwitchValueASCII(
switches::kAutomationClientChannelID);
// 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 =
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/external_cookie_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void ExternalCookieHandler::GetCookies(const CommandLine& parsed_command_line,
// If there are Google External SSO cookies, add them to the cookie store.
if (parsed_command_line.HasSwitch(switches::kCookiePipe)) {
std::string pipe_name =
WideToASCII(parsed_command_line.GetSwitchValue(switches::kCookiePipe));
parsed_command_line.GetSwitchValueASCII(switches::kCookiePipe);
ExternalCookieHandler cookie_handler(new PipeReader(pipe_name));
cookie_handler.HandleCookies(
profile->GetRequestContext()->GetCookieStore());
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/extensions/extensions_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ ExtensionsService::ExtensionsService(Profile* profile,
if (autoupdate_enabled) {
int update_frequency = kDefaultUpdateFrequencySeconds;
if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) {
update_frequency = StringToInt(WideToASCII(command_line->GetSwitchValue(
switches::kExtensionsUpdateFrequency)));
update_frequency = StringToInt(command_line->GetSwitchValueASCII(
switches::kExtensionsUpdateFrequency));
}
updater_ = new ExtensionUpdater(this, prefs, update_frequency);
}
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/first_run_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class HungImporterMonitor : public WorkerThreadTicker::Callback {
HWND owner_window_;
base::ProcessHandle import_process_;
WorkerThreadTicker ticker_;
DISALLOW_EVIL_CONSTRUCTORS(HungImporterMonitor);
DISALLOW_COPY_AND_ASSIGN(HungImporterMonitor);
};

// This class is used by FirstRun::ImportNow to get notified of the outcome of
Expand Down Expand Up @@ -541,7 +541,7 @@ class FirstRunImportObserver : public ImportObserver {

bool loop_running_;
int import_result_;
DISALLOW_EVIL_CONSTRUCTORS(FirstRunImportObserver);
DISALLOW_COPY_AND_ASSIGN(FirstRunImportObserver);
};

std::wstring EncodeImportParams(int browser_type, int options, HWND window) {
Expand Down Expand Up @@ -575,7 +575,7 @@ bool FirstRun::ImportSettings(Profile* profile, int browser_type,
if (cmdline.HasSwitch(switches::kUserDataDir)) {
import_cmd.AppendSwitchWithValue(
switches::kUserDataDir,
cmdline.GetSwitchValue(switches::kUserDataDir));
cmdline.GetSwitchValueASCII(switches::kUserDataDir));
}

// Since ImportSettings is called before the local state is stored on disk
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/nacl_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool NaClProcessHost::LaunchSelLdr(ResourceMessageFilter* renderer_msg_filter,
if (browser_command_line.HasSwitch(switch_names[i])) {
cmd_line.AppendSwitchWithValue(
switch_names[i],
browser_command_line.GetSwitchValue(switch_names[i]));
browser_command_line.GetSwitchValueASCII(switch_names[i]));
}
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/plugin_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ bool PluginProcessHost::Init(const WebPluginInfo& info,
if (browser_command_line.HasSwitch(switch_names[i])) {
cmd_line.AppendSwitchWithValue(
switch_names[i],
browser_command_line.GetSwitchValue(switch_names[i]));
browser_command_line.GetSwitchValueASCII(switch_names[i]));
}
}

Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/plugin_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ PluginService::PluginService()
ChromePluginLib::RegisterPluginsWithNPAPI();
// Load the one specified on the command line as well.
const CommandLine* command_line = CommandLine::ForCurrentProcess();
std::wstring path = command_line->GetSwitchValue(switches::kLoadPlugin);
FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
if (!path.empty()) {
NPAPI::PluginList::Singleton()->AddExtraPluginPath(
FilePath::FromWStringHack(path));
NPAPI::PluginList::Singleton()->AddExtraPluginPath(path);
}
#ifndef DISABLE_NACL
if (command_line->HasSwitch(switches::kInternalNaCl))
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/renderer_host/browser_render_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ void BrowserRenderProcessHost::AppendRendererCommandLine(
FieldTrialList::StatesToString(&field_trial_states);
if (!field_trial_states.empty()) {
command_line->AppendSwitchWithValue(switches::kForceFieldTestNameAndValue,
ASCIIToWide(field_trial_states));
field_trial_states);
}

// A command prefix is something prepended to the command line of the spawned
Expand All @@ -499,8 +499,8 @@ void BrowserRenderProcessHost::AppendRendererCommandLine(

ChildProcessHost::SetCrashReporterCommandLine(command_line);

const std::wstring& profile_path =
browser_command_line.GetSwitchValue(switches::kUserDataDir);
const std::string& profile_path =
browser_command_line.GetSwitchValueASCII(switches::kUserDataDir);
if (!profile_path.empty())
command_line->AppendSwitchWithValue(switches::kUserDataDir, profile_path);
}
Expand Down Expand Up @@ -566,7 +566,7 @@ void BrowserRenderProcessHost::PropogateBrowserCommandLineToRenderer(
for (size_t i = 0; i < arraysize(switch_names); ++i) {
if (browser_cmd.HasSwitch(switch_names[i])) {
renderer_cmd->AppendSwitchWithValue(switch_names[i],
browser_cmd.GetSwitchValue(switch_names[i]));
browser_cmd.GetSwitchValueASCII(switch_names[i]));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/sessions/session_restore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ class SessionRestoreImpl : public NotificationObserver {
bool pin_tabs) {
int pin_count = 0;
if (pin_tabs) {
std::wstring pin_count_string =
CommandLine::ForCurrentProcess()->GetSwitchValue(
std::string pin_count_string =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kPinnedTabCount);
if (!pin_count_string.empty())
pin_count = StringToInt(WideToUTF16Hack(pin_count_string));
pin_count = StringToInt(pin_count_string);
}

for (size_t i = 0; i < urls.size(); ++i) {
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/sync/profile_sync_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ void ProfileSyncService::InitSettings() {
// Override the sync server URL from the command-line, if sync server
// command-line argument exists.
if (command_line.HasSwitch(switches::kSyncServiceURL)) {
std::wstring value(command_line.GetSwitchValue(switches::kSyncServiceURL));
std::string value(command_line.GetSwitchValueASCII(
switches::kSyncServiceURL));
if (!value.empty()) {
GURL custom_sync_url(WideToUTF8(value));
GURL custom_sync_url(value);
if (custom_sync_url.is_valid()) {
sync_service_url_ = custom_sync_url;
} else {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/zygote_host_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ void ZygoteHost::Init(const std::string& sandbox_cmd) {
}
if (browser_command_line.HasSwitch(switches::kLoggingLevel)) {
cmd_line.AppendSwitchWithValue(switches::kLoggingLevel,
browser_command_line.GetSwitchValue(
browser_command_line.GetSwitchValueASCII(
switches::kLoggingLevel));
}
if (browser_command_line.HasSwitch(switches::kEnableLogging)) {
// Append with value to support --enable-logging=stderr.
cmd_line.AppendSwitchWithValue(switches::kEnableLogging,
browser_command_line.GetSwitchValue(
browser_command_line.GetSwitchValueASCII(
switches::kEnableLogging));
}
if (browser_command_line.HasSwitch(switches::kEnableSeccompSandbox)) {
Expand Down
11 changes: 5 additions & 6 deletions chrome/common/child_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@


ChildThread::ChildThread() {
channel_name_ = WideToASCII(
CommandLine::ForCurrentProcess()->GetSwitchValue(
switches::kProcessChannelID));
channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID);
Init();
}

Expand All @@ -32,9 +31,9 @@ void ChildThread::Init() {
check_with_browser_before_shutdown_ = false;
message_loop_ = MessageLoop::current();
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserAgent)) {
webkit_glue::SetUserAgent(WideToUTF8(
CommandLine::ForCurrentProcess()->GetSwitchValue(
switches::kUserAgent)));
webkit_glue::SetUserAgent(
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kUserAgent));
}

channel_.reset(new IPC::SyncChannel(channel_name_,
Expand Down
9 changes: 4 additions & 5 deletions chrome/common/chrome_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ namespace chrome {
bool GetGearsPluginPathFromCommandLine(FilePath* path) {
#ifndef NDEBUG
// for debugging, support a cmd line based override
std::wstring plugin_path = CommandLine::ForCurrentProcess()->GetSwitchValue(
switches::kGearsPluginPathOverride);
// TODO(tc): After GetSwitchNativeValue lands, we don't need to use
// FromWStringHack.
*path = FilePath::FromWStringHack(plugin_path);
FilePath plugin_path =
CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kGearsPluginPathOverride);
*path = plugin_path;
return !plugin_path.empty();
#else
return false;
Expand Down
13 changes: 7 additions & 6 deletions chrome/common/logging_chrome.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void InitChromeLogging(const CommandLine& command_line,
if (enable_logging) {
// Let --enable-logging=stderr force only stderr, particularly useful for
// non-debug builds where otherwise you can't get logs to stderr at all.
if (command_line.GetSwitchValue(switches::kEnableLogging) == L"stderr")
if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr")
log_mode = logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG;
else
log_mode = kDefaultLoggingMode;
Expand All @@ -141,15 +141,16 @@ void InitChromeLogging(const CommandLine& command_line,
command_line.HasSwitch(switches::kNoErrorDialogs))
SuppressDialogs();

std::wstring log_filter_prefix =
command_line.GetSwitchValue(switches::kLogFilterPrefix);
logging::SetLogFilterPrefix(WideToUTF8(log_filter_prefix).c_str());
std::string log_filter_prefix =
command_line.GetSwitchValueASCII(switches::kLogFilterPrefix);
logging::SetLogFilterPrefix(log_filter_prefix.c_str());

// Use a minimum log level if the command line has one, otherwise set the
// default to LOG_WARNING.
std::wstring log_level = command_line.GetSwitchValue(switches::kLoggingLevel);
std::string log_level = command_line.GetSwitchValueASCII(
switches::kLoggingLevel);
int level = 0;
if (StringToInt(WideToUTF16Hack(log_level), &level)) {
if (StringToInt(log_level, &level)) {
if ((level >= 0) && (level < LOG_NUM_SEVERITIES))
logging::SetMinLogLevel(level);
} else {
Expand Down
6 changes: 3 additions & 3 deletions chrome/test/unit/chrome_test_suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class ChromeTestSuite : public TestSuite {
// user data directory that lives alongside the current app.
// NOTE: The user data directory will be erased before each UI test that
// uses it, in order to ensure consistency.
FilePath user_data_dir = FilePath::FromWStringHack(
CommandLine::ForCurrentProcess()->GetSwitchValue(
switches::kUserDataDir));
FilePath user_data_dir =
CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kUserDataDir);
if (user_data_dir.empty() &&
file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_test_"),
&user_data_dir)) {
Expand Down
4 changes: 2 additions & 2 deletions courgette/courgette_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ int main(int argc, const char* argv[]) {
// '-repeat=N' is for debugging. Running many iterations can reveal leaks and
// bugs in cleanup.
int repeat_count = 1;
std::wstring repeat_switch = command_line.GetSwitchValue("repeat");
std::string repeat_switch = command_line.GetSwitchValueASCII("repeat");
if (!repeat_switch.empty())
if (!WideStringToInt(repeat_switch, &repeat_count))
if (!StringToInt(repeat_switch, &repeat_count))
repeat_count = 1;

if (cmd_dis + cmd_asm + cmd_disadj + cmd_make_patch + cmd_apply_patch +
Expand Down
Loading

0 comments on commit c4e52f0

Please sign in to comment.