summaryrefslogtreecommitdiffstats
path: root/chrome/installer/util
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 21:58:12 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-31 21:58:12 +0000
commitd23c9b7b8ddf903fee60da371c902a3fec8f66e7 (patch)
treeebfe1a887d6e7195676f159ef4f2f0ce2077bc9d /chrome/installer/util
parentcec4a2709d524929d1da9a0ad806644274e36b12 (diff)
downloadchromium_src-d23c9b7b8ddf903fee60da371c902a3fec8f66e7.zip
chromium_src-d23c9b7b8ddf903fee60da371c902a3fec8f66e7.tar.gz
chromium_src-d23c9b7b8ddf903fee60da371c902a3fec8f66e7.tar.bz2
Refactoring of master preferences parsing before adding a new preference.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22198 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/util')
-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/master_preferences.cc126
-rw-r--r--chrome/installer/util/master_preferences.h103
-rw-r--r--chrome/installer/util/util_constants.h25
7 files changed, 100 insertions, 162 deletions
diff --git a/chrome/installer/util/browser_distribution.cc b/chrome/installer/util/browser_distribution.cc
index ad31cba..25555ac 100644
--- a/chrome/installer/util/browser_distribution.cc
+++ b/chrome/installer/util/browser_distribution.cc
@@ -88,7 +88,7 @@ void BrowserDistribution::UpdateDiffInstallStatus(bool system_install,
void BrowserDistribution::LaunchUserExperiment(
installer_util::InstallStatus status, const installer::Version& version,
- bool system_install, int options) {
+ bool system_install) {
}
diff --git a/chrome/installer/util/browser_distribution.h b/chrome/installer/util/browser_distribution.h
index 26f9b3b..452b8a2 100644
--- a/chrome/installer/util/browser_distribution.h
+++ b/chrome/installer/util/browser_distribution.h
@@ -58,7 +58,7 @@ class BrowserDistribution {
// sets the wheels in motion or in simple cases does the experiment itself.
virtual void LaunchUserExperiment(installer_util::InstallStatus status,
const installer::Version& version,
- bool system_install, int options);
+ bool system_install);
// The user has qualified for the inactive user toast experiment and this
// function just performs it.
diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc
index 9f8995e..3c60e06 100644
--- a/chrome/installer/util/google_chrome_distribution.cc
+++ b/chrome/installer/util/google_chrome_distribution.cc
@@ -407,7 +407,7 @@ void GoogleChromeDistribution::UpdateDiffInstallStatus(bool system_install,
// applies for users doing upgrades and non-systemwide install.
void GoogleChromeDistribution::LaunchUserExperiment(
installer_util::InstallStatus status, const installer::Version& version,
- bool system_install, int options) {
+ bool system_install) {
if ((installer_util::NEW_VERSION_UPDATED != status) || system_install)
return;
diff --git a/chrome/installer/util/google_chrome_distribution.h b/chrome/installer/util/google_chrome_distribution.h
index f4b5016..aa2c99f 100644
--- a/chrome/installer/util/google_chrome_distribution.h
+++ b/chrome/installer/util/google_chrome_distribution.h
@@ -80,7 +80,7 @@ class GoogleChromeDistribution : public BrowserDistribution {
virtual void LaunchUserExperiment(installer_util::InstallStatus status,
const installer::Version& version,
- bool system_install, int options);
+ bool system_install);
// Assuming that the user qualifies, this function performs the inactive user
// toast experiment. It will use chrome to show the UI and it will record the
diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc
index 8a7c637..eb62aa5 100644
--- a/chrome/installer/util/master_preferences.cc
+++ b/chrome/installer/util/master_preferences.cc
@@ -10,37 +10,26 @@
#include "chrome/common/json_value_serializer.h"
namespace {
+DictionaryValue* GetPrefsFromFile(const FilePath& master_prefs_path) {
+ std::string json_data;
+ if (!file_util::ReadFileToString(master_prefs_path, &json_data))
+ return NULL;
-DictionaryValue* ReadJSONPrefs(const std::string& data) {
- JSONStringValueSerializer json(data);
+ JSONStringValueSerializer json(json_data);
scoped_ptr<Value> root(json.Deserialize(NULL));
+
if (!root.get())
return NULL;
+
if (!root->IsType(Value::TYPE_DICTIONARY))
return NULL;
return static_cast<DictionaryValue*>(root.release());
}
-
-DictionaryValue* GetPrefsFromFile(const std::wstring& master_prefs_path) {
- std::string json_data;
- if (!file_util::ReadFileToString(master_prefs_path, &json_data))
- return NULL;
- return ReadJSONPrefs(json_data);
-}
-
-bool GetBooleanPref(const DictionaryValue* prefs, const std::wstring& name) {
- bool value = false;
- prefs->GetBoolean(name, &value);
- return value;
-}
-
} // namespace
namespace installer_util {
-// All the preferences below are expected to be inside the JSON "distribution"
-// block. See master_preferences.h for an example.
-
+namespace master_preferences {
// Boolean pref that triggers skipping the first run dialogs.
const wchar_t kDistroSkipFirstRunPref[] = L"skip_first_run_ui";
// Boolean pref that triggers loading the welcome page.
@@ -77,88 +66,61 @@ const wchar_t kAltFirstRunBubble[] = L"oem_bubble";
// Boolean pref that triggers silent import of the default browser homepage.
const wchar_t kDistroImportHomePagePref[] = L"import_home_page";
-bool GetDistributionPingDelay(const FilePath& master_prefs_path,
- int& delay) {
- // 90 seconds is the default that we want to use in case master preferences
- // is missing or corrupt.
- delay = 90;
- FilePath master_prefs = master_prefs_path;
- if (master_prefs.empty()) {
- if (!PathService::Get(base::DIR_EXE, &master_prefs))
- return false;
- master_prefs = master_prefs.Append(installer_util::kDefaultMasterPrefs);
- }
+const wchar_t kMasterPreferencesValid[] = L"master_preferencs_valid";
+}
- if (!file_util::PathExists(master_prefs))
- return false;
+bool GetBooleanPreference(const DictionaryValue* prefs,
+ const std::wstring& name) {
+ bool value = false;
+ if (!prefs || !prefs->GetBoolean(name, &value))
+ return false;
+ return value;
+}
- scoped_ptr<DictionaryValue> json_root(
- GetPrefsFromFile(master_prefs.ToWStringHack()));
- if (!json_root.get())
+bool GetDistributionPingDelay(const DictionaryValue* prefs,
+ int* ping_delay) {
+ if (!prefs || !ping_delay)
return false;
- DictionaryValue* distro = NULL;
- if (!json_root->GetDictionary(L"distribution", &distro) ||
- !distro->GetInteger(kDistroPingDelay, &delay))
+ // 90 seconds is the default that we want to use in case master preferences
+ // is missing or corrupt.
+ *ping_delay = 90;
+ if (!prefs->GetInteger(master_preferences::kDistroPingDelay, ping_delay))
return false;
return true;
}
-int ParseDistributionPreferences(const std::wstring& master_prefs_path) {
- if (!file_util::PathExists(master_prefs_path))
- return MASTER_PROFILE_NOT_FOUND;
- LOG(INFO) << "master profile found";
+DictionaryValue* ParseDistributionPreferences(
+ const FilePath& master_prefs_path) {
+ if (!file_util::PathExists(master_prefs_path)) {
+ LOG(WARNING) << "Master preferences file not found: "
+ << master_prefs_path.value();
+ return NULL;
+ }
scoped_ptr<DictionaryValue> json_root(GetPrefsFromFile(master_prefs_path));
- if (!json_root.get())
- return MASTER_PROFILE_ERROR;
+ if (!json_root.get()) {
+ LOG(WARNING) << "Failed to parse preferences file: "
+ << master_prefs_path.value();
+ return NULL;
+ }
- int parse_result = 0;
DictionaryValue* distro = NULL;
- if (json_root->GetDictionary(L"distribution", &distro)) {
- if (GetBooleanPref(distro, kDistroSkipFirstRunPref))
- parse_result |= MASTER_PROFILE_NO_FIRST_RUN_UI;
- if (GetBooleanPref(distro, kDistroShowWelcomePage))
- parse_result |= MASTER_PROFILE_SHOW_WELCOME;
- if (GetBooleanPref(distro, kDistroImportSearchPref))
- parse_result |= MASTER_PROFILE_IMPORT_SEARCH_ENGINE;
- if (GetBooleanPref(distro, kDistroImportHistoryPref))
- parse_result |= MASTER_PROFILE_IMPORT_HISTORY;
- if (GetBooleanPref(distro, kDistroImportBookmarksPref))
- parse_result |= MASTER_PROFILE_IMPORT_BOOKMARKS;
- if (GetBooleanPref(distro, kDistroImportHomePagePref))
- parse_result |= MASTER_PROFILE_IMPORT_HOME_PAGE;
- if (GetBooleanPref(distro, kMakeChromeDefaultForUser))
- parse_result |= MASTER_PROFILE_MAKE_CHROME_DEFAULT_FOR_USER;
- if (GetBooleanPref(distro, kCreateAllShortcuts))
- parse_result |= MASTER_PROFILE_CREATE_ALL_SHORTCUTS;
- if (GetBooleanPref(distro, kDoNotLaunchChrome))
- parse_result |= MASTER_PROFILE_DO_NOT_LAUNCH_CHROME;
- if (GetBooleanPref(distro, kMakeChromeDefault))
- parse_result |= MASTER_PROFILE_MAKE_CHROME_DEFAULT;
- if (GetBooleanPref(distro, kSystemLevel))
- parse_result |= MASTER_PROFILE_SYSTEM_LEVEL;
- if (GetBooleanPref(distro, kVerboseLogging))
- parse_result |= MASTER_PROFILE_VERBOSE_LOGGING;
- if (GetBooleanPref(distro, kRequireEula))
- parse_result |= MASTER_PROFILE_REQUIRE_EULA;
- if (GetBooleanPref(distro, kAltShortcutText))
- parse_result |= MASTER_PROFILE_ALT_SHORTCUT_TXT;
- if (GetBooleanPref(distro, kAltFirstRunBubble))
- parse_result |= MASTER_PROFILE_OEM_FIRST_RUN_BUBBLE;
+ if (!json_root->GetDictionary(L"distribution", &distro)) {
+ LOG(WARNING) << "Failed to get distriubtion params: "
+ << master_prefs_path.value();
+ return NULL;
}
- return parse_result;
+ return distro;
}
-std::vector<std::wstring> ParseFirstRunTabs(
- const std::wstring& master_prefs_path) {
+std::vector<std::wstring> ParseFirstRunTabs(const DictionaryValue* prefs) {
std::vector<std::wstring> launch_tabs;
- scoped_ptr<DictionaryValue> json_root(GetPrefsFromFile(master_prefs_path));
- if (!json_root.get())
+ if (!prefs)
return launch_tabs;
ListValue* tabs_list = NULL;
- if (!json_root->GetList(L"first_run_tabs", &tabs_list))
+ if (!prefs->GetList(L"first_run_tabs", &tabs_list))
return launch_tabs;
for (size_t i = 0; i < tabs_list->GetSize(); ++i) {
Value* entry;
diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h
index 856d53e..103605a 100644
--- a/chrome/installer/util/master_preferences.h
+++ b/chrome/installer/util/master_preferences.h
@@ -8,64 +8,65 @@
#ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_
#define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_
-#include <string>
-#include <vector>
-
-#include "base/file_util.h"
+#include "base/file_path.h"
+#include "base/values.h"
namespace installer_util {
+namespace master_preferences {
+// All the preferences below are expected to be inside the JSON "distribution"
+// block.
+
+// Boolean pref that triggers skipping the first run dialogs.
+extern const wchar_t kDistroSkipFirstRunPref[];
+// Boolean pref that triggers loading the welcome page.
+extern const wchar_t kDistroShowWelcomePage[];
+// Boolean pref that triggers silent import of the default search engine.
+extern const wchar_t kDistroImportSearchPref[];
+// Boolean pref that triggers silent import of the default browser history.
+extern const wchar_t kDistroImportHistoryPref[];
+// Boolean pref that triggers silent import of the default browser bookmarks.
+extern const wchar_t kDistroImportBookmarksPref[];
+// RLZ ping delay in seconds
+extern const wchar_t kDistroPingDelay[];
+// Register Chrome as default browser for the current user.
+extern const wchar_t kMakeChromeDefaultForUser[];
+// The following boolean prefs have the same semantics as the corresponding
+// setup command line switches. See chrome/installer/util/util_constants.cc
+// for more info.
+// Create Desktop and QuickLaunch shortcuts.
+extern const wchar_t kCreateAllShortcuts[];
+// Prevent installer from launching Chrome after a successful first install.
+extern const wchar_t kDoNotLaunchChrome[];
+// Register Chrome as default browser on the system.
+extern const wchar_t kMakeChromeDefault[];
+// Install Chrome to system wise location.
+extern const wchar_t kSystemLevel[];
+// Run installer in verbose mode.
+extern const wchar_t kVerboseLogging[];
+// Show EULA dialog and install only if accepted.
+extern const wchar_t kRequireEula[];
+// Use alternate shortcut text for the main shortcut.
+extern const wchar_t kAltShortcutText[];
+// Use alternate smaller first run info bubble.
+extern const wchar_t kAltFirstRunBubble[];
+// Boolean pref that triggers silent import of the default browser homepage.
+extern const wchar_t kDistroImportHomePagePref[];
+
+extern const wchar_t kMasterPreferencesValid[];
+}
+
// This is the default name for the master preferences file used to pre-set
// values in the user profile at first run.
const wchar_t kDefaultMasterPrefs[] = L"master_preferences";
-// These are the possible results of calling ParseDistributionPreferences.
-// Some of the results can be combined, so they are bit flags.
-enum MasterPrefResult {
- MASTER_PROFILE_NOT_FOUND = 0x1,
- // A critical error processing the master profile.
- MASTER_PROFILE_ERROR = 0x1 << 1,
- // Skip first run dialogs.
- MASTER_PROFILE_NO_FIRST_RUN_UI = 0x1 << 2,
- // Show welcome page.
- MASTER_PROFILE_SHOW_WELCOME = 0x1 << 3,
- // Import search engine setting from the default browser.
- MASTER_PROFILE_IMPORT_SEARCH_ENGINE = 0x1 << 4,
- // Import history from the default browser.
- MASTER_PROFILE_IMPORT_HISTORY = 0x1 << 5,
- // Import bookmarks from the default browser.
- MASTER_PROFILE_IMPORT_BOOKMARKS = 0x1 << 6,
- // Register Chrome as default browser for the current user. This option is
- // different than MAKE_CHROME_DEFAULT as installer ignores this option and
- // Chrome on first run makes itself default.
- MASTER_PROFILE_MAKE_CHROME_DEFAULT_FOR_USER = 0x1 << 7,
- // The following boolean prefs have the same semantics as the corresponding
- // setup command line switches. See chrome/installer/util/util_constants.cc
- // for more info.
- // Create Desktop and QuickLaunch shortcuts.
- MASTER_PROFILE_CREATE_ALL_SHORTCUTS = 0x1 << 8,
- // Prevent installer from launching Chrome after a successful first install.
- MASTER_PROFILE_DO_NOT_LAUNCH_CHROME = 0x1 << 9,
- // Register Chrome as default browser on the system.
- MASTER_PROFILE_MAKE_CHROME_DEFAULT = 0x1 << 10,
- // Install Chrome to system wise location.
- MASTER_PROFILE_SYSTEM_LEVEL = 0x1 << 11,
- // Run installer in verbose mode.
- MASTER_PROFILE_VERBOSE_LOGGING = 0x1 << 12,
- // Show the EULA and do not install if not accepted.
- MASTER_PROFILE_REQUIRE_EULA = 0x1 << 13,
- // Use an alternate description text for some shortcuts.
- MASTER_PROFILE_ALT_SHORTCUT_TXT = 0x1 << 14,
- // Use a smaller OEM info bubble on first run.
- MASTER_PROFILE_OEM_FIRST_RUN_BUBBLE = 0x1 << 15,
- // Import home page from the default browser.
- MASTER_PROFILE_IMPORT_HOME_PAGE = 0x1 << 16
-};
+bool GetBooleanPreference(const DictionaryValue* prefs,
+ const std::wstring& name);
// This function gets ping delay (ping_delay in the sample above) from master
// preferences.
-bool GetDistributionPingDelay(const FilePath& master_prefs_path,
- int& delay);
+bool GetDistributionPingDelay(const DictionaryValue* prefs,
+ int* ping_delay);
// The master preferences is a JSON file with the same entries as the
// 'Default\Preferences' file. This function parses the distribution
@@ -109,7 +110,8 @@ bool GetDistributionPingDelay(const FilePath& master_prefs_path,
// installation properties. This entry will be ignored at other times.
// This function parses the 'distribution' entry and returns a combination
// of MasterPrefResult.
-int ParseDistributionPreferences(const std::wstring& master_prefs_path);
+DictionaryValue* ParseDistributionPreferences(
+ const FilePath& master_prefs_path);
// As part of the master preferences an optional section indicates the tabs
// to open during first run. An example is the following:
@@ -125,8 +127,7 @@ int ParseDistributionPreferences(const std::wstring& master_prefs_path);
//
// This function retuns the list as a vector of strings. If the master
// preferences file does not contain such list the vector is empty.
-std::vector<std::wstring> ParseFirstRunTabs(
- const std::wstring& master_prefs_path);
+std::vector<std::wstring> ParseFirstRunTabs(const DictionaryValue* prefs);
}
#endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H_
diff --git a/chrome/installer/util/util_constants.h b/chrome/installer/util/util_constants.h
index 5256d6a..4e209b2 100644
--- a/chrome/installer/util/util_constants.h
+++ b/chrome/installer/util/util_constants.h
@@ -42,31 +42,6 @@ enum InstallStatus {
INSTALL_DIR_IN_USE // Installation directory is in use by another process
};
-// These are distribution related install options specified through command
-// line switches (see below) or master preference file (see
-// chrome/installer/util/master_preference.h). The options can be combined,
-// so they are bit flags.
-enum InstallOption {
- // A master profile file is provided to installer.
- MASTER_PROFILE_PRESENT = 0x1,
- // The master profile file provided is valid.
- MASTER_PROFILE_VALID = 0x1 << 1,
- // Create Desktop and QuickLaunch shortcuts.
- CREATE_ALL_SHORTCUTS = 0x1 << 2,
- // Prevent installer from launching Chrome after a successful first install.
- DO_NOT_LAUNCH_CHROME = 0x1 << 3,
- // Register Chrome as default browser on the system.
- MAKE_CHROME_DEFAULT = 0x1 << 4,
- // Install Chrome to system wise location.
- SYSTEM_LEVEL = 0x1 << 5,
- // Run installer in verbose mode.
- VERBOSE_LOGGING = 0x1 << 6,
- // Show the EULA dialog.
- SHOW_EULA_DIALOG = 0x1 << 7,
- // Use alternate dekstop shortcut text.
- ALT_DESKTOP_SHORTCUT = 0x1 << 8
-};
-
namespace switches {
extern const wchar_t kCreateAllShortcuts[];
extern const wchar_t kDeleteProfile[];