diff options
-rw-r--r-- | chrome/browser/browser_main.cc | 12 | ||||
-rw-r--r-- | chrome/browser/first_run.h | 4 | ||||
-rw-r--r-- | chrome/browser/first_run_win.cc | 48 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 4 | ||||
-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 | ||||
-rw-r--r-- | chrome/installer/util/browser_distribution.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/browser_distribution.h | 2 | ||||
-rw-r--r-- | chrome/installer/util/google_chrome_distribution.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/google_chrome_distribution.h | 2 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 126 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.h | 103 | ||||
-rw-r--r-- | chrome/installer/util/util_constants.h | 25 |
14 files changed, 240 insertions, 291 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 302385d..e54471c 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -445,14 +445,16 @@ int BrowserMain(const MainFunctionParams& parameters) { BrowserInit browser_init; + int ping_delay = 0; if (is_first_run) { // On first run, we need to process the master preferences before the // browser's profile_manager object is created, but after ResourceBundle // is initialized. std::vector<std::wstring> first_run_tabs; - first_run_ui_bypass = - !FirstRun::ProcessMasterPreferences(user_data_dir, FilePath(), NULL, - &first_run_tabs); + first_run_ui_bypass = !FirstRun::ProcessMasterPreferences(user_data_dir, + FilePath(), + &first_run_tabs, + &ping_delay); // The master prefs might specify a set of urls to display. if (first_run_tabs.size()) AddFirstRunNewTabs(&browser_init, first_run_tabs); @@ -658,12 +660,10 @@ int BrowserMain(const MainFunctionParams& parameters) { win_util::ScopedCOMInitializer com_initializer; - int delay = 0; - installer_util::GetDistributionPingDelay(FilePath(), delay); // Init the RLZ library. This just binds the dll and schedules a task on the // file thread to be run sometime later. If this is the first run we record // the installation event. - RLZTracker::InitRlzDelayed(base::DIR_MODULE, is_first_run, delay); + RLZTracker::InitRlzDelayed(base::DIR_MODULE, is_first_run, ping_delay); #endif // Config the network module so it has access to resources. diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index 030c535..3bf1ce3 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -69,8 +69,8 @@ class FirstRun { // 'master_preferences' file. static bool ProcessMasterPreferences(const FilePath& user_data_dir, const FilePath& master_prefs_path, - int* preference_details, - std::vector<std::wstring>* new_tabs); + std::vector<std::wstring>* new_tabs, + int* ping_delay); // Sets the kShouldShowFirstRunBubble local state pref so that the browser // shows the bubble once the main message loop gets going. Returns false if diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc index a00f456..f14a3ea 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -167,12 +167,9 @@ bool FirstRun::CreateChromeQuickLaunchShortcut() { bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, const FilePath& master_prefs_path, - int* preference_details, - std::vector<std::wstring>* new_tabs) { + std::vector<std::wstring>* new_tabs, + int* ping_delay) { DCHECK(!user_data_dir.empty()); - if (preference_details) - *preference_details = 0; - FilePath master_prefs = master_prefs_path; if (master_prefs.empty()) { // The default location of the master prefs is next to the chrome exe. @@ -182,18 +179,18 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, master_prefs = master_prefs.Append(installer_util::kDefaultMasterPrefs); } - int parse_result = installer_util::ParseDistributionPreferences( - master_prefs.ToWStringHack()); - if (preference_details) - *preference_details = parse_result; - - if (parse_result & installer_util::MASTER_PROFILE_ERROR) + scoped_ptr<DictionaryValue> prefs( + installer_util::ParseDistributionPreferences(master_prefs)); + if (!prefs.get()) return true; if (new_tabs) - *new_tabs = installer_util::ParseFirstRunTabs(master_prefs.ToWStringHack()); + *new_tabs = installer_util::ParseFirstRunTabs(prefs.get()); + if (ping_delay) + installer_util::GetDistributionPingDelay(prefs.get(), ping_delay); - if (parse_result & installer_util::MASTER_PROFILE_REQUIRE_EULA) { + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kRequireEula)) { // Show the post-installation EULA. This is done by setup.exe and the // result determines if we continue or not. We wait here until the user // dismisses the dialog. @@ -219,7 +216,8 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, } } - if (parse_result & installer_util::MASTER_PROFILE_OEM_FIRST_RUN_BUBBLE) + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kAltFirstRunBubble)) FirstRun::SetOEMFirstRunBubblePref(); FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir); @@ -231,7 +229,8 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, if (!file_util::CopyFile(master_prefs, user_prefs)) return true; - if (!(parse_result & installer_util::MASTER_PROFILE_NO_FIRST_RUN_UI)) + if (!installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroSkipFirstRunPref)) return true; // From here on we won't show first run so we need to do the work to set the @@ -244,17 +243,22 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, if (!FirstRun::CreateSentinel()) return false; - if (parse_result & installer_util::MASTER_PROFILE_SHOW_WELCOME) + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroShowWelcomePage)) FirstRun::SetShowWelcomePagePref(); int import_items = 0; - if (parse_result & installer_util::MASTER_PROFILE_IMPORT_SEARCH_ENGINE) + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroImportSearchPref)) import_items += SEARCH_ENGINES; - if (parse_result & installer_util::MASTER_PROFILE_IMPORT_HISTORY) + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroImportHistoryPref)) import_items += HISTORY; - if (parse_result & installer_util::MASTER_PROFILE_IMPORT_BOOKMARKS) + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroImportBookmarksPref)) import_items += FAVORITES; - if (parse_result & installer_util::MASTER_PROFILE_IMPORT_HOME_PAGE) + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroImportHomePagePref)) import_items += HOME_PAGE; if (import_items) { @@ -268,8 +272,8 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, } } - if (parse_result & - installer_util::MASTER_PROFILE_MAKE_CHROME_DEFAULT_FOR_USER) + if (installer_util::GetBooleanPreference(prefs.get(), + installer_util::master_preferences::kMakeChromeDefaultForUser)) ShellIntegration::SetAsDefaultBrowser(); return false; diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 8d914ac..b1d6f40 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -145,8 +145,8 @@ void AutomationProvider::OnMessageFromExternalHost( // static bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, const FilePath& master_prefs_path, - int* preference_details, - std::vector<std::wstring>* new_tabs) { + std::vector<std::wstring>* new_tabs, + int* ping_delay) { // http://code.google.com/p/chromium/issues/detail?id=11971 // Pretend we processed them correctly. return true; 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(); diff --git a/chrome/installer/util/browser_distribution.cc b/chrome/installer/util/browser_distribution.cc index ad31cba..25555ac 100644 --- a/chrome/installer/util/browser_distribution.cc +++ b/chrome/installer/util/browser_distribution.cc @@ -88,7 +88,7 @@ void BrowserDistribution::UpdateDiffInstallStatus(bool system_install, void BrowserDistribution::LaunchUserExperiment( installer_util::InstallStatus status, const installer::Version& version, - bool system_install, int options) { + bool system_install) { } diff --git a/chrome/installer/util/browser_distribution.h b/chrome/installer/util/browser_distribution.h index 26f9b3b..452b8a2 100644 --- a/chrome/installer/util/browser_distribution.h +++ b/chrome/installer/util/browser_distribution.h @@ -58,7 +58,7 @@ class BrowserDistribution { // sets the wheels in motion or in simple cases does the experiment itself. virtual void LaunchUserExperiment(installer_util::InstallStatus status, const installer::Version& version, - bool system_install, int options); + bool system_install); // The user has qualified for the inactive user toast experiment and this // function just performs it. diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index 9f8995e..3c60e06 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -407,7 +407,7 @@ void GoogleChromeDistribution::UpdateDiffInstallStatus(bool system_install, // applies for users doing upgrades and non-systemwide install. void GoogleChromeDistribution::LaunchUserExperiment( installer_util::InstallStatus status, const installer::Version& version, - bool system_install, int options) { + bool system_install) { if ((installer_util::NEW_VERSION_UPDATED != status) || system_install) return; diff --git a/chrome/installer/util/google_chrome_distribution.h b/chrome/installer/util/google_chrome_distribution.h index f4b5016..aa2c99f 100644 --- a/chrome/installer/util/google_chrome_distribution.h +++ b/chrome/installer/util/google_chrome_distribution.h @@ -80,7 +80,7 @@ class GoogleChromeDistribution : public BrowserDistribution { virtual void LaunchUserExperiment(installer_util::InstallStatus status, const installer::Version& version, - bool system_install, int options); + bool system_install); // Assuming that the user qualifies, this function performs the inactive user // toast experiment. It will use chrome to show the UI and it will record the diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index 8a7c637..eb62aa5 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -10,37 +10,26 @@ #include "chrome/common/json_value_serializer.h" namespace { +DictionaryValue* GetPrefsFromFile(const FilePath& master_prefs_path) { + std::string json_data; + if (!file_util::ReadFileToString(master_prefs_path, &json_data)) + return NULL; -DictionaryValue* ReadJSONPrefs(const std::string& data) { - JSONStringValueSerializer json(data); + JSONStringValueSerializer json(json_data); scoped_ptr<Value> root(json.Deserialize(NULL)); + if (!root.get()) return NULL; + if (!root->IsType(Value::TYPE_DICTIONARY)) return NULL; return static_cast<DictionaryValue*>(root.release()); } - -DictionaryValue* GetPrefsFromFile(const std::wstring& master_prefs_path) { - std::string json_data; - if (!file_util::ReadFileToString(master_prefs_path, &json_data)) - return NULL; - return ReadJSONPrefs(json_data); -} - -bool GetBooleanPref(const DictionaryValue* prefs, const std::wstring& name) { - bool value = false; - prefs->GetBoolean(name, &value); - return value; -} - } // namespace namespace installer_util { -// All the preferences below are expected to be inside the JSON "distribution" -// block. See master_preferences.h for an example. - +namespace master_preferences { // Boolean pref that triggers skipping the first run dialogs. const wchar_t kDistroSkipFirstRunPref[] = L"skip_first_run_ui"; // Boolean pref that triggers loading the welcome page. @@ -77,88 +66,61 @@ const wchar_t kAltFirstRunBubble[] = L"oem_bubble"; // Boolean pref that triggers silent import of the default browser homepage. const wchar_t kDistroImportHomePagePref[] = L"import_home_page"; -bool GetDistributionPingDelay(const FilePath& master_prefs_path, - int& delay) { - // 90 seconds is the default that we want to use in case master preferences - // is missing or corrupt. - delay = 90; - FilePath master_prefs = master_prefs_path; - if (master_prefs.empty()) { - if (!PathService::Get(base::DIR_EXE, &master_prefs)) - return false; - master_prefs = master_prefs.Append(installer_util::kDefaultMasterPrefs); - } +const wchar_t kMasterPreferencesValid[] = L"master_preferencs_valid"; +} - if (!file_util::PathExists(master_prefs)) - return false; +bool GetBooleanPreference(const DictionaryValue* prefs,
+ const std::wstring& name) {
+ bool value = false;
+ if (!prefs || !prefs->GetBoolean(name, &value))
+ return false;
+ return value;
+} - scoped_ptr<DictionaryValue> json_root( - GetPrefsFromFile(master_prefs.ToWStringHack())); - if (!json_root.get()) +bool GetDistributionPingDelay(const DictionaryValue* prefs, + int* ping_delay) { + if (!prefs || !ping_delay) return false; - DictionaryValue* distro = NULL; - if (!json_root->GetDictionary(L"distribution", &distro) || - !distro->GetInteger(kDistroPingDelay, &delay)) + // 90 seconds is the default that we want to use in case master preferences + // is missing or corrupt. + *ping_delay = 90; + if (!prefs->GetInteger(master_preferences::kDistroPingDelay, ping_delay)) return false; return true; } -int ParseDistributionPreferences(const std::wstring& master_prefs_path) { - if (!file_util::PathExists(master_prefs_path)) - return MASTER_PROFILE_NOT_FOUND; - LOG(INFO) << "master profile found"; +DictionaryValue* ParseDistributionPreferences( + const FilePath& master_prefs_path) { + if (!file_util::PathExists(master_prefs_path)) { + LOG(WARNING) << "Master preferences file not found: " + << master_prefs_path.value(); + return NULL; + } scoped_ptr<DictionaryValue> json_root(GetPrefsFromFile(master_prefs_path)); - if (!json_root.get()) - return MASTER_PROFILE_ERROR; + if (!json_root.get()) { + LOG(WARNING) << "Failed to parse preferences file: " + << master_prefs_path.value(); + return NULL; + } - int parse_result = 0; DictionaryValue* distro = NULL; - if (json_root->GetDictionary(L"distribution", &distro)) { - if (GetBooleanPref(distro, kDistroSkipFirstRunPref)) - parse_result |= MASTER_PROFILE_NO_FIRST_RUN_UI; - if (GetBooleanPref(distro, kDistroShowWelcomePage)) - parse_result |= MASTER_PROFILE_SHOW_WELCOME; - if (GetBooleanPref(distro, kDistroImportSearchPref)) - parse_result |= MASTER_PROFILE_IMPORT_SEARCH_ENGINE; - if (GetBooleanPref(distro, kDistroImportHistoryPref)) - parse_result |= MASTER_PROFILE_IMPORT_HISTORY; - if (GetBooleanPref(distro, kDistroImportBookmarksPref)) - parse_result |= MASTER_PROFILE_IMPORT_BOOKMARKS; - if (GetBooleanPref(distro, kDistroImportHomePagePref)) - parse_result |= MASTER_PROFILE_IMPORT_HOME_PAGE; - if (GetBooleanPref(distro, kMakeChromeDefaultForUser)) - parse_result |= MASTER_PROFILE_MAKE_CHROME_DEFAULT_FOR_USER; - if (GetBooleanPref(distro, kCreateAllShortcuts)) - parse_result |= MASTER_PROFILE_CREATE_ALL_SHORTCUTS; - if (GetBooleanPref(distro, kDoNotLaunchChrome)) - parse_result |= MASTER_PROFILE_DO_NOT_LAUNCH_CHROME; - if (GetBooleanPref(distro, kMakeChromeDefault)) - parse_result |= MASTER_PROFILE_MAKE_CHROME_DEFAULT; - if (GetBooleanPref(distro, kSystemLevel)) - parse_result |= MASTER_PROFILE_SYSTEM_LEVEL; - if (GetBooleanPref(distro, kVerboseLogging)) - parse_result |= MASTER_PROFILE_VERBOSE_LOGGING; - if (GetBooleanPref(distro, kRequireEula)) - parse_result |= MASTER_PROFILE_REQUIRE_EULA; - if (GetBooleanPref(distro, kAltShortcutText)) - parse_result |= MASTER_PROFILE_ALT_SHORTCUT_TXT; - if (GetBooleanPref(distro, kAltFirstRunBubble)) - parse_result |= MASTER_PROFILE_OEM_FIRST_RUN_BUBBLE; + if (!json_root->GetDictionary(L"distribution", &distro)) { + LOG(WARNING) << "Failed to get distriubtion params: " + << master_prefs_path.value(); + return NULL; } - return parse_result; + return distro; } -std::vector<std::wstring> ParseFirstRunTabs( - const std::wstring& master_prefs_path) { +std::vector<std::wstring> ParseFirstRunTabs(const DictionaryValue* prefs) { std::vector<std::wstring> launch_tabs; - scoped_ptr<DictionaryValue> json_root(GetPrefsFromFile(master_prefs_path)); - if (!json_root.get()) + if (!prefs) return launch_tabs; ListValue* tabs_list = NULL; - if (!json_root->GetList(L"first_run_tabs", &tabs_list)) + if (!prefs->GetList(L"first_run_tabs", &tabs_list)) return launch_tabs; for (size_t i = 0; i < tabs_list->GetSize(); ++i) { Value* entry; diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h index 856d53e..103605a 100644 --- a/chrome/installer/util/master_preferences.h +++ b/chrome/installer/util/master_preferences.h @@ -8,64 +8,65 @@ #ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ #define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ -#include <string> -#include <vector> - -#include "base/file_util.h" +#include "base/file_path.h" +#include "base/values.h" namespace installer_util { +namespace master_preferences { +// All the preferences below are expected to be inside the JSON "distribution" +// block. + +// Boolean pref that triggers skipping the first run dialogs. +extern const wchar_t kDistroSkipFirstRunPref[]; +// Boolean pref that triggers loading the welcome page. +extern const wchar_t kDistroShowWelcomePage[]; +// Boolean pref that triggers silent import of the default search engine. +extern const wchar_t kDistroImportSearchPref[]; +// Boolean pref that triggers silent import of the default browser history. +extern const wchar_t kDistroImportHistoryPref[]; +// Boolean pref that triggers silent import of the default browser bookmarks. +extern const wchar_t kDistroImportBookmarksPref[]; +// RLZ ping delay in seconds +extern const wchar_t kDistroPingDelay[]; +// Register Chrome as default browser for the current user. +extern const wchar_t kMakeChromeDefaultForUser[]; +// The following boolean prefs have the same semantics as the corresponding +// setup command line switches. See chrome/installer/util/util_constants.cc +// for more info. +// Create Desktop and QuickLaunch shortcuts. +extern const wchar_t kCreateAllShortcuts[]; +// Prevent installer from launching Chrome after a successful first install. +extern const wchar_t kDoNotLaunchChrome[]; +// Register Chrome as default browser on the system. +extern const wchar_t kMakeChromeDefault[]; +// Install Chrome to system wise location. +extern const wchar_t kSystemLevel[]; +// Run installer in verbose mode. +extern const wchar_t kVerboseLogging[]; +// Show EULA dialog and install only if accepted. +extern const wchar_t kRequireEula[]; +// Use alternate shortcut text for the main shortcut. +extern const wchar_t kAltShortcutText[]; +// Use alternate smaller first run info bubble. +extern const wchar_t kAltFirstRunBubble[]; +// Boolean pref that triggers silent import of the default browser homepage. +extern const wchar_t kDistroImportHomePagePref[]; + +extern const wchar_t kMasterPreferencesValid[]; +} + // This is the default name for the master preferences file used to pre-set // values in the user profile at first run. const wchar_t kDefaultMasterPrefs[] = L"master_preferences"; -// These are the possible results of calling ParseDistributionPreferences. -// Some of the results can be combined, so they are bit flags. -enum MasterPrefResult { - MASTER_PROFILE_NOT_FOUND = 0x1, - // A critical error processing the master profile. - MASTER_PROFILE_ERROR = 0x1 << 1, - // Skip first run dialogs. - MASTER_PROFILE_NO_FIRST_RUN_UI = 0x1 << 2, - // Show welcome page. - MASTER_PROFILE_SHOW_WELCOME = 0x1 << 3, - // Import search engine setting from the default browser. - MASTER_PROFILE_IMPORT_SEARCH_ENGINE = 0x1 << 4, - // Import history from the default browser. - MASTER_PROFILE_IMPORT_HISTORY = 0x1 << 5, - // Import bookmarks from the default browser. - MASTER_PROFILE_IMPORT_BOOKMARKS = 0x1 << 6, - // Register Chrome as default browser for the current user. This option is - // different than MAKE_CHROME_DEFAULT as installer ignores this option and - // Chrome on first run makes itself default. - MASTER_PROFILE_MAKE_CHROME_DEFAULT_FOR_USER = 0x1 << 7, - // The following boolean prefs have the same semantics as the corresponding - // setup command line switches. See chrome/installer/util/util_constants.cc - // for more info. - // Create Desktop and QuickLaunch shortcuts. - MASTER_PROFILE_CREATE_ALL_SHORTCUTS = 0x1 << 8, - // Prevent installer from launching Chrome after a successful first install. - MASTER_PROFILE_DO_NOT_LAUNCH_CHROME = 0x1 << 9, - // Register Chrome as default browser on the system. - MASTER_PROFILE_MAKE_CHROME_DEFAULT = 0x1 << 10, - // Install Chrome to system wise location. - MASTER_PROFILE_SYSTEM_LEVEL = 0x1 << 11, - // Run installer in verbose mode. - MASTER_PROFILE_VERBOSE_LOGGING = 0x1 << 12, - // Show the EULA and do not install if not accepted. - MASTER_PROFILE_REQUIRE_EULA = 0x1 << 13, - // Use an alternate description text for some shortcuts. - MASTER_PROFILE_ALT_SHORTCUT_TXT = 0x1 << 14, - // Use a smaller OEM info bubble on first run. - MASTER_PROFILE_OEM_FIRST_RUN_BUBBLE = 0x1 << 15, - // Import home page from the default browser. - MASTER_PROFILE_IMPORT_HOME_PAGE = 0x1 << 16 -}; +bool GetBooleanPreference(const DictionaryValue* prefs,
+ const std::wstring& name);
// This function gets ping delay (ping_delay in the sample above) from master // preferences. -bool GetDistributionPingDelay(const FilePath& master_prefs_path, - int& delay); +bool GetDistributionPingDelay(const DictionaryValue* prefs, + int* ping_delay); // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function parses the distribution @@ -109,7 +110,8 @@ bool GetDistributionPingDelay(const FilePath& master_prefs_path, // installation properties. This entry will be ignored at other times. // This function parses the 'distribution' entry and returns a combination // of MasterPrefResult. -int ParseDistributionPreferences(const std::wstring& master_prefs_path); +DictionaryValue* ParseDistributionPreferences( + const FilePath& master_prefs_path); // As part of the master preferences an optional section indicates the tabs // to open during first run. An example is the following: @@ -125,8 +127,7 @@ int ParseDistributionPreferences(const std::wstring& master_prefs_path); // // This function retuns the list as a vector of strings. If the master // preferences file does not contain such list the vector is empty. -std::vector<std::wstring> ParseFirstRunTabs( - const std::wstring& master_prefs_path); +std::vector<std::wstring> ParseFirstRunTabs(const DictionaryValue* prefs); } #endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_ diff --git a/chrome/installer/util/util_constants.h b/chrome/installer/util/util_constants.h index 5256d6a..4e209b2 100644 --- a/chrome/installer/util/util_constants.h +++ b/chrome/installer/util/util_constants.h @@ -42,31 +42,6 @@ enum InstallStatus { INSTALL_DIR_IN_USE // Installation directory is in use by another process }; -// These are distribution related install options specified through command -// line switches (see below) or master preference file (see -// chrome/installer/util/master_preference.h). The options can be combined, -// so they are bit flags. -enum InstallOption { - // A master profile file is provided to installer. - MASTER_PROFILE_PRESENT = 0x1, - // The master profile file provided is valid. - MASTER_PROFILE_VALID = 0x1 << 1, - // Create Desktop and QuickLaunch shortcuts. - CREATE_ALL_SHORTCUTS = 0x1 << 2, - // Prevent installer from launching Chrome after a successful first install. - DO_NOT_LAUNCH_CHROME = 0x1 << 3, - // Register Chrome as default browser on the system. - MAKE_CHROME_DEFAULT = 0x1 << 4, - // Install Chrome to system wise location. - SYSTEM_LEVEL = 0x1 << 5, - // Run installer in verbose mode. - VERBOSE_LOGGING = 0x1 << 6, - // Show the EULA dialog. - SHOW_EULA_DIALOG = 0x1 << 7, - // Use alternate dekstop shortcut text. - ALT_DESKTOP_SHORTCUT = 0x1 << 8 -}; - namespace switches { extern const wchar_t kCreateAllShortcuts[]; extern const wchar_t kDeleteProfile[]; |