diff options
Diffstat (limited to 'chrome/installer/setup')
-rw-r--r-- | chrome/installer/setup/main.cc | 85 | ||||
-rwxr-xr-x | chrome/installer/setup/setup.cc | 22 | ||||
-rw-r--r-- | chrome/installer/setup/setup.h | 6 |
3 files changed, 86 insertions, 27 deletions
diff --git a/chrome/installer/setup/main.cc b/chrome/installer/setup/main.cc index fec04a7..a553031 100644 --- a/chrome/installer/setup/main.cc +++ b/chrome/installer/setup/main.cc @@ -25,6 +25,7 @@ #include "chrome/installer/util/logging_installer.h" #include "chrome/installer/util/lzma_util.h" #include "chrome/installer/util/google_update_constants.h" +#include "chrome/installer/util/master_preferences.h" #include "chrome/installer/util/shell_util.h" #include "chrome/installer/util/util_constants.h" #include "chrome/installer/util/work_item.h" @@ -160,6 +161,59 @@ installer::Version* GetVersionFromDir(const std::wstring& chrome_path) { return version; } +// 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; + + if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) { + std::wstring 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; + } + } + + if (preferences & installer_util::MASTER_PROFILE_CREATE_ALL_SHORTCUTS || + cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts)) + options |= installer_util::CREATE_ALL_SHORTCUTS; + + 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 (preferences & installer_util::MASTER_PROFILE_MAKE_CHROME_DEFAULT || + cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault)) + options |= installer_util::MAKE_CHROME_DEFAULT; + + if (preferences & installer_util::MASTER_PROFILE_SYSTEM_LEVEL || + cmd_line.HasSwitch(installer_util::switches::kSystemLevel)) + options |= installer_util::SYSTEM_LEVEL; + + return options; +} + +// 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"; + } +} + // This method is temporary and only called by UpdateChromeOpenCmd() below. void ReplaceRegistryValue(const std::wstring& reg_key, const std::wstring& old_val, @@ -192,7 +246,8 @@ void UpdateChromeOpenCmd(bool system_install) { } installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, - const installer::Version* installed_version, bool system_install) { + const installer::Version* installed_version, int options) { + 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()); @@ -249,7 +304,8 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, LOG(ERROR) << "Higher version is already installed."; install_status = installer_util::HIGHER_VERSION_EXISTS; InstallUtil::WriteInstallerResult(system_install, install_status, - IDS_INSTALL_HIGHER_VERSION_BASE, NULL); + IDS_INSTALL_HIGHER_VERSION_BASE, + NULL); } else { // We want to keep uncompressed archive (chrome.7z) that we get after // uncompressing and binary patching. Get the location for this file. @@ -257,12 +313,12 @@ 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, system_install, + cmd_line.program(), archive_to_copy, temp_path, options, *installer_version, installed_version); if (install_status == installer_util::FIRST_INSTALL_SUCCESS) { LOG(INFO) << "First install successful."; - if (cmd_line.HasSwitch( - installer_util::switches::kDoNotLaunchChrome)) { + CopyPreferenceFileForFirstRun(options, cmd_line); + if (options & installer_util::DO_NOT_LAUNCH_CHROME) { std::wstring chrome_exe = installer::GetChromeInstallPath(system_install); if (!chrome_exe.empty()) { @@ -298,11 +354,17 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, } } - // Delete install temporary directory. + // Delete temporary files. These include install temporary directory + // and master profile file if present. + scoped_ptr<WorkItemList> cleanup_list(WorkItem::CreateWorkItemList()); LOG(INFO) << "Deleting temporary directory " << temp_path; - scoped_ptr<DeleteTreeWorkItem> delete_tree( - WorkItem::CreateDeleteTreeWorkItem(temp_path, std::wstring())); - delete_tree->Do(); + cleanup_list->AddDeleteTreeWorkItem(temp_path, std::wstring()); + if (options & installer_util::MASTER_PROFILE_PRESENT) { + std::wstring prefs_path = cmd_line.GetSwitchValue( + installer_util::switches::kInstallerData); + cleanup_list->AddDeleteTreeWorkItem(prefs_path, std::wstring()); + } + cleanup_list->Do(); BrowserDistribution* dist = BrowserDistribution::GetDistribution(); dist->UpdateDiffInstallStatus(system_install, incremental_install, @@ -328,6 +390,7 @@ installer_util::InstallStatus UninstallChrome(const CommandLine& cmd_line, return installer_setup::UninstallChrome(cmd_line.program(), system_install, *version, remove_all, force); } + } // namespace @@ -337,8 +400,8 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, base::AtExitManager exit_manager; CommandLine parsed_command_line; installer::InitInstallerLogging(parsed_command_line); - bool system_install = - parsed_command_line.HasSwitch(installer_util::switches::kSystemLevel); + int options = GetInstallOptions(parsed_command_line); + bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; LOG(INFO) << "system install is " << system_install; // Check to make sure current system is WinXP or later. If not, log diff --git a/chrome/installer/setup/setup.cc b/chrome/installer/setup/setup.cc index d9a4298..b5d0ea8 100755 --- a/chrome/installer/setup/setup.cc +++ b/chrome/installer/setup/setup.cc @@ -40,7 +40,8 @@ void AddChromeToMediaPlayerList() { } -void DoFirstInstallTasks(std::wstring install_path, bool system_level) { +void DoFirstInstallTasks(std::wstring install_path, int options) { + bool system_level = (options & installer_util::SYSTEM_LEVEL) != 0; // 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. @@ -53,7 +54,7 @@ void DoFirstInstallTasks(std::wstring install_path, bool system_level) { CommandLine cmd_line; LOG(INFO) << "Registering Chrome as browser"; ShellUtil::RegisterStatus ret = ShellUtil::FAILURE; - if (cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault)) { + if (options & installer_util::MAKE_CHROME_DEFAULT) { ret = ShellUtil::AddChromeToSetAccessDefaults(chrome_exe, false); if (ret == ShellUtil::SUCCESS) { if (system_level) { @@ -84,10 +85,11 @@ void DoFirstInstallTasks(std::wstring install_path, bool system_level) { // If the shortcuts do not exist, the function does not recreate them during // update. bool CreateOrUpdateChromeShortcuts(const std::wstring& exe_path, - bool system_install, + 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; std::wstring shortcut_path; int dir_enum = (system_install) ? base::DIR_COMMON_START_MENU : base::DIR_START_MENU; @@ -161,10 +163,7 @@ 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 = false; // Only update; do not create, if they do not exist - CommandLine cmd_line; - if (cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts)) - create = true; + bool create = (options & installer_util::CREATE_ALL_SHORTCUTS) != 0; if (system_install) { ret = ret && ShellUtil::CreateChromeDesktopShortcut(chrome_exe, ShellUtil::SYSTEM_LEVEL, create); @@ -193,9 +192,9 @@ std::wstring installer::GetInstallerPathUnderChrome( installer_util::InstallStatus installer::InstallOrUpdateChrome( const std::wstring& exe_path, const std::wstring& archive_path, - const std::wstring& install_temp_path, bool system_install, + const std::wstring& install_temp_path, int options, const Version& new_version, const Version* installed_version) { - + bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; std::wstring install_path(GetChromeInstallPath(system_install)); if (install_path.empty()) { LOG(ERROR) << "Could not get installation destination path."; @@ -236,13 +235,13 @@ installer_util::InstallStatus installer::InstallOrUpdateChrome( NOTREACHED(); } - if (!CreateOrUpdateChromeShortcuts(exe_path, system_install, result, + if (!CreateOrUpdateChromeShortcuts(exe_path, options, result, install_path, new_version.GetString())) LOG(WARNING) << "Failed to create/update start menu shortcut."; if (result == installer_util::FIRST_INSTALL_SUCCESS || result == installer_util::INSTALL_REPAIRED) { - DoFirstInstallTasks(install_path, system_install); + DoFirstInstallTasks(install_path, options); } else { RemoveOldVersionDirs(install_path, new_version.GetString()); } @@ -250,4 +249,3 @@ installer_util::InstallStatus installer::InstallOrUpdateChrome( return result; } - diff --git a/chrome/installer/setup/setup.h b/chrome/installer/setup/setup.h index d1e0220..26feefe 100644 --- a/chrome/installer/setup/setup.h +++ b/chrome/installer/setup/setup.h @@ -29,8 +29,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. -// system_install: if true, the function performs a system wide install/update. -// Otherwise it installs/updates Chrome for the current user. +// options: install options. See chrome/installer/util/util_constants.h. // new_version: new Chrome version that needs to be installed // installed_version: currently installed version of Chrome, if any, or // NULL otherwise @@ -39,7 +38,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, bool system_install, + const std::wstring& install_temp_path, int options, const Version& new_version, const Version* installed_version); // This function installs a new version of Chrome to the specified location. @@ -77,4 +76,3 @@ bool InstallNewVersion(const std::wstring& exe_path, } #endif // CHROME_INSTALLER_SETUP_SETUP_H__ - |