diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-31 21:58:12 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-31 21:58:12 +0000 |
commit | d23c9b7b8ddf903fee60da371c902a3fec8f66e7 (patch) | |
tree | ebfe1a887d6e7195676f159ef4f2f0ce2077bc9d /chrome/installer/setup | |
parent | cec4a2709d524929d1da9a0ad806644274e36b12 (diff) | |
download | chromium_src-d23c9b7b8ddf903fee60da371c902a3fec8f66e7.zip chromium_src-d23c9b7b8ddf903fee60da371c902a3fec8f66e7.tar.gz chromium_src-d23c9b7b8ddf903fee60da371c902a3fec8f66e7.tar.bz2 |
Refactoring of master preferences parsing before adding a new preference.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22198 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/setup')
-rw-r--r-- | chrome/installer/setup/install.cc | 50 | ||||
-rw-r--r-- | chrome/installer/setup/install.h | 7 | ||||
-rw-r--r-- | chrome/installer/setup/setup_main.cc | 144 |
3 files changed, 104 insertions, 97 deletions
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index 2a3bc3a..8d6a4db 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -20,6 +20,7 @@ #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/helper.h" #include "chrome/installer/util/install_util.h" +#include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/set_reg_value_work_item.h" #include "chrome/installer/util/shell_util.h" #include "chrome/installer/util/util_constants.h" @@ -160,11 +161,12 @@ void AddUninstallShortcutWorkItems(HKEY reg_root, // If the shortcuts do not exist, the function does not recreate them during // update. bool CreateOrUpdateChromeShortcuts(const std::wstring& exe_path, - int options, - installer_util::InstallStatus install_status, const std::wstring& install_path, - const std::wstring& new_version) { - bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; + const std::wstring& new_version, + installer_util::InstallStatus install_status, + bool system_install, + bool create_all_shortcut, + bool alt_shortcut) { FilePath shortcut_path; int dir_enum = (system_install) ? base::DIR_COMMON_START_MENU : base::DIR_START_MENU; @@ -242,20 +244,18 @@ bool CreateOrUpdateChromeShortcuts(const std::wstring& exe_path, // Update Desktop and Quick Launch shortcuts. If --create-new-shortcuts // is specified we want to create them, otherwise we update them only if // they exist. - bool create = (options & installer_util::CREATE_ALL_SHORTCUTS) != 0; - // In some cases the main desktop shortcut has an alternate name. - bool alt_shortcut = (options & installer_util::ALT_DESKTOP_SHORTCUT) != 0; - if (system_install) { ret = ret && ShellUtil::CreateChromeDesktopShortcut(chrome_exe, - product_desc, ShellUtil::SYSTEM_LEVEL, alt_shortcut, create); + product_desc, ShellUtil::SYSTEM_LEVEL, alt_shortcut, + create_all_shortcut); ret = ret && ShellUtil::CreateChromeQuickLaunchShortcut(chrome_exe, - ShellUtil::CURRENT_USER | ShellUtil::SYSTEM_LEVEL, create); + ShellUtil::CURRENT_USER | ShellUtil::SYSTEM_LEVEL, create_all_shortcut); } else { ret = ret && ShellUtil::CreateChromeDesktopShortcut(chrome_exe, - product_desc, ShellUtil::CURRENT_USER, alt_shortcut, create); + product_desc, ShellUtil::CURRENT_USER, alt_shortcut, + create_all_shortcut); ret = ret && ShellUtil::CreateChromeQuickLaunchShortcut(chrome_exe, - ShellUtil::CURRENT_USER, create); + ShellUtil::CURRENT_USER, create_all_shortcut); } return ret; @@ -279,8 +279,9 @@ bool Is64bit() { return false; } -void RegisterChromeOnMachine(const std::wstring& install_path, int options) { - bool system_level = (options & installer_util::SYSTEM_LEVEL) != 0; +void RegisterChromeOnMachine(const std::wstring& install_path, + bool system_level, + bool make_chrome_default) { // Try to add Chrome to Media Player shim inclusion list. We don't do any // error checking here because this operation will fail if user doesn't // have admin rights and we want to ignore the error. @@ -291,7 +292,7 @@ void RegisterChromeOnMachine(const std::wstring& install_path, int options) { std::wstring chrome_exe(install_path); file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe); LOG(INFO) << "Registering Chrome as browser"; - if (options & installer_util::MAKE_CHROME_DEFAULT) { + if (make_chrome_default) { int level = ShellUtil::CURRENT_USER; if (system_level) level = level | ShellUtil::SYSTEM_LEVEL; @@ -483,9 +484,10 @@ bool installer::InstallNewVersion(const std::wstring& exe_path, installer_util::InstallStatus installer::InstallOrUpdateChrome( const std::wstring& exe_path, const std::wstring& archive_path, - const std::wstring& install_temp_path, int options, + const std::wstring& install_temp_path, const DictionaryValue* prefs, const Version& new_version, const Version* installed_version) { - bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; + bool system_install = installer_util::GetBooleanPreference(prefs, + installer_util::master_preferences::kSystemLevel); std::wstring install_path(GetChromeInstallPath(system_install)); if (install_path.empty()) { LOG(ERROR) << "Could not get installation destination path."; @@ -526,13 +528,21 @@ installer_util::InstallStatus installer::InstallOrUpdateChrome( result = installer_util::NEW_VERSION_UPDATED; } - if (!CreateOrUpdateChromeShortcuts(exe_path, options, result, - install_path, new_version.GetString())) + bool create_all_shortcut = installer_util::GetBooleanPreference(prefs, + installer_util::master_preferences::kCreateAllShortcuts); + bool alt_shortcut = installer_util::GetBooleanPreference(prefs, + installer_util::master_preferences::kAltShortcutText); + if (!CreateOrUpdateChromeShortcuts(exe_path, install_path, + new_version.GetString(), result, + system_install, create_all_shortcut, + alt_shortcut)) LOG(WARNING) << "Failed to create/update start menu shortcut."; RemoveOldVersionDirs(install_path, new_version.GetString()); - RegisterChromeOnMachine(install_path, options); + bool make_chrome_default = installer_util::GetBooleanPreference(prefs, + installer_util::master_preferences::kMakeChromeDefault); + RegisterChromeOnMachine(install_path, system_install, make_chrome_default); } return result; diff --git a/chrome/installer/setup/install.h b/chrome/installer/setup/install.h index 6613e6fb..de468b3 100644 --- a/chrome/installer/setup/install.h +++ b/chrome/installer/setup/install.h @@ -7,8 +7,7 @@ #ifndef CHROME_INSTALLER_SETUP_INSTALL_H_ #define CHROME_INSTALLER_SETUP_INSTALL_H_ -#include <string> -#include <windows.h> +#include <base/values.h> #include "chrome/installer/util/util_constants.h" #include "chrome/installer/util/version.h" @@ -29,7 +28,7 @@ std::wstring GetInstallerPathUnderChrome(const std::wstring& install_path, // install_temp_path: working directory used during install/update. It should // also has a sub dir source that contains a complete // and unpacked Chrome package. -// options: install options. See chrome/installer/util/util_constants.h. +// prefs: master preferences. See chrome/installer/util/master_preferences.h. // new_version: new Chrome version that needs to be installed // installed_version: currently installed version of Chrome, if any, or // NULL otherwise @@ -38,7 +37,7 @@ std::wstring GetInstallerPathUnderChrome(const std::wstring& install_path, // is responsible for cleaning up install_temp_path. installer_util::InstallStatus InstallOrUpdateChrome( const std::wstring& exe_path, const std::wstring& archive_path, - const std::wstring& install_temp_path, int options, + const std::wstring& install_temp_path, const DictionaryValue* prefs, const Version& new_version, const Version* installed_version); // This function installs a new version of Chrome to the specified location. diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc index d73e4db..0f0d41a 100644 --- a/chrome/installer/setup/setup_main.cc +++ b/chrome/installer/setup/setup_main.cc @@ -206,74 +206,66 @@ installer_util::InstallStatus RenameChromeExecutables(bool system_install) { // Parse command line and read master profile, if present, to get distribution // related install options. -int GetInstallOptions(const CommandLine& cmd_line) { - int options = 0; - int preferences = 0; +DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line) { + DictionaryValue* preferences = NULL; if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) { - std::wstring prefs_path = cmd_line.GetSwitchValue( - installer_util::switches::kInstallerData); + FilePath prefs_path( + cmd_line.GetSwitchValue(installer_util::switches::kInstallerData)); preferences = installer_util::ParseDistributionPreferences(prefs_path); - if ((preferences & installer_util::MASTER_PROFILE_NOT_FOUND) == 0) { - options |= installer_util::MASTER_PROFILE_PRESENT; - if ((preferences & installer_util::MASTER_PROFILE_ERROR) == 0) - options |= installer_util::MASTER_PROFILE_VALID; - } - // While there is a --show-eula command line flag, we don't process - // it in this function because it requires special handling. - if (preferences & installer_util::MASTER_PROFILE_REQUIRE_EULA) - options |= installer_util::SHOW_EULA_DIALOG; + if (preferences) + preferences->SetBoolean( + installer_util::master_preferences::kMasterPreferencesValid, true); } - if (preferences & installer_util::MASTER_PROFILE_CREATE_ALL_SHORTCUTS || - cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts)) - options |= installer_util::CREATE_ALL_SHORTCUTS; + if (!preferences) + preferences = new DictionaryValue(); - if (preferences & installer_util::MASTER_PROFILE_DO_NOT_LAUNCH_CHROME || - cmd_line.HasSwitch(installer_util::switches::kDoNotLaunchChrome)) - options |= installer_util::DO_NOT_LAUNCH_CHROME; + if (cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts)) + preferences->SetBoolean( + installer_util::master_preferences::kCreateAllShortcuts, true); - if (preferences & installer_util::MASTER_PROFILE_MAKE_CHROME_DEFAULT || - cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault)) - options |= installer_util::MAKE_CHROME_DEFAULT; + if (cmd_line.HasSwitch(installer_util::switches::kDoNotLaunchChrome)) + preferences->SetBoolean( + installer_util::master_preferences::kDoNotLaunchChrome, true); - if (preferences & installer_util::MASTER_PROFILE_SYSTEM_LEVEL || - cmd_line.HasSwitch(installer_util::switches::kSystemLevel)) - options |= installer_util::SYSTEM_LEVEL; + if (cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault)) + preferences->SetBoolean( + installer_util::master_preferences::kMakeChromeDefault, true); - if (preferences & installer_util::MASTER_PROFILE_VERBOSE_LOGGING || - cmd_line.HasSwitch(installer_util::switches::kVerboseLogging)) - options |= installer_util::VERBOSE_LOGGING; + if (cmd_line.HasSwitch(installer_util::switches::kSystemLevel)) + preferences->SetBoolean( + installer_util::master_preferences::kSystemLevel, true); - if (preferences & installer_util::MASTER_PROFILE_ALT_SHORTCUT_TXT || - cmd_line.HasSwitch(installer_util::switches::kAltDesktopShortcut)) - options |= installer_util::ALT_DESKTOP_SHORTCUT; + if (cmd_line.HasSwitch(installer_util::switches::kVerboseLogging)) + preferences->SetBoolean( + installer_util::master_preferences::kVerboseLogging, true); - return options; + if (cmd_line.HasSwitch(installer_util::switches::kAltDesktopShortcut)) + preferences->SetBoolean( + installer_util::master_preferences::kAltShortcutText, true); + + return preferences; } -// Copy master preference file if provided to installer to the same path -// of chrome.exe so Chrome first run can find it. -// This function will be called only when Chrome is launched the first time. -void CopyPreferenceFileForFirstRun(int options, const CommandLine& cmd_line) { - if (options & installer_util::MASTER_PROFILE_VALID) { - std::wstring prefs_source_path = cmd_line.GetSwitchValue( - installer_util::switches::kInstallerData); - bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; - std::wstring prefs_dest_path( - installer::GetChromeInstallPath(system_install)); - file_util::AppendToPath(&prefs_dest_path, - installer_util::kDefaultMasterPrefs); - if (!file_util::CopyFile(prefs_source_path, prefs_dest_path)) - LOG(ERROR) << "failed copying master profile"; - } +// Copy master preferences file provided to installer, in the same folder +// as chrome.exe so Chrome first run can find it. This function will be called +// only on the first install of Chrome. +void CopyPreferenceFileForFirstRun(bool system_level, + const CommandLine& cmd_line) { + std::wstring prefs_source_path = cmd_line.GetSwitchValue( + installer_util::switches::kInstallerData); + std::wstring prefs_dest_path( + installer::GetChromeInstallPath(system_level)); + file_util::AppendToPath(&prefs_dest_path, + installer_util::kDefaultMasterPrefs); + if (!file_util::CopyFile(prefs_source_path, prefs_dest_path)) + LOG(ERROR) << "failed copying master profile"; } bool CheckPreInstallConditions(const installer::Version* installed_version, - int options, + bool system_install, installer_util::InstallStatus& status) { - bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; - // Check to avoid simultaneous per-user and per-machine installs. scoped_ptr<installer::Version> chrome_version(InstallUtil::GetChromeVersion(!system_install)); @@ -308,12 +300,14 @@ bool CheckPreInstallConditions(const installer::Version* installed_version, } installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, - const installer::Version* installed_version, int options) { + const installer::Version* installed_version, const DictionaryValue* prefs) { + bool system_level = installer_util::GetBooleanPreference(prefs, + installer_util::master_preferences::kSystemLevel); installer_util::InstallStatus install_status = installer_util::UNKNOWN_STATUS; - if (!CheckPreInstallConditions(installed_version, options, install_status)) + if (!CheckPreInstallConditions(installed_version, + system_level, install_status)) return install_status; - bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; // For install the default location for chrome.packed.7z is in current // folder, so get that value first. std::wstring archive = file_util::GetDirectoryFromPath(cmd_line.program()); @@ -332,7 +326,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, if (!file_util::CreateNewTempDirectory(std::wstring(L"chrome_"), &temp_path)) { LOG(ERROR) << "Could not create temporary path."; - InstallUtil::WriteInstallerResult(system_install, + InstallUtil::WriteInstallerResult(system_level, installer_util::TEMP_DIR_FAILED, IDS_INSTALL_TEMP_DIR_FAILED_BASE, NULL); @@ -345,10 +339,10 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, file_util::AppendToPath(&unpack_path, std::wstring(installer::kInstallSourceDir)); bool incremental_install = false; - if (UnPackArchive(archive, system_install, installed_version, + if (UnPackArchive(archive, system_level, installed_version, temp_path, unpack_path, incremental_install)) { install_status = installer_util::UNCOMPRESSION_FAILED; - InstallUtil::WriteInstallerResult(system_install, install_status, + InstallUtil::WriteInstallerResult(system_level, install_status, IDS_INSTALL_UNCOMPRESSION_FAILED_BASE, NULL); } else { @@ -361,7 +355,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, if (!installer_version.get()) { LOG(ERROR) << "Did not find any valid version in installer."; install_status = installer_util::INVALID_ARCHIVE; - InstallUtil::WriteInstallerResult(system_install, install_status, + InstallUtil::WriteInstallerResult(system_level, install_status, IDS_INSTALL_INVALID_ARCHIVE_BASE, NULL); } else { LOG(INFO) << "version to install: " << installer_version->GetString(); @@ -369,7 +363,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, installed_version->IsHigherThan(installer_version.get())) { LOG(ERROR) << "Higher version is already installed."; install_status = installer_util::HIGHER_VERSION_EXISTS; - InstallUtil::WriteInstallerResult(system_install, install_status, + InstallUtil::WriteInstallerResult(system_level, install_status, IDS_INSTALL_HIGHER_VERSION_BASE, NULL); } else { @@ -379,13 +373,13 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, file_util::AppendToPath(&archive_to_copy, std::wstring(installer::kChromeArchive)); install_status = installer::InstallOrUpdateChrome( - cmd_line.program(), archive_to_copy, temp_path, options, + cmd_line.program(), archive_to_copy, temp_path, prefs, *installer_version, installed_version); int install_msg_base = IDS_INSTALL_FAILED_BASE; std::wstring chrome_exe; if (install_status != installer_util::INSTALL_FAILED) { - chrome_exe = installer::GetChromeInstallPath(system_install); + chrome_exe = installer::GetChromeInstallPath(system_level); if (chrome_exe.empty()) { // If we failed to construct install path, it means the OS call to // get %ProgramFiles% or %AppData% failed. Report this as failure. @@ -397,15 +391,17 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, install_msg_base = 0; } } - InstallUtil::WriteInstallerResult(system_install, install_status, + InstallUtil::WriteInstallerResult(system_level, install_status, install_msg_base, &chrome_exe); if (install_status == installer_util::FIRST_INSTALL_SUCCESS) { LOG(INFO) << "First install successful."; - CopyPreferenceFileForFirstRun(options, cmd_line); + if (installer_util::GetBooleanPreference(prefs, + installer_util::master_preferences::kMasterPreferencesValid)) + CopyPreferenceFileForFirstRun(system_level, cmd_line); // We never want to launch Chrome in system level install mode. - if (!(options & installer_util::DO_NOT_LAUNCH_CHROME) && - !(options & installer_util::SYSTEM_LEVEL)) - installer::LaunchChrome(system_install); + if (!system_level && !installer_util::GetBooleanPreference(prefs, + installer_util::master_preferences::kDoNotLaunchChrome)) + installer::LaunchChrome(system_level); } } } @@ -414,7 +410,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, // the case we would not do that directly at this point but in another // instance of setup.exe dist->LaunchUserExperiment(install_status, *installer_version, - system_install, options); + system_level); } // Delete temporary files. These include install temporary directory @@ -422,14 +418,14 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, scoped_ptr<WorkItemList> cleanup_list(WorkItem::CreateWorkItemList()); LOG(INFO) << "Deleting temporary directory " << temp_path; cleanup_list->AddDeleteTreeWorkItem(temp_path, std::wstring()); - if (options & installer_util::MASTER_PROFILE_PRESENT) { + if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) { std::wstring prefs_path = cmd_line.GetSwitchValue( installer_util::switches::kInstallerData); cleanup_list->AddDeleteTreeWorkItem(prefs_path, std::wstring()); } cleanup_list->Do(); - dist->UpdateDiffInstallStatus(system_install, incremental_install, + dist->UpdateDiffInstallStatus(system_level, incremental_install, install_status); return install_status; } @@ -620,11 +616,13 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, CommandLine::Init(0, NULL); const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); installer::InitInstallerLogging(parsed_command_line); - int options = GetInstallOptions(parsed_command_line); - if (options & installer_util::VERBOSE_LOGGING) + scoped_ptr<DictionaryValue> prefs(GetInstallPreferences(parsed_command_line)); + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kVerboseLogging)) logging::SetMinLogLevel(logging::LOG_INFO); - bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; + bool system_install = installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kSystemLevel); LOG(INFO) << "system install is " << system_install; // Check to make sure current system is WinXP or later. If not, log @@ -691,7 +689,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, } else { install_status = InstallChrome(parsed_command_line, installed_version.get(), - options); + prefs.get()); } CoUninitialize(); |