Commit 3db6d1d7 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Tidy up some browser switch handling code.

Change-Id: Ibab32e3da920f0fb643efcd1e3807630fd62a849
Reviewed-on: https://chromium-review.googlesource.com/775180Reviewed-by: default avatarKevin Bailey <krb@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517162}
parent 7321bdc1
......@@ -1414,14 +1414,9 @@ bool BrowserProcessImpl::IsRunningInBackground() const {
KeepAliveRegistry::GetInstance()->IsKeepingAlive();
}
// Switches to add when auto-restarting Chrome.
const char* const kSwitchesToAddOnAutorestart[] = {
switches::kNoStartupWindow
};
void BrowserProcessImpl::RestartBackgroundInstance() {
base::CommandLine* old_cl = base::CommandLine::ForCurrentProcess();
auto new_cl = base::MakeUnique<base::CommandLine>(old_cl->GetProgram());
auto new_cl = std::make_unique<base::CommandLine>(old_cl->GetProgram());
base::CommandLine::SwitchMap switches = old_cl->GetSwitches();
switches::RemoveSwitchesForAutostart(&switches);
......@@ -1429,17 +1424,22 @@ void BrowserProcessImpl::RestartBackgroundInstance() {
// Append the rest of the switches (along with their values, if any)
// to the new command line
for (const auto& it : switches) {
base::CommandLine::StringType switch_value = it.second;
if (switch_value.length() > 0)
new_cl->AppendSwitchNative(it.first, it.second);
const auto& switch_name = it.first;
const auto& switch_value = it.second;
if (switch_value.empty())
new_cl->AppendSwitch(switch_name);
else
new_cl->AppendSwitch(it.first);
new_cl->AppendSwitchNative(switch_name, switch_value);
}
// Switches to add when auto-restarting Chrome.
static constexpr const char* kSwitchesToAddOnAutorestart[] = {
switches::kNoStartupWindow};
// Ensure that our desired switches are set on the new process.
for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) {
if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i]))
new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]);
for (const char* switch_to_add : kSwitchesToAddOnAutorestart) {
if (!new_cl->HasSwitch(switch_to_add))
new_cl->AppendSwitch(switch_to_add);
}
#if defined(OS_WIN)
......@@ -1449,7 +1449,6 @@ void BrowserProcessImpl::RestartBackgroundInstance() {
DLOG(WARNING) << "Shutting down current instance of the browser.";
chrome::AttemptExit();
// Transfer ownership to Upgrade.
upgrade_util::SetNewCommandLine(new_cl.release());
}
......
......@@ -209,7 +209,7 @@ bool RecordShutdownInfoPrefs() {
void ShutdownPostThreadsStop(int shutdown_flags) {
delete g_browser_process;
g_browser_process = NULL;
g_browser_process = nullptr;
// crbug.com/95079 - This needs to happen after the browser process object
// goes away.
......@@ -228,7 +228,9 @@ void ShutdownPostThreadsStop(int shutdown_flags) {
#endif
if (shutdown_flags & RESTART_LAST_SESSION) {
#if !defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS)
NOTIMPLEMENTED();
#else
// Make sure to relaunch the browser with the original command line plus
// the Restore Last Session flag. Note that Chrome can be launched (ie.
// through ShellExecute on Windows) with a switch argument terminator at
......@@ -237,30 +239,25 @@ void ShutdownPostThreadsStop(int shutdown_flags) {
// 46182). We therefore use GetSwitches to copy the command line (it stops
// at the switch argument terminator).
base::CommandLine old_cl(*base::CommandLine::ForCurrentProcess());
std::unique_ptr<base::CommandLine> new_cl(
new base::CommandLine(old_cl.GetProgram()));
auto new_cl = std::make_unique<base::CommandLine>(old_cl.GetProgram());
base::CommandLine::SwitchMap switches = old_cl.GetSwitches();
// Remove the switches that shouldn't persist across restart.
about_flags::RemoveFlagsSwitches(&switches);
switches::RemoveSwitchesForAutostart(&switches);
// Append the old switches to the new command line.
for (const auto& it : switches) {
const base::CommandLine::StringType& switch_value = it.second;
if (!switch_value.empty())
new_cl->AppendSwitchNative(it.first, it.second);
const auto& switch_name = it.first;
const auto& switch_value = it.second;
if (switch_value.empty())
new_cl->AppendSwitch(switch_name);
else
new_cl->AppendSwitch(it.first);
new_cl->AppendSwitchNative(switch_name, switch_value);
}
if (shutdown_flags & RESTART_IN_BACKGROUND)
new_cl->AppendSwitch(switches::kNoStartupWindow);
#if defined(OS_POSIX) || defined(OS_WIN)
upgrade_util::RelaunchChromeBrowser(*new_cl.get());
#endif // defined(OS_WIN)
#else
NOTIMPLEMENTED();
#endif // !defined(OS_CHROMEOS)
upgrade_util::RelaunchChromeBrowser(*new_cl);
#endif // defined(OS_CHROMEOS)
}
if (g_shutdown_type > NOT_VALID && g_shutdown_num_processes > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment