summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 17:46:05 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 17:46:05 +0000
commit6752d476fbb54c3dd00343c7b194c23620c3d1e5 (patch)
tree77afb9a9f6a819e509f0a223f3b1e77012b9d47b
parentbf0791a666425e2e61400953fa538ed1d2b2edf8 (diff)
downloadchromium_src-6752d476fbb54c3dd00343c7b194c23620c3d1e5.zip
chromium_src-6752d476fbb54c3dd00343c7b194c23620c3d1e5.tar.gz
chromium_src-6752d476fbb54c3dd00343c7b194c23620c3d1e5.tar.bz2
Refactoring of master preferences parsing before adding a new preference.
Currently we are parsing master preferences file three time on startup. Since we only return an int bit mask flag after parsing preferences, it can not handle any preference other than boolean and we end up reading it again for first run tabs and ping delay. This change refactors all the preferences parsing logic to directly pass around DictionaryValue object around in Chrome as well as installer. No functional change but this will make adding a new preference for new icon more logical since we will not read the preferences file once again. BUG=12701 TEST=Make sure all the distribution preferences still work as before. Review URL: http://codereview.chromium.org/159539 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22284 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc12
-rw-r--r--chrome/browser/first_run.h6
-rw-r--r--chrome/browser/first_run_win.cc48
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc4
-rw-r--r--chrome/installer/setup/install.cc56
-rw-r--r--chrome/installer/setup/install.h7
-rw-r--r--chrome/installer/setup/setup_main.cc141
-rw-r--r--chrome/installer/util/browser_distribution.cc2
-rw-r--r--chrome/installer/util/browser_distribution.h2
-rw-r--r--chrome/installer/util/google_chrome_distribution.cc2
-rw-r--r--chrome/installer/util/google_chrome_distribution.h2
-rw-r--r--chrome/installer/util/google_chrome_distribution_unittest.cc77
-rw-r--r--chrome/installer/util/master_preferences.cc180
-rw-r--r--chrome/installer/util/master_preferences.h127
-rw-r--r--chrome/installer/util/util_constants.h25
15 files changed, 325 insertions, 366 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 3e85501..906ee5b 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -447,14 +447,16 @@ int BrowserMain(const MainFunctionParams& parameters) {
BrowserInit browser_init;
+ int rlz_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,
+ &rlz_ping_delay);
// The master prefs might specify a set of urls to display.
if (first_run_tabs.size())
AddFirstRunNewTabs(&browser_init, first_run_tabs);
@@ -660,12 +662,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, rlz_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..0914e9f 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
@@ -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 30b6df32..7d16dc3 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::GetFirstRunTabs(prefs.get());
+ if (ping_delay)
+ installer_util::GetDistributionPingDelay(prefs.get(), ping_delay);
- if (parse_result & installer_util::MASTER_PROFILE_REQUIRE_EULA) {
+ if (installer_util::GetDistroBooleanPreference(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::GetDistroBooleanPreference(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::GetDistroBooleanPreference(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::GetDistroBooleanPreference(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::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportSearchPref))
import_items += SEARCH_ENGINES;
- if (parse_result & installer_util::MASTER_PROFILE_IMPORT_HISTORY)
+ if (installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportHistoryPref))
import_items += HISTORY;
- if (parse_result & installer_util::MASTER_PROFILE_IMPORT_BOOKMARKS)
+ if (installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportBookmarksPref))
import_items += FAVORITES;
- if (parse_result & installer_util::MASTER_PROFILE_IMPORT_HOME_PAGE)
+ if (installer_util::GetDistroBooleanPreference(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::GetDistroBooleanPreference(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..ba62f0c 100644
--- a/chrome/installer/setup/install.cc
+++ b/chrome/installer/setup/install.cc
@@ -7,24 +7,21 @@
#include "chrome/installer/setup/install.h"
-#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/logging.h"
#include "base/path_service.h"
#include "base/registry.h"
#include "base/scoped_ptr.h"
-#include "base/string_util.h"
-#include "chrome/common/chrome_constants.h"
#include "chrome/installer/setup/setup_constants.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/create_reg_key_work_item.h"
#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"
-#include "chrome/installer/util/work_item.h"
-#include "chrome/installer/util/version.h"
#include "chrome/installer/util/work_item_list.h"
// Build-time generated include file.
@@ -160,11 +157,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 +240,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 +275,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 +288,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 +480,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::GetDistroBooleanPreference(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 +524,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::GetDistroBooleanPreference(prefs,
+ installer_util::master_preferences::kCreateAllShortcuts);
+ bool alt_shortcut = installer_util::GetDistroBooleanPreference(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::GetDistroBooleanPreference(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..eb2e8ba 100644
--- a/chrome/installer/setup/setup_main.cc
+++ b/chrome/installer/setup/setup_main.cc
@@ -206,74 +206,63 @@ 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* prefs = NULL;
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;
- }
- // 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;
+ FilePath prefs_path(
+ cmd_line.GetSwitchValue(installer_util::switches::kInstallerData));
+ prefs = installer_util::ParseDistributionPreferences(prefs_path);
}
- if (preferences & installer_util::MASTER_PROFILE_CREATE_ALL_SHORTCUTS ||
- cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts))
- options |= installer_util::CREATE_ALL_SHORTCUTS;
+ if (!prefs)
+ prefs = 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))
+ installer_util::SetDistroBooleanPreference(
+ prefs, 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))
+ installer_util::SetDistroBooleanPreference(
+ prefs, 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))
+ installer_util::SetDistroBooleanPreference(
+ prefs, 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))
+ installer_util::SetDistroBooleanPreference(
+ prefs, 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))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kVerboseLogging, true);
- return options;
+ if (cmd_line.HasSwitch(installer_util::switches::kAltDesktopShortcut))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kAltShortcutText, true);
+
+ return prefs;
}
-// 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 +297,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::GetDistroBooleanPreference(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 +323,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 +336,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 +352,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 +360,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 +370,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 +388,15 @@ 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);
+ 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::GetDistroBooleanPreference(prefs,
+ installer_util::master_preferences::kDoNotLaunchChrome))
+ installer::LaunchChrome(system_level);
}
}
}
@@ -414,7 +405,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 +413,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 +611,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::GetDistroBooleanPreference(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::GetDistroBooleanPreference(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 +684,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/google_chrome_distribution_unittest.cc b/chrome/installer/util/google_chrome_distribution_unittest.cc
index c404061..f84916b 100644
--- a/chrome/installer/util/google_chrome_distribution_unittest.cc
+++ b/chrome/installer/util/google_chrome_distribution_unittest.cc
@@ -256,8 +256,8 @@ TEST(BrowserDistribution, AlternateAndNormalShortcutName) {
}
TEST(MasterPreferences, ParseDistroParams) {
- std::wstring prefs;
- ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs));
+ std::wstring prefs_file;
+ ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
const char text[] =
"{ \n"
" \"distribution\": { \n"
@@ -281,31 +281,49 @@ TEST(MasterPreferences, ParseDistroParams) {
" }\n"
"} \n";
- EXPECT_TRUE(file_util::WriteFile(prefs, text, sizeof(text)));
- int result = installer_util::ParseDistributionPreferences(prefs);
- EXPECT_FALSE(result & installer_util::MASTER_PROFILE_NOT_FOUND);
- EXPECT_FALSE(result & installer_util::MASTER_PROFILE_ERROR);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_NO_FIRST_RUN_UI);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_SHOW_WELCOME);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_IMPORT_SEARCH_ENGINE);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_IMPORT_HISTORY);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_IMPORT_BOOKMARKS);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_IMPORT_HOME_PAGE);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_CREATE_ALL_SHORTCUTS);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_DO_NOT_LAUNCH_CHROME);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_MAKE_CHROME_DEFAULT);
- EXPECT_TRUE(result &
- installer_util::MASTER_PROFILE_MAKE_CHROME_DEFAULT_FOR_USER);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_SYSTEM_LEVEL);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_VERBOSE_LOGGING);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_REQUIRE_EULA);
- EXPECT_TRUE(result & installer_util::MASTER_PROFILE_ALT_SHORTCUT_TXT);
- EXPECT_TRUE(file_util::Delete(prefs, false));
+ EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ scoped_ptr<DictionaryValue> prefs(
+ installer_util::ParseDistributionPreferences(
+ FilePath::FromWStringHack(prefs_file)));
+ EXPECT_TRUE(prefs.get() != NULL);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroSkipFirstRunPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroShowWelcomePage));
+
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportSearchPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportHistoryPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportBookmarksPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportHomePagePref));
+
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kCreateAllShortcuts));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDoNotLaunchChrome));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kMakeChromeDefault));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kMakeChromeDefaultForUser));
+
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kSystemLevel));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kVerboseLogging));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kRequireEula));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kAltShortcutText));
+
+ EXPECT_TRUE(file_util::Delete(prefs_file, false));
}
TEST(MasterPreferences, FirstRunTabs) {
- std::wstring prefs;
- ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs));
+ std::wstring prefs_file;
+ ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
const char text[] =
"{ \n"
" \"distribution\": { \n"
@@ -318,12 +336,17 @@ TEST(MasterPreferences, FirstRunTabs) {
" ]\n"
"} \n";
- EXPECT_TRUE(file_util::WriteFile(prefs, text, sizeof(text)));
+ EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ scoped_ptr<DictionaryValue> prefs(
+ installer_util::ParseDistributionPreferences(
+ FilePath::FromWStringHack(prefs_file)));
+ EXPECT_TRUE(prefs.get() != NULL);
+
typedef std::vector<std::wstring> TabsVector;
- TabsVector tabs = installer_util::ParseFirstRunTabs(prefs);
+ TabsVector tabs = installer_util::GetFirstRunTabs(prefs.get());
ASSERT_EQ(3, tabs.size());
EXPECT_EQ(L"http://google.com/f1", tabs[0]);
EXPECT_EQ(L"https://google.com/f2", tabs[1]);
EXPECT_EQ(L"new_tab_page", tabs[2]);
- EXPECT_TRUE(file_util::Delete(prefs, false));
+ EXPECT_TRUE(file_util::Delete(prefs_file, false));
}
diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc
index 8a7c637..f8c8018 100644
--- a/chrome/installer/util/master_preferences.cc
+++ b/chrome/installer/util/master_preferences.cc
@@ -11,154 +11,92 @@
namespace {
-DictionaryValue* ReadJSONPrefs(const std::string& data) {
- JSONStringValueSerializer json(data);
+const wchar_t* kDistroDict = L"distribution";
+
+DictionaryValue* GetPrefsFromFile(const FilePath& master_prefs_path) {
+ std::string json_data;
+ if (!file_util::ReadFileToString(master_prefs_path, &json_data))
+ return NULL;
+
+ 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.
-
-// 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.
-const wchar_t kDistroShowWelcomePage[] = L"show_welcome_page";
-// Boolean pref that triggers silent import of the default search engine.
-const wchar_t kDistroImportSearchPref[] = L"import_search_engine";
-// Boolean pref that triggers silent import of the default browser history.
-const wchar_t kDistroImportHistoryPref[] = L"import_history";
-// Boolean pref that triggers silent import of the default browser bookmarks.
+namespace master_preferences {
+const wchar_t kAltFirstRunBubble[] = L"oem_bubble";
+const wchar_t kAltShortcutText[] = L"alternate_shortcut_text";
+const wchar_t kCreateAllShortcuts[] = L"create_all_shortcuts";
const wchar_t kDistroImportBookmarksPref[] = L"import_bookmarks";
-// RLZ ping delay in seconds
+const wchar_t kDistroImportHistoryPref[] = L"import_history";
+const wchar_t kDistroImportHomePagePref[] = L"import_home_page";
+const wchar_t kDistroImportSearchPref[] = L"import_search_engine";
const wchar_t kDistroPingDelay[] = L"ping_delay";
-// Register Chrome as default browser for the current user.
-const wchar_t kMakeChromeDefaultForUser[] = L"make_chrome_default_for_user";
-// 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.
-const wchar_t kCreateAllShortcuts[] = L"create_all_shortcuts";
-// Prevent installer from launching Chrome after a successful first install.
+const wchar_t kDistroShowWelcomePage[] = L"show_welcome_page";
+const wchar_t kDistroSkipFirstRunPref[] = L"skip_first_run_ui";
const wchar_t kDoNotLaunchChrome[] = L"do_not_launch_chrome";
-// Register Chrome as default browser on the system.
const wchar_t kMakeChromeDefault[] = L"make_chrome_default";
-// Install Chrome to system wise location.
+const wchar_t kMakeChromeDefaultForUser[] = L"make_chrome_default_for_user";
+const wchar_t kRequireEula[] = L"require_eula";
const wchar_t kSystemLevel[] = L"system_level";
-// Run installer in verbose mode.
const wchar_t kVerboseLogging[] = L"verbose_logging";
-// Show EULA dialog and install only if accepted.
-const wchar_t kRequireEula[] = L"require_eula";
-// Use alternate shortcut text for the main shortcut.
-const wchar_t kAltShortcutText[] = L"alternate_shortcut_text";
-// Use alternate smaller first run info bubble.
-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);
- }
+bool GetDistroBooleanPreference(const DictionaryValue* prefs,
+ const std::wstring& name) {
- if (!file_util::PathExists(master_prefs))
- return false;
+ bool value = false;
+ DictionaryValue* distro = NULL;
+ if (prefs && prefs->GetDictionary(kDistroDict, &distro) && distro)
+ distro->GetBoolean(name, &value);
+ return value;
+}
- scoped_ptr<DictionaryValue> json_root(
- GetPrefsFromFile(master_prefs.ToWStringHack()));
- if (!json_root.get())
+bool GetDistributionPingDelay(const DictionaryValue* prefs,
+ int* ping_delay) {
+ if (!ping_delay)
return false;
+ // 90 seconds is the default that we want to use in case master preferences
+ // is missing or corrupt.
+ *ping_delay = 90;
+
DictionaryValue* distro = NULL;
- if (!json_root->GetDictionary(L"distribution", &distro) ||
- !distro->GetInteger(kDistroPingDelay, &delay))
+ if (!prefs || !prefs->GetDictionary(kDistroDict, &distro) || !distro)
+ return false;
+
+ if (!distro->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";
-
- scoped_ptr<DictionaryValue> json_root(GetPrefsFromFile(master_prefs_path));
- if (!json_root.get())
- return MASTER_PROFILE_ERROR;
-
- 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;
+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;
}
- return parse_result;
+
+ return GetPrefsFromFile(master_prefs_path);
}
-std::vector<std::wstring> ParseFirstRunTabs(
- const std::wstring& master_prefs_path) {
+std::vector<std::wstring> GetFirstRunTabs(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;
@@ -172,4 +110,18 @@ std::vector<std::wstring> ParseFirstRunTabs(
return launch_tabs;
}
+bool SetDistroBooleanPreference(DictionaryValue* prefs,
+ const std::wstring& name,
+ bool value) {
+
+ bool ret = false;
+ if (prefs && !name.empty()) {
+ std::wstring key(kDistroDict);
+ key.append(L"." + name);
+ if (prefs->SetBoolean(key, value))
+ ret = true;
+ }
+ return ret;
+}
+
} // installer_util
diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h
index 856d53e..d9efb3d 100644
--- a/chrome/installer/util/master_preferences.h
+++ b/chrome/installer/util/master_preferences.h
@@ -8,64 +8,64 @@
#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. Some of them also have equivalent command line option. If same option
+// is specified in master preference as well as command line, the commnd line
+// value takes precedence.
+
+// Boolean. Use alternate text for the shortcut. Cmd line override present.
+extern const wchar_t kAltShortcutText[];
+// Boolean. Use alternate smaller first run info bubble.
+extern const wchar_t kAltFirstRunBubble[];
+// Boolean. Create Desktop and QuickLaunch shortcuts. Cmd line override present.
+extern const wchar_t kCreateAllShortcuts[];
+// Boolean pref that triggers silent import of the default browser bookmarks.
+extern const wchar_t kDistroImportBookmarksPref[];
+// 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 homepage.
+extern const wchar_t kDistroImportHomePagePref[];
+// Boolean pref that triggers silent import of the default search engine.
+extern const wchar_t kDistroImportSearchPref[];
+// Integer. RLZ ping delay in seconds.
+extern const wchar_t kDistroPingDelay[];
+// Boolean pref that triggers loading the welcome page.
+extern const wchar_t kDistroShowWelcomePage[];
+// Boolean pref that triggers skipping the first run dialogs.
+extern const wchar_t kDistroSkipFirstRunPref[];
+// Boolean. Do not launch Chrome after first install. Cmd line override present.
+extern const wchar_t kDoNotLaunchChrome[];
+// Boolean. Register Chrome as default browser. Cmd line override present.
+extern const wchar_t kMakeChromeDefault[];
+// Boolean. Register Chrome as default browser for the current user.
+extern const wchar_t kMakeChromeDefaultForUser[];
+// Boolean. Show EULA dialog before install.
+extern const wchar_t kRequireEula[];
+// Boolean. Install Chrome to system wise location. Cmd line override present.
+extern const wchar_t kSystemLevel[];
+// Boolean. Run installer in verbose mode. Cmd line override present.
+extern const wchar_t kVerboseLogging[];
+}
+
// 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
-};
+// Gets the value of given boolean preference |name| from |prefs| dictionary
+// which is assumed to contain a dictionary named "distribution".
+bool GetDistroBooleanPreference(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
@@ -75,21 +75,22 @@ bool GetDistributionPingDelay(const FilePath& master_prefs_path,
//
// {
// "distribution": {
-// "skip_first_run_ui": true,
-// "show_welcome_page": true,
-// "import_search_engine": true,
-// "import_history": false,
+// "alternate_shortcut_text": false,
+// "oem_bubble": false,
+// "create_all_shortcuts": true,
// "import_bookmarks": false,
+// "import_history": false,
// "import_home_page": false,
-// "create_all_shortcuts": true,
+// "import_search_engine": true,
+// "ping_delay": 40,
+// "show_welcome_page": true,
+// "skip_first_run_ui": true,
// "do_not_launch_chrome": false,
// "make_chrome_default": false,
// "make_chrome_default_for_user": true,
-// "system_level": false,
-// "verbose_logging": true,
// "require_eula": true,
-// "alternate_shortcut_text": false,
-// "ping_delay": 40
+// "system_level": false,
+// "verbose_logging": true
// },
// "browser": {
// "show_home_button": true
@@ -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,13 @@ 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> GetFirstRunTabs(const DictionaryValue* prefs);
+
+// Sets the value of given boolean preference |name| in "distribution"
+// dictionary inside |prefs| dictionary.
+bool SetDistroBooleanPreference(DictionaryValue* prefs,
+ const std::wstring& name,
+ bool value);
}
#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[];