0

Refactor chrome_launcher_support::GetAnyChromePath.

Combined GetAnyChromePath and GetChromeSxSPath into one function that
takes a bool |is_sxs|. Avoids the need to have a wrapper function that
conditionally calls GetAnyChromePath or GetAnyChromeSxsPath.

BUG=428600

Review URL: https://codereview.chromium.org/685103004

Cr-Commit-Position: refs/heads/master@{#311384}
This commit is contained in:
mgiuca
2015-01-13 17:19:36 -08:00
committed by Commit bot
parent 4b73fadb14
commit e1b07409f1
10 changed files with 45 additions and 65 deletions

@ -20,6 +20,7 @@
#include "chrome/app_installer/win/app_installer_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/installer/launcher_support/chrome_launcher_support.h"
#include "chrome/installer/util/util_constants.h"
#include "content/public/common/user_agent.h"
@ -121,14 +122,15 @@ int WINAPI wWinMain(HINSTANCE instance,
return COULD_NOT_PARSE_INLINE_INSTALL_DATA;
}
base::FilePath chrome_path = GetChromeExePath(is_canary);
base::FilePath chrome_path =
chrome_launcher_support::GetAnyChromePath(is_canary);
// If none found, show EULA, download, and install Chrome.
if (chrome_path.empty()) {
ExitCode get_chrome_result = GetChrome(is_canary, inline_install_json);
if (get_chrome_result != SUCCESS)
return get_chrome_result;
chrome_path = GetChromeExePath(is_canary);
chrome_path = chrome_launcher_support::GetAnyChromePath(is_canary);
if (chrome_path.empty())
return COULD_NOT_FIND_CHROME;
}

@ -298,11 +298,6 @@ bool FetchUrl(const base::string16& user_agent,
return ReadHttpData(request_handle.Get(), response_data);
}
base::FilePath GetChromeExePath(bool is_canary) {
return is_canary ? chrome_launcher_support::GetAnyChromeSxSPath()
: chrome_launcher_support::GetAnyChromePath();
}
ExitCode GetChrome(bool is_canary, const std::string& inline_install_json) {
// Show UI to install Chrome. The UI returns a download URL.
base::string16 download_url =

@ -50,8 +50,6 @@ bool FetchUrl(const base::string16& user_agent,
const base::string16& object_name,
std::vector<uint8_t>* response_data);
base::FilePath GetChromeExePath(bool is_canary);
// Shows UI to download and install Chrome. Returns a failure code, or SUCCESS
// if the installation completed successfully.
ExitCode GetChrome(bool is_canary, const std::string& inline_install_json);

@ -22,11 +22,6 @@ const int kLaunchFailure = 2;
// Command-line switches.
const char kChromeSxS[] = "chrome-sxs";
base::FilePath GetChromeExePath(bool is_canary) {
return is_canary ? chrome_launcher_support::GetAnyChromeSxSPath()
: chrome_launcher_support::GetAnyChromePath();
}
} // namespace
// This program runs chrome.exe, passing its arguments on to the Chrome binary.
@ -55,10 +50,10 @@ int WINAPI wWinMain(HINSTANCE instance,
logging::InitLogging(logging_settings);
// Get the command-line for the Chrome binary.
// --chrome-sxs on the command line means we should run the canary binary.
bool is_canary =
base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS);
base::FilePath chrome_path = GetChromeExePath(is_canary);
// --chrome-sxs on the command line means we should run the SxS binary.
bool is_sxs = base::CommandLine::ForCurrentProcess()->HasSwitch(kChromeSxS);
base::FilePath chrome_path =
chrome_launcher_support::GetAnyChromePath(is_sxs);
if (chrome_path.empty()) {
LOG(ERROR) << "Could not find chrome.exe path in the registry.";
return kNoProgram;

@ -391,11 +391,11 @@ bool GetGoogleChromePath(base::FilePath* chrome_exe_path) {
// Now grab the uninstall string from the appropriate ClientState key
// and use that as the base for a path to chrome.exe.
*chrome_exe_path =
chrome_launcher_support::GetChromePathForInstallationLevel(
install_key == HKEY_LOCAL_MACHINE ?
chrome_launcher_support::SYSTEM_LEVEL_INSTALLATION :
chrome_launcher_support::USER_LEVEL_INSTALLATION);
*chrome_exe_path = chrome_launcher_support::GetChromePathForInstallationLevel(
install_key == HKEY_LOCAL_MACHINE
? chrome_launcher_support::SYSTEM_LEVEL_INSTALLATION
: chrome_launcher_support::USER_LEVEL_INSTALLATION,
false /* is_sxs */);
return !chrome_exe_path->empty();
}

@ -113,39 +113,29 @@ base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path,
return base::FilePath();
}
// Returns the path to an installed SxS chrome.exe at the specified level, if
// it can be found via the registry.
base::FilePath GetChromeSxSPathForInstallationLevel(InstallationLevel level) {
#if defined(GOOGLE_CHROME_BUILD)
return FindExeRelativeToSetupExe(
GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe);
#else
// There is no SxS build for Chromium.
return base::FilePath();
#endif
}
} // namespace
base::FilePath GetChromePathForInstallationLevel(InstallationLevel level) {
return FindExeRelativeToSetupExe(
GetSetupExeForInstallationLevel(level), kChromeExe);
base::FilePath GetChromePathForInstallationLevel(InstallationLevel level,
bool is_sxs) {
if (is_sxs) {
#if defined(GOOGLE_CHROME_BUILD)
return FindExeRelativeToSetupExe(
GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe);
#else
// There is no SxS build for Chromium.
return base::FilePath();
#endif
} else {
return FindExeRelativeToSetupExe(GetSetupExeForInstallationLevel(level),
kChromeExe);
}
}
base::FilePath GetAnyChromePath() {
base::FilePath chrome_path;
if (chrome_path.empty())
chrome_path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
if (chrome_path.empty())
chrome_path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION);
return chrome_path;
}
base::FilePath GetAnyChromeSxSPath() {
base::FilePath path =
GetChromeSxSPathForInstallationLevel(USER_LEVEL_INSTALLATION);
base::FilePath GetAnyChromePath(bool is_sxs) {
base::FilePath path;
path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION, is_sxs);
if (path.empty())
path = GetChromeSxSPathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION);
path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION, is_sxs);
return path;
}

