Uniform when to use args or argv

This commit is contained in:
Cheng Zhao 2016-06-02 20:41:59 +09:00
parent 0d066de53e
commit 9a08cbce27
4 changed files with 24 additions and 23 deletions

View file

@ -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() {

View file

@ -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);
}

View file

@ -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);

View file

@ -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;
}