summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 20:12:50 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 20:12:50 +0000
commitc604a55498cea3b78c4eafda2cb408fd16edf6af (patch)
treeb99109b879257d12a2cbe5c537d0281625946bb2
parent41c78fa1896c5f849c2160ae5de84c232e2c3de9 (diff)
downloadchromium_src-c604a55498cea3b78c4eafda2cb408fd16edf6af.zip
chromium_src-c604a55498cea3b78c4eafda2cb408fd16edf6af.tar.gz
chromium_src-c604a55498cea3b78c4eafda2cb408fd16edf6af.tar.bz2
Allowing MSI mode detection to work from the master preferences file.
Refactor the piece of master preferences code that was in setup_util.h|cc (setup) into master_preferences.h|cc (install_util). This adds an install_util -> googleurl dependency, which should to be fine. Add in master_preferences_dummy.cc to keep the nacl64 stuff compiling happily. Add values.h|cc to the portion of base built in 64 bit mode and add a minor fix to values.cc to make it build. Also refactor accompanying master_preferences test code from setup tests to install_util tests. BUG=19370 Review URL: http://codereview.chromium.org/979003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42248 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base.gypi4
-rw-r--r--base/values.cc7
-rw-r--r--chrome/installer/installer_util.gypi7
-rw-r--r--chrome/installer/setup/install.cc37
-rw-r--r--chrome/installer/setup/setup_main.cc7
-rw-r--r--chrome/installer/setup/setup_util.cc55
-rw-r--r--chrome/installer/setup/setup_util.h7
-rw-r--r--chrome/installer/setup/setup_util_unittest.cc78
-rw-r--r--chrome/installer/util/install_util.cc15
-rw-r--r--chrome/installer/util/install_util.h5
-rw-r--r--chrome/installer/util/master_preferences.cc82
-rw-r--r--chrome/installer/util/master_preferences.h58
-rw-r--r--chrome/installer/util/master_preferences_constants.cc32
-rw-r--r--chrome/installer/util/master_preferences_constants.h64
-rw-r--r--chrome/installer/util/master_preferences_dummy.cc68
-rw-r--r--chrome/installer/util/master_preferences_unittest.cc78
-rw-r--r--chrome/installer/util/util_constants.cc1
-rw-r--r--chrome/installer/util/util_constants.h1
18 files changed, 373 insertions, 233 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 3325b63..eb99848 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -254,6 +254,8 @@
'utf_string_conversions.cc',
'utf_string_conversions.h',
'unix_domain_socket_posix.cc',
+ 'values.cc',
+ 'values.h',
'waitable_event.h',
'waitable_event_posix.cc',
'waitable_event_watcher.h',
@@ -548,8 +550,6 @@
'sync_socket_posix.cc',
'time_mac.cc',
'time_posix.cc',
- 'values.cc',
- 'values.h',
'version.cc',
'version.h',
],
diff --git a/base/values.cc b/base/values.cc
index f78f474..f214ead 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -816,7 +816,12 @@ int ListValue::Remove(const Value& value) {
size_t index = i - list_.begin();
delete *i;
list_.erase(i);
- return index;
+
+ // TODO(anyone): Returning a signed int type here is just wrong.
+ // Change this interface to return a size_t.
+ DCHECK(index <= INT_MAX);
+ int return_index = static_cast<int>(index);
+ return return_index;
}
}
return -1;
diff --git a/chrome/installer/installer_util.gypi b/chrome/installer/installer_util.gypi
index ba164a9..528a5bf 100644
--- a/chrome/installer/installer_util.gypi
+++ b/chrome/installer/installer_util.gypi
@@ -37,6 +37,8 @@
'util/install_util.h',
'util/l10n_string_util.cc',
'util/l10n_string_util.h',
+ 'util/master_preferences_constants.cc',
+ 'util/master_preferences_constants.h',
'util/move_tree_work_item.cc',
'util/move_tree_work_item.h',
'util/self_reg_work_item.cc',
@@ -70,6 +72,7 @@
},
'dependencies': [
'installer_util_strings',
+ '../../build/temp_gyp/googleurl.gyp:googleurl',
'../chrome.gyp:common_constants',
'../chrome.gyp:chrome_resources',
'../chrome.gyp:chrome_strings',
@@ -114,6 +117,8 @@
],
'sources': [
'util/google_chrome_distribution_dummy.cc',
+ 'util/master_preferences.h',
+ 'util/master_preferences_dummy.cc',
],
'configurations': {
'Common_Base': {
@@ -136,6 +141,8 @@
'sources': [
'util/master_preferences.cc',
'util/master_preferences.h',
+ 'util/master_preferences_constants.cc',
+ 'util/master_preferences_constants.h',
],
'include_dirs': [
'<(DEPTH)',
diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc
index cba5704..71ad8ae 100644
--- a/chrome/installer/setup/install.cc
+++ b/chrome/installer/setup/install.cc
@@ -99,6 +99,11 @@ void AppendUninstallCommandLineFlags(std::wstring* uninstall_cmd_line,
uninstall_cmd_line->append(installer_util::switches::kChromeSxS);
}
+ if (InstallUtil::IsMSIProcess()) {
+ uninstall_cmd_line->append(L" --");
+ uninstall_cmd_line->append(installer_util::switches::kMsi);
+ }
+
// Propagate the verbose logging switch to uninstalls too.
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(installer_util::switches::kVerboseLogging)) {
@@ -128,21 +133,29 @@ void AddUninstallShortcutWorkItems(HKEY reg_root,
file_util::GetFilenameFromPath(exe_path));
uninstall_cmd.append(L"\"");
- AppendUninstallCommandLineFlags(&uninstall_cmd,
- reg_root == HKEY_LOCAL_MACHINE);
-
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(installer_util::switches::kMsi)) {
- // If we're running at the behest of an MSI, store our uninstall string
- // in the Google Update client state key.
- std::wstring update_state_key = dist->GetStateKey();
- install_list->AddCreateRegKeyWorkItem(reg_root, update_state_key);
- install_list->AddSetRegValueWorkItem(reg_root, update_state_key,
- installer_util::kUninstallStringField, uninstall_cmd, true);
- } else {
- // Otherwise, create DisplayName, UninstallString and InstallLocation keys.
+
+ // When we are installed via an MSI, we need to store our uninstall strings
+ // in the Google Update client state key. We do this even for non-MSI
+ // managed installs to avoid breaking the edge case whereby an MSI-managed
+ // install is updated by a non-msi installer (which would confuse the MSI
+ // machinery if these strings were not also updated).
+ std::wstring uninstall_arguments;
+ AppendUninstallCommandLineFlags(&uninstall_arguments,
+ reg_root == HKEY_LOCAL_MACHINE);
+ std::wstring update_state_key = dist->GetStateKey();
+ install_list->AddCreateRegKeyWorkItem(reg_root, update_state_key);
+ install_list->AddSetRegValueWorkItem(reg_root, update_state_key,
+ installer_util::kUninstallStringField, uninstall_cmd, true);
+ install_list->AddSetRegValueWorkItem(reg_root, update_state_key,
+ installer_util::kUninstallArgumentsField, uninstall_arguments, true);
+
+ // MSI installations will manage their own uninstall shortcuts.
+ if (!InstallUtil::IsMSIProcess()) {
+ AppendUninstallCommandLineFlags(&uninstall_cmd,
+ reg_root == HKEY_LOCAL_MACHINE);
std::wstring uninstall_reg = dist->GetUninstallRegPath();
install_list->AddCreateRegKeyWorkItem(reg_root, uninstall_reg);
install_list->AddSetRegValueWorkItem(reg_root, uninstall_reg,
diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc
index c4ab6f8..94fc237 100644
--- a/chrome/installer/setup/setup_main.cc
+++ b/chrome/installer/setup/setup_main.cc
@@ -597,7 +597,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
CommandLine::Init(0, NULL);
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
installer::InitInstallerLogging(parsed_command_line);
- scoped_ptr<DictionaryValue> prefs(setup_util::GetInstallPreferences(
+ scoped_ptr<DictionaryValue> prefs(installer_util::GetInstallPreferences(
parsed_command_line));
bool value = false;
if (installer_util::GetDistroBooleanPreference(prefs.get(),
@@ -605,6 +605,8 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
value)
logging::SetMinLogLevel(logging::LOG_INFO);
+ LOG(INFO) << "Command Line: " << parsed_command_line.command_line_string();
+
bool system_install = false;
installer_util::GetDistroBooleanPreference(prefs.get(),
installer_util::master_preferences::kSystemLevel, &system_install);
@@ -714,7 +716,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
// MSI demands that custom actions always return 0 (ERROR_SUCCESS) or it will
// rollback the action. If we're uninstalling we want to avoid this, so always
// report success, squashing any more informative return codes.
- if (!(parsed_command_line.HasSwitch(installer_util::switches::kMsi) &&
+ if (!(InstallUtil::IsMSIProcess() &&
parsed_command_line.HasSwitch(installer_util::switches::kUninstall))) {
// Note that we allow the status installer_util::UNINSTALL_REQUIRES_REBOOT
// to pass through, since this is only returned on uninstall which is never
@@ -722,5 +724,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
dist->GetInstallReturnCode(install_status);
}
+ LOG(INFO) << "Installation complete, returning: " << return_code;
return return_code;
}
diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc
index ad09ec8..2136616 100644
--- a/chrome/installer/setup/setup_util.cc
+++ b/chrome/installer/setup/setup_util.cc
@@ -33,61 +33,6 @@ int setup_util::ApplyDiffPatch(const std::wstring& src,
return ApplyBinaryPatch(src.c_str(), patch.c_str(), dest.c_str());
}
-DictionaryValue* setup_util::GetInstallPreferences(
- const CommandLine& cmd_line) {
- DictionaryValue* prefs = NULL;
-
- if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) {
- FilePath prefs_path(
- cmd_line.GetSwitchValue(installer_util::switches::kInstallerData));
- prefs = installer_util::ParseDistributionPreferences(prefs_path);
- }
-
- if (!prefs)
- prefs = new DictionaryValue();
-
- if (cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kCreateAllShortcuts, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kDoNotCreateShortcuts))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kDoNotCreateShortcuts, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kMsi))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kMsi, true);
-
- if (cmd_line.HasSwitch(
- installer_util::switches::kDoNotRegisterForUpdateLaunch))
- installer_util::SetDistroBooleanPreference(
- prefs,
- installer_util::master_preferences::kDoNotRegisterForUpdateLaunch,
- true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kDoNotLaunchChrome))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kDoNotLaunchChrome, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kMakeChromeDefault, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kSystemLevel))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kSystemLevel, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kVerboseLogging))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kVerboseLogging, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kAltDesktopShortcut))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kAltShortcutText, true);
-
- return prefs;
-}
-
installer::Version* setup_util::GetVersionFromDir(
const std::wstring& chrome_path) {
LOG(INFO) << "Looking for Chrome version folder under " << chrome_path;
diff --git a/chrome/installer/setup/setup_util.h b/chrome/installer/setup/setup_util.h
index a2f1ee9..350894d 100644
--- a/chrome/installer/setup/setup_util.h
+++ b/chrome/installer/setup/setup_util.h
@@ -7,8 +7,6 @@
#ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
#define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
-#include "base/command_line.h"
-#include "base/values.h"
#include "chrome/installer/util/version.h"
namespace setup_util {
@@ -19,11 +17,6 @@ namespace setup_util {
const std::wstring& patch,
const std::wstring& dest);
- // Parse command line and read master preferences, if present, to get
- // distribution related install options. Merge them if any command line
- // options present (command line value takes precedence).
- DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line);
-
// Find the version of Chrome from an install source directory.
// Chrome_path should contain a version folder.
// Returns the first version found or NULL if no version is found.
diff --git a/chrome/installer/setup/setup_util_unittest.cc b/chrome/installer/setup/setup_util_unittest.cc
index e0f87ae..fc0ac9e 100644
--- a/chrome/installer/setup/setup_util_unittest.cc
+++ b/chrome/installer/setup/setup_util_unittest.cc
@@ -63,84 +63,6 @@ TEST_F(SetupUtilTest, ApplyDiffPatchTest) {
EXPECT_EQ(setup_util::ApplyDiffPatch(L"", L"", L""), 6);
}
-// Test that we are parsing master preferences correctly.
-TEST_F(SetupUtilTest, GetInstallPreferencesTest) {
- // Create a temporary prefs file.
- FilePath prefs_file;
- ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file));
- const char text[] =
- "{ \n"
- " \"distribution\": { \n"
- " \"skip_first_run_ui\": true,\n"
- " \"create_all_shortcuts\": false,\n"
- " \"do_not_launch_chrome\": true,\n"
- " \"system_level\": true,\n"
- " \"verbose_logging\": false\n"
- " }\n"
- "} \n";
- EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
-
- // Make sure command line values override the values in master preferences.
- std::wstring cmd_str(
- L"setup.exe --installerdata=\"" + prefs_file.value() + L"\"");
- cmd_str.append(L" --create-all-shortcuts");
- cmd_str.append(L" --do-not-launch-chrome");
- cmd_str.append(L" --alt-desktop-shortcut");
- CommandLine cmd_line = CommandLine::FromString(cmd_str);
- scoped_ptr<DictionaryValue> prefs(
- setup_util::GetInstallPreferences(cmd_line));
- EXPECT_TRUE(prefs.get() != NULL);
-
- // Check prefs that do not have any equivalent command line option.
- bool value = false;
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroSkipFirstRunPref, &value) &&
- value);
- EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroShowWelcomePage, &value));
-
- // Now check that prefs got merged correctly.
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kCreateAllShortcuts, &value) &&
- value);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDoNotLaunchChrome, &value) &&
- value);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kAltShortcutText, &value) &&
- value);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kSystemLevel, &value) &&
- value);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kVerboseLogging, &value));
- EXPECT_FALSE(value);
-
- // Delete temporary prefs file.
- EXPECT_TRUE(file_util::Delete(prefs_file, false));
-
- // Check that if master prefs doesn't exist, we can still parse the common
- // prefs.
- cmd_str = L"setup.exe --create-all-shortcuts --do-not-launch-chrome"
- L" --alt-desktop-shortcut";
- cmd_line.ParseFromString(cmd_str);
- prefs.reset(setup_util::GetInstallPreferences(cmd_line));
- EXPECT_TRUE(prefs.get() != NULL);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kCreateAllShortcuts, &value) &&
- value);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDoNotLaunchChrome, &value) &&
- value);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kAltShortcutText, &value) &&
- value);
- EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kSystemLevel, &value));
- EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kVerboseLogging, &value));
-}
-
// Test that we are parsing Chrome version correctly.
TEST_F(SetupUtilTest, GetVersionFromDirTest) {
// Create a version dir
diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc
index e3e7d45..a3f32d1 100644
--- a/chrome/installer/util/install_util.cc
+++ b/chrome/installer/util/install_util.cc
@@ -20,10 +20,11 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/win_util.h"
-
+#include "chrome/common/json_value_serializer.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/l10n_string_util.h"
+#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/util_constants.h"
#include "chrome/installer/util/work_item_list.h"
@@ -163,6 +164,18 @@ bool InstallUtil::IsChromeSxSProcess() {
chrome_sxs_dir);
}
+bool InstallUtil::IsMSIProcess() {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ CHECK(command_line);
+
+ scoped_ptr<DictionaryValue> prefs(installer_util::GetInstallPreferences(
+ *command_line));
+ bool value = false;
+ return (installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kMsi, &value) &&
+ value);
+}
+
bool InstallUtil::BuildDLLRegistrationList(const std::wstring& install_path,
const wchar_t** const dll_names,
int dll_names_count,
diff --git a/chrome/installer/util/install_util.h b/chrome/installer/util/install_util.h
index f1f07c4..8a2854a 100644
--- a/chrome/installer/util/install_util.h
+++ b/chrome/installer/util/install_util.h
@@ -66,6 +66,11 @@ class InstallUtil {
// by either --chrome-sxs or the executable path).
static bool IsChromeSxSProcess();
+ // Returns true if this setup process is running as an install managed by an
+ // MSI wrapper. This is indicated by the presence of --msi on the command line
+ // or the presence of "msi": true in the master preferences file.
+ static bool IsMSIProcess();
+
// Adds all DLLs in install_path whose names are given by dll_names to a
// work item list containing registration or unregistration actions.
//
diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc
index 3cebf4b..2a6a4e7 100644
--- a/chrome/installer/util/master_preferences.cc
+++ b/chrome/installer/util/master_preferences.cc
@@ -8,8 +8,10 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/common/json_value_serializer.h"
+#include "chrome/installer/util/util_constants.h"
#include "googleurl/src/gurl.h"
+
namespace {
const wchar_t* kDistroDict = L"distribution";
@@ -46,30 +48,6 @@ std::vector<GURL> GetNamedList(const wchar_t* name,
}
namespace installer_util {
-namespace master_preferences {
-const wchar_t kAltFirstRunBubble[] = L"oem_bubble";
-const wchar_t kAltShortcutText[] = L"alternate_shortcut_text";
-const wchar_t kChromeShortcutIconIndex[] = L"chrome_shortcut_icon_index";
-const wchar_t kCreateAllShortcuts[] = L"create_all_shortcuts";
-const wchar_t kDistroImportBookmarksPref[] = L"import_bookmarks";
-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";
-const wchar_t kDistroShowWelcomePage[] = L"show_welcome_page";
-const wchar_t kDistroSkipFirstRunPref[] = L"skip_first_run_ui";
-const wchar_t kDoNotCreateShortcuts[] = L"do_not_create_shortcuts";
-const wchar_t kDoNotLaunchChrome[] = L"do_not_launch_chrome";
-const wchar_t kDoNotRegisterForUpdateLaunch[] =
- L"do_not_register_for_update_launch";
-const wchar_t kMakeChromeDefault[] = L"make_chrome_default";
-const wchar_t kMakeChromeDefaultForUser[] = L"make_chrome_default_for_user";
-const wchar_t kMsi[] = L"msi";
-const wchar_t kRequireEula[] = L"require_eula";
-const wchar_t kSystemLevel[] = L"system_level";
-const wchar_t kVerboseLogging[] = L"verbose_logging";
-const wchar_t kExtensionsBlock[] = L"extensions.settings";
-}
bool GetDistroBooleanPreference(const DictionaryValue* prefs,
const std::wstring& name,
@@ -103,6 +81,61 @@ bool GetDistroIntegerPreference(const DictionaryValue* prefs,
return true;
}
+DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line) {
+ DictionaryValue* prefs = NULL;
+#if defined(OS_WIN)
+ if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) {
+ FilePath prefs_path(
+ cmd_line.GetSwitchValue(installer_util::switches::kInstallerData));
+ prefs = installer_util::ParseDistributionPreferences(prefs_path);
+ }
+
+ if (!prefs)
+ prefs = new DictionaryValue();
+
+ if (cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kCreateAllShortcuts, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kDoNotCreateShortcuts))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kDoNotCreateShortcuts, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kMsi))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kMsi, true);
+
+ if (cmd_line.HasSwitch(
+ installer_util::switches::kDoNotRegisterForUpdateLaunch))
+ installer_util::SetDistroBooleanPreference(
+ prefs,
+ installer_util::master_preferences::kDoNotRegisterForUpdateLaunch,
+ true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kDoNotLaunchChrome))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kDoNotLaunchChrome, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kMakeChromeDefault, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kSystemLevel))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kSystemLevel, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kVerboseLogging))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kVerboseLogging, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kAltDesktopShortcut))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kAltShortcutText, true);
+#endif
+
+ return prefs;
+}
+
DictionaryValue* ParseDistributionPreferences(
const FilePath& master_prefs_path) {
if (!file_util::PathExists(master_prefs_path)) {
@@ -113,6 +146,7 @@ DictionaryValue* ParseDistributionPreferences(
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));
diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h
index a6da339..e244e96 100644
--- a/chrome/installer/util/master_preferences.h
+++ b/chrome/installer/util/master_preferences.h
@@ -10,67 +10,23 @@
#include <vector>
+#include "base/command_line.h"
#include "base/file_path.h"
#include "base/values.h"
#include "googleurl/src/gurl.h"
+#include "chrome/installer/util/master_preferences_constants.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[];
-// Integer. Icon index from chrome.exe to use for shortcuts.
-extern const wchar_t kChromeShortcutIconIndex[];
-// 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 create Chrome desktop shortcuts. Cmd line override present.
-extern const wchar_t kDoNotCreateShortcuts[];
-// Boolean. Do not launch Chrome after first install. Cmd line override present.
-extern const wchar_t kDoNotLaunchChrome[];
-// Boolean. Do not register with Google Update to have Chrome launched after
-// install. Cmd line override present.
-extern const wchar_t kDoNotRegisterForUpdateLaunch[];
-// 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. Expect to be run by an MSI installer. Cmd line override present.
-extern const wchar_t kMsi[];
-// 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[];
-// Name of the block that contains the extensions on the master preferences.
-extern const wchar_t kExtensionsBlock[];
-}
-
// This is the default name for the master preferences file used to pre-set
// values in the user profile at first run.
const char kDefaultMasterPrefs[] = "master_preferences";
+// Parse command line and read master preferences, if present, to get
+// distribution related install options. Merge them if any command line
+// options present (command line value takes precedence).
+DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line);
+
// Gets the value of given boolean preference |name| from |prefs| dictionary
// which is assumed to contain a dictionary named "distribution". Returns
// true if the value is read successfully, otherwise false.
diff --git a/chrome/installer/util/master_preferences_constants.cc b/chrome/installer/util/master_preferences_constants.cc
new file mode 100644
index 0000000..6519e4c
--- /dev/null
+++ b/chrome/installer/util/master_preferences_constants.cc
@@ -0,0 +1,32 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/installer/util/master_preferences_constants.h"
+
+namespace installer_util {
+namespace master_preferences {
+ const wchar_t kAltFirstRunBubble[] = L"oem_bubble";
+ const wchar_t kAltShortcutText[] = L"alternate_shortcut_text";
+ const wchar_t kChromeShortcutIconIndex[] = L"chrome_shortcut_icon_index";
+ const wchar_t kCreateAllShortcuts[] = L"create_all_shortcuts";
+ const wchar_t kDistroImportBookmarksPref[] = L"import_bookmarks";
+ 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";
+ const wchar_t kDistroShowWelcomePage[] = L"show_welcome_page";
+ const wchar_t kDistroSkipFirstRunPref[] = L"skip_first_run_ui";
+ const wchar_t kDoNotCreateShortcuts[] = L"do_not_create_shortcuts";
+ const wchar_t kDoNotLaunchChrome[] = L"do_not_launch_chrome";
+ const wchar_t kDoNotRegisterForUpdateLaunch[] =
+ L"do_not_register_for_update_launch";
+ const wchar_t kMakeChromeDefault[] = L"make_chrome_default";
+ const wchar_t kMakeChromeDefaultForUser[] = L"make_chrome_default_for_user";
+ const wchar_t kMsi[] = L"msi";
+ const wchar_t kRequireEula[] = L"require_eula";
+ const wchar_t kSystemLevel[] = L"system_level";
+ const wchar_t kVerboseLogging[] = L"verbose_logging";
+ const wchar_t kExtensionsBlock[] = L"extensions.settings";
+}
+}
diff --git a/chrome/installer/util/master_preferences_constants.h b/chrome/installer/util/master_preferences_constants.h
new file mode 100644
index 0000000..5bcd5d3
--- /dev/null
+++ b/chrome/installer/util/master_preferences_constants.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This file contains the constants used to process master_preferences files
+// used by setup and first run.
+
+#ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_CONSTANTS_H_
+#define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_CONSTANTS_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[];
+// Integer. Icon index from chrome.exe to use for shortcuts.
+extern const wchar_t kChromeShortcutIconIndex[];
+// 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 create Chrome desktop shortcuts. Cmd line override present.
+extern const wchar_t kDoNotCreateShortcuts[];
+// Boolean. Do not launch Chrome after first install. Cmd line override present.
+extern const wchar_t kDoNotLaunchChrome[];
+// Boolean. Do not register with Google Update to have Chrome launched after
+// install. Cmd line override present.
+extern const wchar_t kDoNotRegisterForUpdateLaunch[];
+// 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. Expect to be run by an MSI installer. Cmd line override present.
+extern const wchar_t kMsi[];
+// 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[];
+// Name of the block that contains the extensions on the master preferences.
+extern const wchar_t kExtensionsBlock[];
+}
+}
+
+#endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_CONSTANTS_H_
diff --git a/chrome/installer/util/master_preferences_dummy.cc b/chrome/installer/util/master_preferences_dummy.cc
new file mode 100644
index 0000000..9abd037
--- /dev/null
+++ b/chrome/installer/util/master_preferences_dummy.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This file defines dummy implementation of several functions from the
+// master_preferences namespace for Google Chrome. These functions allow 64-bit
+// Windows Chrome binary to build successfully. Since this binary is only used
+// for Native Client support which uses the 32 bit installer, most of the
+// master preferences functionality is not actually needed.
+
+#include "chrome/installer/util/master_preferences.h"
+
+#include <windows.h>
+
+#include "base/logging.h"
+#include "googleurl/src/gurl.h"
+
+namespace installer_util {
+
+bool GetDistroBooleanPreference(const DictionaryValue* prefs,
+ const std::wstring& name,
+ bool* value) {
+ NOTREACHED();
+ return false;
+}
+
+bool GetDistroIntegerPreference(const DictionaryValue* prefs,
+ const std::wstring& name,
+ int* value) {
+ NOTREACHED();
+ return false;
+}
+
+DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line) {
+ NOTREACHED();
+ return NULL;
+}
+
+DictionaryValue* ParseDistributionPreferences(
+ const FilePath& master_prefs_path) {
+ NOTREACHED();
+ return NULL;
+}
+
+std::vector<GURL> GetFirstRunTabs(const DictionaryValue* prefs) {
+ NOTREACHED();
+ return std::vector<GURL>();
+}
+
+std::vector<GURL> GetDefaultBookmarks(const DictionaryValue* prefs) {
+ NOTREACHED();
+ return std::vector<GURL>();
+}
+
+bool SetDistroBooleanPreference(DictionaryValue* prefs,
+ const std::wstring& name,
+ bool value) {
+ NOTREACHED();
+ return false;
+}
+
+bool HasExtensionsBlock(const DictionaryValue* prefs,
+ DictionaryValue** extensions) {
+ NOTREACHED();
+ return false;
+}
+
+}
diff --git a/chrome/installer/util/master_preferences_unittest.cc b/chrome/installer/util/master_preferences_unittest.cc
index 3b7550a..65fcc6d 100644
--- a/chrome/installer/util/master_preferences_unittest.cc
+++ b/chrome/installer/util/master_preferences_unittest.cc
@@ -243,3 +243,81 @@ TEST(MasterPrefsExtension, ValidateExtensionJSON) {
EXPECT_TRUE(extensions->GetString(
L"behllobkkfkfnphdnhnkndlbkcpglgmj.manifest.version", &version));
}
+
+// Test that we are parsing master preferences correctly.
+TEST_F(MasterPreferencesTest, GetInstallPreferencesTest) {
+ // Create a temporary prefs file.
+ FilePath prefs_file;
+ ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file));
+ const char text[] =
+ "{ \n"
+ " \"distribution\": { \n"
+ " \"skip_first_run_ui\": true,\n"
+ " \"create_all_shortcuts\": false,\n"
+ " \"do_not_launch_chrome\": true,\n"
+ " \"system_level\": true,\n"
+ " \"verbose_logging\": false\n"
+ " }\n"
+ "} \n";
+ EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+
+ // Make sure command line values override the values in master preferences.
+ std::wstring cmd_str(
+ L"setup.exe --installerdata=\"" + prefs_file.value() + L"\"");
+ cmd_str.append(L" --create-all-shortcuts");
+ cmd_str.append(L" --do-not-launch-chrome");
+ cmd_str.append(L" --alt-desktop-shortcut");
+ CommandLine cmd_line = CommandLine::FromString(cmd_str);
+ scoped_ptr<DictionaryValue> prefs(
+ installer_util::GetInstallPreferences(cmd_line));
+ EXPECT_TRUE(prefs.get() != NULL);
+
+ // Check prefs that do not have any equivalent command line option.
+ bool value = false;
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroSkipFirstRunPref, &value) &&
+ value);
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroShowWelcomePage, &value));
+
+ // Now check that prefs got merged correctly.
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kCreateAllShortcuts, &value) &&
+ value);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDoNotLaunchChrome, &value) &&
+ value);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kAltShortcutText, &value) &&
+ value);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kSystemLevel, &value) &&
+ value);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kVerboseLogging, &value));
+ EXPECT_FALSE(value);
+
+ // Delete temporary prefs file.
+ EXPECT_TRUE(file_util::Delete(prefs_file, false));
+
+ // Check that if master prefs doesn't exist, we can still parse the common
+ // prefs.
+ cmd_str = L"setup.exe --create-all-shortcuts --do-not-launch-chrome"
+ L" --alt-desktop-shortcut";
+ cmd_line.ParseFromString(cmd_str);
+ prefs.reset(installer_util::GetInstallPreferences(cmd_line));
+ EXPECT_TRUE(prefs.get() != NULL);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kCreateAllShortcuts, &value) &&
+ value);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDoNotLaunchChrome, &value) &&
+ value);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kAltShortcutText, &value) &&
+ value);
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kSystemLevel, &value));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kVerboseLogging, &value));
+}
diff --git a/chrome/installer/util/util_constants.cc b/chrome/installer/util/util_constants.cc
index 261863d..5980992 100644
--- a/chrome/installer/util/util_constants.cc
+++ b/chrome/installer/util/util_constants.cc
@@ -132,6 +132,7 @@ const wchar_t kInstallerDir[] = L"Installer";
const wchar_t kSxSSuffix[] = L" SxS";
const wchar_t kUninstallStringField[] = L"UninstallString";
+const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
const wchar_t kUninstallDisplayNameField[] = L"DisplayName";
const wchar_t kUninstallMetricsName[] = L"uninstall_metrics";
const wchar_t kUninstallInstallationDate[] = L"installation_date";
diff --git a/chrome/installer/util/util_constants.h b/chrome/installer/util/util_constants.h
index 7c0db12..1b8207e 100644
--- a/chrome/installer/util/util_constants.h
+++ b/chrome/installer/util/util_constants.h
@@ -98,6 +98,7 @@ extern const wchar_t kInstallerDir[];
extern const wchar_t kSxSSuffix[];
extern const wchar_t kUninstallStringField[];
+extern const wchar_t kUninstallArgumentsField[];
extern const wchar_t kUninstallDisplayNameField[];
extern const wchar_t kUninstallMetricsName[];
extern const wchar_t kUninstallInstallationDate[];