@ -19,19 +19,16 @@ enum InstallationLevel {
// Returns the path to an installed chrome.exe at the specified level, if it can
// be found in the registry. Prefers the installer from a multi-install, but may
// also return that of a single-install of Chrome if no multi-install exists.
base::FilePath GetChromePathForInstallationLevel(InstallationLevel level);
// If |is_sxs| is true, gets the path to the SxS (Canary) version of chrome.exe.
base::FilePath GetChromePathForInstallationLevel(InstallationLevel level,
bool is_sxs);
// Returns the path to an installed chrome.exe, or an empty path. Prefers a
// system-level installation to a user-level installation. Uses the registry to
// identify a Chrome installation location. The file path returned (if any) is
// identify a Chrome installation location. If |is_sxs| is true, gets the path
// to the SxS (Canary) version of chrome.exe. The file path returned (if any) is
// guaranteed to exist.
base::FilePath GetAnyChromePath();
// Returns the path to an installed SxS chrome.exe, or an empty path. Prefers a
// user-level installation to a system-level installation. Uses the registry to
// identify a Chrome Canary installation location. The file path returned (if
// any) is guaranteed to exist.
base::FilePath GetAnyChromeSxSPath();
base::FilePath GetAnyChromePath(bool is_sxs);
} // namespace chrome_launcher_support

@ -198,7 +198,8 @@ void ChromeLauncher::Run() {
for (base::TimeDelta time_out = default_time_out;;
time_out = std::min(time_out * 2, max_time_out)) {
base::FilePath chrome_path = chrome_launcher_support::GetAnyChromePath();
base::FilePath chrome_path =
chrome_launcher_support::GetAnyChromePath(false /* is_sxs */);
if (!chrome_path.empty()) {
base::CommandLine cmd(chrome_path);
@ -258,7 +259,8 @@ std::string ChromeLauncher::CreateServiceStateFile(
return std::string();
}
base::FilePath chrome_path = chrome_launcher_support::GetAnyChromePath();
base::FilePath chrome_path =
chrome_launcher_support::GetAnyChromePath(false /* is_sxs */);
if (chrome_path.empty()) {
LOG(ERROR) << "Can't find Chrome.";
return std::string();

@ -35,8 +35,9 @@ std::string GetEnvironment(const base::FilePath& user_data_dir) {
printing::XPSModule::Init());
environment.SetString(SetupListener::kUserNameJsonValueName,
GetCurrentUserName());
environment.SetString(SetupListener::kChromePathJsonValueName,
chrome_launcher_support::GetAnyChromePath().value());
environment.SetString(
SetupListener::kChromePathJsonValueName,
chrome_launcher_support::GetAnyChromePath(false /* is_sxs */).value());
if (base::CreateDirectory(user_data_dir)) {
base::FilePath temp_file;
if (base::CreateTemporaryFileInDir(user_data_dir, &temp_file)) {

@ -308,7 +308,7 @@ base::FilePath GetChromeExePath() {
base::FilePath path = ReadPathFromAnyRegistry(kChromeExePathRegValue);
if (!path.empty())
return path;
return chrome_launcher_support::GetAnyChromePath();
return chrome_launcher_support::GetAnyChromePath(false /* is_sxs */);
}
base::FilePath GetChromeProfilePath() {