diff options
Diffstat (limited to 'chrome/installer/util')
-rw-r--r-- | chrome/installer/util/eula_util.cc | 110 | ||||
-rw-r--r-- | chrome/installer/util/eula_util.h | 25 | ||||
-rw-r--r-- | chrome/installer/util/installation_validator.cc | 35 | ||||
-rw-r--r-- | chrome/installer/util/installation_validator.h | 9 | ||||
-rw-r--r-- | chrome/installer/util/installation_validator_unittest.cc | 40 | ||||
-rw-r--r-- | chrome/installer/util/util_constants.cc | 5 | ||||
-rw-r--r-- | chrome/installer/util/util_constants.h | 2 |
7 files changed, 217 insertions, 9 deletions
diff --git a/chrome/installer/util/eula_util.cc b/chrome/installer/util/eula_util.cc new file mode 100644 index 0000000..98c23c7 --- /dev/null +++ b/chrome/installer/util/eula_util.cc @@ -0,0 +1,110 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/installer/util/eula_util.h" + +#include "base/file_util.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/installer/util/browser_distribution.h" +#include "chrome/installer/util/install_util.h" +#include "chrome/installer/util/installation_state.h" +#include "chrome/installer/util/master_preferences.h" +#include "chrome/installer/util/master_preferences_constants.h" +#include "chrome/installer/util/util_constants.h" + +namespace installer { + +namespace { + +bool IsChromeFirstRunPending(BrowserDistribution* dist) { + // Chrome creates the first run sentinel after the user has gone through the + // first-run flow. Assume Chrome has been run if the path to the sentinel + // cannot be determined. + FilePath first_run_sentinel; + return InstallUtil::GetSentinelFilePath(chrome::kFirstRunSentinel, + dist, + &first_run_sentinel) + && !file_util::PathExists(first_run_sentinel); +} + +bool IsEULAAcceptanceFlagged(BrowserDistribution* dist) { + // Chrome creates the EULA sentinel after the EULA has been accepted when + // doing so is required by master_preferences. Assume the EULA has not been + // accepted if the path to the sentinel cannot be determined. + FilePath eula_sentinel; + return InstallUtil::GetSentinelFilePath(kEULASentinelFile, + dist, + &eula_sentinel) + && file_util::PathExists(eula_sentinel); +} + +scoped_ptr<MasterPreferences> GetMasterPrefs(const ProductState& prod_state) { + // The standard location of the master prefs is next to the chrome binary. + FilePath master_prefs_path( + prod_state.GetSetupPath().DirName().DirName().DirName()); + scoped_ptr<MasterPreferences> install_prefs(new MasterPreferences( + master_prefs_path.AppendASCII(kDefaultMasterPrefs))); + if (install_prefs && install_prefs->read_from_file()) + return install_prefs.Pass(); + + return scoped_ptr<MasterPreferences>(); +} + +// Attempts to initialize |state| with any Chrome-related product. +// Returns true if any of these product are installed, otherwise false. +bool GetAnyChromeProductState(bool system_level, ProductState* state) { + return state->Initialize(system_level, BrowserDistribution::CHROME_BROWSER) + || state->Initialize(system_level, BrowserDistribution::CHROME_FRAME) + || state->Initialize(system_level, BrowserDistribution::CHROME_APP_HOST); +} + +} // namespace + +EULAAcceptanceResponse IsEULAAccepted(bool system_level) { + ProductState prod_state; + + if (!system_level) { // User-level case has seprate flow. + // Do not simply check Chrome binaries. Instead, check whether or not + // any Chrome-related products is installed, because the presence of any of + // these products at user-level implies that the EULA has been accepted. + return GetAnyChromeProductState(false, &prod_state) + ? QUERY_EULA_ACCEPTED : QUERY_EULA_NOT_ACCEPTED; + } + + // System-level. Try to use Chrome binaries product state. + if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BINARIES)) { + // Fall back to Chrome Browser product state only. + if (!prod_state.Initialize(true, BrowserDistribution::CHROME_BROWSER)) + return QUERY_EULA_FAIL; + + LOG_IF(DFATAL, prod_state.is_multi_install()) + << "Binaries are not installed, but Chrome is multi-install."; + } + BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( + BrowserDistribution::CHROME_BROWSER); + + // Is Google Update waiting for Chrome's EULA to be accepted? + DWORD eula_accepted = 0; + if (prod_state.GetEulaAccepted(&eula_accepted) && !eula_accepted) + return QUERY_EULA_NOT_ACCEPTED; + + if (!IsChromeFirstRunPending(dist) || IsEULAAcceptanceFlagged(dist)) + return QUERY_EULA_ACCEPTED; + + // EULA acceptance not flagged. Now see if it is required. + scoped_ptr<MasterPreferences> install_prefs(GetMasterPrefs(prod_state)); + // If we fail to get master preferences, assume that EULA is not required. + if (!install_prefs) + return QUERY_EULA_ACCEPTED; + + bool eula_required = false; + // If kRequireEula value is absent, assume EULA is not required. + if (!install_prefs->GetBool(master_preferences::kRequireEula, &eula_required)) + return QUERY_EULA_ACCEPTED; + + return eula_required ? QUERY_EULA_NOT_ACCEPTED : QUERY_EULA_ACCEPTED; +} + +} // namespace installer diff --git a/chrome/installer/util/eula_util.h b/chrome/installer/util/eula_util.h new file mode 100644 index 0000000..7888c09 --- /dev/null +++ b/chrome/installer/util/eula_util.h @@ -0,0 +1,25 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// This file contains helper functions to read the Chrome EULA. + +#ifndef CHROME_INSTALLER_UTIL_EULA_UTIL_H_ +#define CHROME_INSTALLER_UTIL_EULA_UTIL_H_ + +namespace installer { + +enum EULAAcceptanceResponse{ + QUERY_EULA_FAIL = -1, + QUERY_EULA_NOT_ACCEPTED = 0, + QUERY_EULA_ACCEPTED = 1, +}; + +// Performs a comprehensive test on EULA acceptance in Chrome. +// This is mostly intended for system-level Chrome, although it also supports +// user-level Chrome (should return QUERY_EULA_ACCEPTED). +EULAAcceptanceResponse IsEULAAccepted(bool system_level); + +} // namespace installer + +#endif // CHROME_INSTALLER_UTIL_EULA_UTIL_H_ diff --git a/chrome/installer/util/installation_validator.cc b/chrome/installer/util/installation_validator.cc index 435c777..3790061 100644 --- a/chrome/installer/util/installation_validator.cc +++ b/chrome/installer/util/installation_validator.cc @@ -270,6 +270,39 @@ void InstallationValidator::ValidateOnOsUpgradeCommand( } } +// Validates the "query-eula-acceptance" Google Update product command. +void InstallationValidator::ValidateQueryEULAAcceptanceCommand( + const ProductContext& ctx, + const AppCommand& command, + bool* is_valid) { + DCHECK(is_valid); + + CommandLine the_command(CommandLine::FromString(command.command_line())); + + ValidateSetupPath(ctx, the_command.GetProgram(), "query EULA acceptance", + is_valid); + + SwitchExpectations expected; + expected.push_back(std::make_pair(std::string(switches::kQueryEULAAcceptance), + true)); + expected.push_back(std::make_pair(std::string(switches::kSystemLevel), + ctx.system_install)); + + ValidateCommandExpectations(ctx, the_command, expected, + "query EULA acceptance", is_valid); + + if (command.sends_pings()) { + *is_valid = false; + LOG(ERROR) << "Query-EULA-acceptance command " + "should not be able to send pings."; + } + + if (!command.is_web_accessible()) { + *is_valid = false; + LOG(ERROR) << "Query-EULA-acceptance command is not web accessible."; + } +} + // Validates the "quick-enable-cf" Google Update product command. void InstallationValidator::ValidateQuickEnableCfCommand( const ProductContext& ctx, @@ -410,6 +443,8 @@ void InstallationValidator::ValidateBinariesCommands( expectations[kCmdQuickEnableApplicationHost] = &ValidateQuickEnableApplicationHostCommand; + + expectations[kCmdQueryEULAAcceptance] = &ValidateQueryEULAAcceptanceCommand; } ValidateAppCommandExpectations(ctx, expectations, is_valid); diff --git a/chrome/installer/util/installation_validator.h b/chrome/installer/util/installation_validator.h index 5ab6031..6315a74 100644 --- a/chrome/installer/util/installation_validator.h +++ b/chrome/installer/util/installation_validator.h @@ -186,12 +186,15 @@ class InstallationValidator { const ProductRules& rules; }; - static void ValidateOnOsUpgradeCommand(const ProductContext& ctx, - const AppCommand& command, - bool* is_valid); static void ValidateInstallAppCommand(const ProductContext& ctx, const AppCommand& command, bool* is_valid); + static void ValidateOnOsUpgradeCommand(const ProductContext& ctx, + const AppCommand& command, + bool* is_valid); + static void ValidateQueryEULAAcceptanceCommand(const ProductContext& ctx, + const AppCommand& command, + bool* is_valid); static void ValidateQuickEnableCfCommand(const ProductContext& ctx, const AppCommand& command, bool* is_valid); diff --git a/chrome/installer/util/installation_validator_unittest.cc b/chrome/installer/util/installation_validator_unittest.cc index 5b2b4eb..9f988da 100644 --- a/chrome/installer/util/installation_validator_unittest.cc +++ b/chrome/installer/util/installation_validator_unittest.cc @@ -90,6 +90,10 @@ class FakeProductState : public ProductState { Level install_level, const char* version, int channel_modifiers); + void AddQueryEULAAcceptanceCommand(BrowserDistribution::Type dist_type, + Level install_level, + const char* version, + int channel_modifiers); void set_multi_install(bool is_multi_install) { multi_install_ = is_multi_install; } @@ -266,6 +270,25 @@ void FakeProductState::AddOsUpgradeCommand(BrowserDistribution::Type dist_type, commands_.Set(installer::kCmdOnOsUpgrade, app_cmd); } +// Adds the "query-eula-acceptance" Google Update product command. +void FakeProductState::AddQueryEULAAcceptanceCommand( + BrowserDistribution::Type dist_type, + Level install_level, + const char* version, + int channel_modifiers) { + DCHECK_EQ(dist_type, BrowserDistribution::CHROME_BINARIES); + + CommandLine cmd_line(GetSetupExePath(dist_type, install_level, version, + channel_modifiers)); + cmd_line.AppendSwitch(installer::switches::kQueryEULAAcceptance); + if (install_level == SYSTEM_LEVEL) + cmd_line.AppendSwitch(installer::switches::kSystemLevel); + cmd_line.AppendSwitch(installer::switches::kVerboseLogging); + AppCommand app_cmd(cmd_line.GetCommandLineString()); + app_cmd.set_is_web_accessible(true); + commands_.Set(installer::kCmdQueryEULAAcceptance, app_cmd); +} + } // namespace // Fixture for testing the InstallationValidator. Errors logged by the @@ -450,12 +473,17 @@ void InstallationValidatorTest::MakeProductState( state->SetUninstallCommand(prod_type, install_level, chrome::kChromeVersion, channel_modifiers, vehicle); state->set_multi_install(is_multi_install); - if (prod_type == BrowserDistribution::CHROME_BINARIES && - (inst_type == InstallationValidator::CHROME_MULTI || - inst_type == - InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI)) { - state->AddQuickEnableCfCommand(prod_type, install_level, - chrome::kChromeVersion, channel_modifiers); + if (prod_type == BrowserDistribution::CHROME_BINARIES) { + if (inst_type == InstallationValidator::CHROME_MULTI || + inst_type == + InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI) { + state->AddQuickEnableCfCommand(prod_type, install_level, + chrome::kChromeVersion, channel_modifiers); + } + state->AddQueryEULAAcceptanceCommand(prod_type, + install_level, + chrome::kChromeVersion, + channel_modifiers); } if (prod_type == BrowserDistribution::CHROME_BINARIES) { state->AddQuickEnableApplicationHostCommand(prod_type, diff --git a/chrome/installer/util/util_constants.cc b/chrome/installer/util/util_constants.cc index ef2b076..b41fada 100644 --- a/chrome/installer/util/util_constants.cc +++ b/chrome/installer/util/util_constants.cc @@ -122,6 +122,10 @@ const char kNewSetupExe[] = "new-setup-exe"; // Notify the installer that the OS has been upgraded. const char kOnOsUpgrade[] = "on-os-upgrade"; +// Determines whether or not EULA has been accepted at some point. Returns via +// exit code: 0 if EULA not accepted, 1 if EULA accepted, and E_FAIL on error. +const char kQueryEULAAcceptance[] = "query-eula-acceptance"; + // Register Chrome as a valid browser on the current sytem. This option // requires that setup.exe is running as admin. If this option is specified, // options kInstallArchive and kUninstall are ignored. @@ -215,6 +219,7 @@ const wchar_t kChromeNewExe[] = L"new_chrome.exe"; const wchar_t kChromeOldExe[] = L"old_chrome.exe"; const wchar_t kCmdInstallApp[] = L"install-application"; const wchar_t kCmdOnOsUpgrade[] = L"on-os-upgrade"; +const wchar_t kCmdQueryEULAAcceptance[] = L"query-eula-acceptance"; const wchar_t kCmdQuickEnableApplicationHost[] = L"quick-enable-application-host"; const wchar_t kCmdQuickEnableCf[] = L"quick-enable-cf"; diff --git a/chrome/installer/util/util_constants.h b/chrome/installer/util/util_constants.h index da07084..3892cc2a 100644 --- a/chrome/installer/util/util_constants.h +++ b/chrome/installer/util/util_constants.h @@ -158,6 +158,7 @@ extern const char kMsi[]; extern const char kMultiInstall[]; extern const char kNewSetupExe[]; extern const char kOnOsUpgrade[]; +extern const char kQueryEULAAcceptance[]; extern const char kRegisterChromeBrowser[]; extern const char kRegisterChromeBrowserSuffix[]; extern const char kRegisterDevChrome[]; @@ -191,6 +192,7 @@ extern const wchar_t kChromeOldExe[]; extern const wchar_t kChromeNewExe[]; extern const wchar_t kCmdInstallApp[]; extern const wchar_t kCmdOnOsUpgrade[]; +extern const wchar_t kCmdQueryEULAAcceptance[]; extern const wchar_t kCmdQuickEnableApplicationHost[]; extern const wchar_t kCmdQuickEnableCf[]; extern const wchar_t kDelegateExecuteExe[]; |