forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunch_chrome.cc
61 lines (48 loc) · 1.72 KB
/
launch_chrome.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/installer/setup/launch_chrome.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/util/util_constants.h"
namespace installer {
base::CommandLine GetPostInstallLaunchCommand(
const base::FilePath& application_path) {
base::CommandLine cmd(application_path.Append(kChromeExe));
cmd.AppendSwitch(::switches::kFromInstaller);
return cmd;
}
bool LaunchChromeBrowser(const base::FilePath& application_path) {
if (application_path.empty())
return false;
return base::LaunchProcess(GetPostInstallLaunchCommand(application_path),
base::LaunchOptions())
.IsValid();
}
bool LaunchChromeAndWait(const base::FilePath& application_path,
const base::CommandLine& options,
int32_t* exit_code) {
if (application_path.empty())
return false;
base::CommandLine cmd(application_path.Append(kChromeExe));
cmd.AppendArguments(options, false);
base::Process chrome_handle = base::LaunchProcess(cmd, base::LaunchOptions());
if (!chrome_handle.IsValid()) {
PLOG(ERROR) << "Failed to launch: " << cmd.GetCommandLineString();
return false;
}
int ret = STILL_ACTIVE;
if (!chrome_handle.WaitForExit(&ret)) {
PLOG(ERROR) << "Wait for process exit failed";
return false;
}
DCHECK_NE(ret, static_cast<int>(STILL_ACTIVE));
if (exit_code)
*exit_code = ret;
return true;
}
} // namespace installer