Implement Relaunch on Windows

This commit is contained in:
Cheng Zhao 2016-06-02 19:49:36 +09:00
parent a3f39e9d0b
commit 0646f6ea9e
10 changed files with 179 additions and 40 deletions

View file

@ -32,12 +32,22 @@
#include <string>
#include <vector>
#include "base/command_line.h"
#if defined(OS_WIN)
#include "base/process/process_handle.h"
#endif
namespace content {
struct MainFunctionParams;
}
namespace relauncher {
using CharType = base::CommandLine::CharType;
using StringType = base::CommandLine::StringType;
using StringVector = base::CommandLine::StringVector;
// Relaunches the application using the helper application associated with the
// currently running instance of Chrome in the parent browser process as the
// executable for the relauncher process. |args| is an argv-style vector of
@ -49,7 +59,8 @@ namespace relauncher {
// 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 std::vector<std::string>& args);
bool RelaunchApp(const base::FilePath& app,
const StringVector& args);
// Identical to RelaunchApp, but uses |helper| as the path to the relauncher
// process, and allows additional arguments to be supplied to the relauncher
@ -60,22 +71,25 @@ bool RelaunchApp(const std::vector<std::string>& 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 std::string& helper,
const std::vector<std::string>& relauncher_args,
const std::vector<std::string>& args);
bool RelaunchAppWithHelper(const base::FilePath& app,
const base::FilePath& helper,
const StringVector& relauncher_args,
const StringVector& args);
// The entry point from ChromeMain into the relauncher process.
int RelauncherMain(const content::MainFunctionParams& main_parameters);
namespace internal {
#if defined(OS_POSIX)
// The "magic" file descriptor that the relauncher process' write side of the
// pipe shows up on. Chosen to avoid conflicting with stdin, stdout, and
// stderr.
extern const int kRelauncherSyncFD;
#endif
// The "type" argument identifying a relauncher process ("--type=relauncher").
extern const char* kRelauncherTypeArg;
extern const CharType* kRelauncherTypeArg;
// The argument separating arguments intended for the relauncher process from
// those intended for the relaunched process. "---" is chosen instead of "--"
@ -84,7 +98,11 @@ extern const char* kRelauncherTypeArg;
// arguments intended for the relaunched process, to get the correct settings
// for such things as logging and the user-data-dir in case it affects crash
// reporting.
extern const char* kRelauncherArgSeparator;
extern const CharType* kRelauncherArgSeparator;
#if defined(OS_WIN)
StringType GetWaitEventName(base::ProcessId pid);
#endif
// In the relauncher process, performs the necessary synchronization steps
// with the parent by setting up a kqueue to watch for it to exit, writing a
@ -94,9 +112,9 @@ extern const char* kRelauncherArgSeparator;
// process and the best recovery approach is to attempt relaunch anyway.
void RelauncherSynchronizeWithParent();
int LaunchProgram(const std::vector<std::string>& relauncher_args,
const std::string& program,
const std::vector<std::string>& argv);
int LaunchProgram(const StringVector& relauncher_args,
const StringType& program,
const StringVector& argv);
} // namespace internal