From 9a08cbce274a0b08062a8cc1a81b4e07f4bffe81 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 2 Jun 2016 20:41:59 +0900 Subject: [PATCH] Uniform when to use args or argv --- atom/browser/browser.cc | 8 ++++++-- atom/browser/relauncher.cc | 32 +++++++++++++++----------------- atom/browser/relauncher.h | 5 ++--- atom/browser/relauncher_win.cc | 2 +- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 88eeaab986c..41d4ae5754d 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -9,6 +9,7 @@ #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" +#include "atom/common/atom_command_line.h" #include "base/files/file_util.h" #include "base/message_loop/message_loop.h" #include "base/path_service.h" @@ -35,13 +36,16 @@ Browser* Browser::Get() { bool Browser::Relaunch(const base::FilePath& app, const relauncher::StringVector& args) { + relauncher::StringVector argv; if (app.empty()) { base::FilePath exe_path; PathService::Get(base::FILE_EXE, &exe_path); - return relauncher::RelaunchApp(exe_path, args); + argv.push_back(exe_path.value()); } else { - return relauncher::RelaunchApp(app, args); + argv.push_back(app.value()); } + + return relauncher::RelaunchApp(argv); } void Browser::Quit() { diff --git a/atom/browser/relauncher.cc b/atom/browser/relauncher.cc index dce4f46b9a7..5362a7b78ae 100644 --- a/atom/browser/relauncher.cc +++ b/atom/browser/relauncher.cc @@ -34,7 +34,7 @@ const CharType* kRelauncherArgSeparator = FILE_PATH_LITERAL("---"); } // namespace internal -bool RelaunchApp(const base::FilePath& app, const StringVector& args) { +bool RelaunchApp(const StringVector& argv) { // Use the currently-running application's helper process. The automatic // update feature is careful to leave the currently-running version alone, // so this is safe even if the relaunch is the result of an update having @@ -48,24 +48,22 @@ bool RelaunchApp(const base::FilePath& app, const StringVector& args) { } StringVector relauncher_args; - return RelaunchAppWithHelper(app, child_path, relauncher_args, args); + return RelaunchAppWithHelper(child_path, relauncher_args, argv); } -bool RelaunchAppWithHelper(const base::FilePath& app, - const base::FilePath& helper, +bool RelaunchAppWithHelper(const base::FilePath& helper, const StringVector& relauncher_args, - const StringVector& args) { - StringVector relaunch_args; - relaunch_args.push_back(helper.value()); - relaunch_args.push_back(internal::kRelauncherTypeArg); + const StringVector& argv) { + StringVector relaunch_argv; + relaunch_argv.push_back(helper.value()); + relaunch_argv.push_back(internal::kRelauncherTypeArg); - relaunch_args.insert(relaunch_args.end(), + relaunch_argv.insert(relaunch_argv.end(), relauncher_args.begin(), relauncher_args.end()); - relaunch_args.push_back(internal::kRelauncherArgSeparator); + relaunch_argv.push_back(internal::kRelauncherArgSeparator); - relaunch_args.push_back(app.value()); - relaunch_args.insert(relaunch_args.end(), args.begin(), args.end()); + relaunch_argv.insert(relaunch_argv.end(), argv.begin(), argv.end()); #if defined(OS_POSIX) int pipe_fds[2]; @@ -99,10 +97,10 @@ bool RelaunchAppWithHelper(const base::FilePath& app, base::LaunchOptions options; #if defined(OS_POSIX) options.fds_to_remap = &fd_map; - base::Process process = base::LaunchProcess(relaunch_args, options); + base::Process process = base::LaunchProcess(relaunch_argv, options); #elif defined(OS_WIN) base::Process process = base::LaunchProcess( - base::JoinString(relaunch_args, L" "), options); + base::JoinString(relaunch_argv, L" "), options); #endif if (!process.IsValid()) { LOG(ERROR) << "base::LaunchProcess failed"; @@ -158,15 +156,15 @@ int RelauncherMain(const content::MainFunctionParams& main_parameters) { // Figure out what to execute, what arguments to pass it, and whether to // start it in the background. - bool in_relaunch_args = false; + bool in_relauncher_args = false; StringType relaunch_executable; StringVector relauncher_args; StringVector launch_argv; for (size_t argv_index = 2; argv_index < argv.size(); ++argv_index) { const StringType& arg(argv[argv_index]); - if (!in_relaunch_args) { + if (!in_relauncher_args) { if (arg == internal::kRelauncherArgSeparator) { - in_relaunch_args = true; + in_relauncher_args = true; } else { relauncher_args.push_back(arg); } diff --git a/atom/browser/relauncher.h b/atom/browser/relauncher.h index f6722f946d2..c19557b330c 100644 --- a/atom/browser/relauncher.h +++ b/atom/browser/relauncher.h @@ -59,7 +59,7 @@ using StringVector = base::CommandLine::StringVector; // successfully. Returns true on success, although some failures can occur // after this function returns true if, for example, they occur within the // relauncher process. Returns false when the relaunch definitely failed. -bool RelaunchApp(const base::FilePath& app, const StringVector& args); +bool RelaunchApp(const StringVector& argv); // Identical to RelaunchApp, but uses |helper| as the path to the relauncher // process, and allows additional arguments to be supplied to the relauncher @@ -70,8 +70,7 @@ bool RelaunchApp(const base::FilePath& app, const StringVector& args); // able to communicate with one another. This variant can be useful to // relaunch the same version of Chrome from another location, using that // location's helper. -bool RelaunchAppWithHelper(const base::FilePath& app, - const base::FilePath& helper, +bool RelaunchAppWithHelper(const base::FilePath& helper, const StringVector& relauncher_args, const StringVector& args); diff --git a/atom/browser/relauncher_win.cc b/atom/browser/relauncher_win.cc index bb7617f29cb..a759e7c2fff 100644 --- a/atom/browser/relauncher_win.cc +++ b/atom/browser/relauncher_win.cc @@ -68,7 +68,7 @@ int LaunchProgram(const StringVector& relauncher_args, const StringVector& argv) { base::LaunchOptions options; base::Process process = - base::LaunchProcess(base::JoinString(args, L" "), options); + base::LaunchProcess(base::JoinString(argv, L" "), options); return process.IsValid() ? 0 : 1; }