This source file includes following definitions.
- LaunchSetupForEula
- GetEULASentinelFilePath
- IsEULANotAccepted
- WriteEULAtoTempFile
- CreateEULASentinel
- DoPostImportPlatformSpecificTasks
- IsFirstRunSentinelPresent
- ShowPostInstallEULAIfNeeded
- MasterPrefsPath
#include "chrome/browser/first_run/first_run_internal.h"
#include <windows.h>
#include <shellapi.h>
#include "base/base_paths.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/time/time.h"
#include "base/win/metro.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/master_preferences_constants.h"
#include "chrome/installer/util/util_constants.h"
#include "content/public/browser/browser_thread.h"
#include "grit/locale_settings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/win/shell.h"
namespace {
bool LaunchSetupForEula(const base::FilePath::StringType& value,
int* ret_code) {
base::FilePath exe_dir;
if (!PathService::Get(base::DIR_MODULE, &exe_dir))
return false;
exe_dir = exe_dir.Append(installer::kInstallerDir);
base::FilePath exe_path = exe_dir.Append(installer::kSetupExe);
base::ProcessHandle ph;
CommandLine cl(CommandLine::NO_PROGRAM);
cl.AppendSwitchNative(installer::switches::kShowEula, value);
if (base::win::IsMetroProcess()) {
cl.AppendSwitch(installer::switches::kShowEulaForMetro);
ui::win::OpenAnyViaShell(exe_path.value(),
exe_dir.value(),
cl.GetCommandLineString(),
SEE_MASK_FLAG_LOG_USAGE | SEE_MASK_FLAG_NO_UI);
return false;
} else {
CommandLine setup_path(exe_path);
setup_path.AppendArguments(cl, false);
int exit_code = 0;
if (!base::LaunchProcess(setup_path, base::LaunchOptions(), &ph) ||
!base::WaitForExitCode(ph, &exit_code)) {
return false;
}
*ret_code = exit_code;
return true;
}
}
bool GetEULASentinelFilePath(base::FilePath* path) {
return InstallUtil::GetSentinelFilePath(
installer::kEULASentinelFile, BrowserDistribution::GetDistribution(),
path);
}
bool IsEULANotAccepted(installer::MasterPreferences* install_prefs) {
bool value = false;
if (install_prefs->GetBool(installer::master_preferences::kRequireEula,
&value) && value) {
base::FilePath eula_sentinel;
if (!GetEULASentinelFilePath(&eula_sentinel) ||
!base::PathExists(eula_sentinel)) {
return true;
}
}
return false;
}
bool WriteEULAtoTempFile(base::FilePath* eula_path) {
std::string terms = l10n_util::GetStringUTF8(IDS_TERMS_HTML);
return (!terms.empty() &&
base::CreateTemporaryFile(eula_path) &&
base::WriteFile(*eula_path, terms.data(), terms.size()) != -1);
}
bool CreateEULASentinel() {
base::FilePath eula_sentinel;
if (!GetEULASentinelFilePath(&eula_sentinel))
return false;
return (base::CreateDirectory(eula_sentinel.DirName()) &&
base::WriteFile(eula_sentinel, "", 0) != -1);
}
}
namespace first_run {
namespace internal {
void DoPostImportPlatformSpecificTasks(Profile* ) {
static const int64 kTiggerActiveSetupDelaySeconds = 5;
base::FilePath chrome_exe;
if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
NOTREACHED();
} else if (!InstallUtil::IsPerUserInstall(chrome_exe.value().c_str())) {
content::BrowserThread::GetBlockingPool()->PostDelayedTask(
FROM_HERE,
base::Bind(&InstallUtil::TriggerActiveSetupCommand),
base::TimeDelta::FromSeconds(kTiggerActiveSetupDelaySeconds));
}
}
bool IsFirstRunSentinelPresent() {
base::FilePath sentinel;
if (!GetFirstRunSentinelFilePath(&sentinel) || base::PathExists(sentinel))
return true;
base::FilePath exe_path;
if (PathService::Get(base::DIR_EXE, &exe_path) &&
InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
base::FilePath legacy_sentinel = exe_path.Append(chrome::kFirstRunSentinel);
if (base::PathExists(legacy_sentinel)) {
bool migrated = base::CopyFile(legacy_sentinel, sentinel);
DPCHECK(migrated);
return true;
}
}
return false;
}
bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) {
if (IsEULANotAccepted(install_prefs)) {
base::FilePath inner_html;
if (WriteEULAtoTempFile(&inner_html)) {
int retcode = 0;
if (!LaunchSetupForEula(inner_html.value(), &retcode) ||
(retcode != installer::EULA_ACCEPTED &&
retcode != installer::EULA_ACCEPTED_OPT_IN)) {
LOG(WARNING) << "EULA flow requires fast exit.";
return false;
}
CreateEULASentinel();
if (retcode == installer::EULA_ACCEPTED) {
VLOG(1) << "EULA : no collection";
GoogleUpdateSettings::SetCollectStatsConsent(false);
} else if (retcode == installer::EULA_ACCEPTED_OPT_IN) {
VLOG(1) << "EULA : collection consent";
GoogleUpdateSettings::SetCollectStatsConsent(true);
}
}
}
return true;
}
base::FilePath MasterPrefsPath() {
base::FilePath master_prefs;
if (!PathService::Get(base::DIR_EXE, &master_prefs))
return base::FilePath();
return master_prefs.AppendASCII(installer::kDefaultMasterPrefs);
}
}
}