diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-04 22:23:17 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-04 22:23:17 +0000 |
commit | cac407bd57b7f7b3f9d85e1951a07d68f8400d0a (patch) | |
tree | 60f20e4ef815964c4689f928134e645509c07249 /chrome/installer | |
parent | 95ce68cc99b05ef26aa7b54bfb08a477960220aa (diff) | |
download | chromium_src-cac407bd57b7f7b3f9d85e1951a07d68f8400d0a.zip chromium_src-cac407bd57b7f7b3f9d85e1951a07d68f8400d0a.tar.gz chromium_src-cac407bd57b7f7b3f9d85e1951a07d68f8400d0a.tar.bz2 |
Refactoring master preference parsing code into installer util so
it can be shared by first run and set up. There is no functionality
change in this CL.
Review URL: http://codereview.chromium.org/9338
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4688 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 67 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.h | 75 | ||||
-rw-r--r-- | chrome/installer/util/util.vcproj | 8 |
3 files changed, 150 insertions, 0 deletions
diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc new file mode 100644 index 0000000..6b4102d --- /dev/null +++ b/chrome/installer/util/master_preferences.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2006-2008 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 "base/file_util.h" +#include "base/logging.h" +#include "chrome/common/json_value_serializer.h" +#include "chrome/installer/util/master_preferences.h" + +namespace { + +DictionaryValue* ReadJSONPrefs(const std::string& data) { + JSONStringValueSerializer json(data); + Value* root; + if (!json.Deserialize(&root)) + return NULL; + if (!root->IsType(Value::TYPE_DICTIONARY)) { + delete root; + return NULL; + } + return static_cast<DictionaryValue*>(root); +} + +bool GetBooleanPref(const DictionaryValue* prefs, const std::wstring& name) { + bool value = false; + prefs->GetBoolean(name, &value); + return value; +} + +} // namespace + +namespace installer_util { + +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"; + + std::string json_data; + if (!file_util::ReadFileToString(master_prefs_path, &json_data)) + return MASTER_PROFILE_ERROR; + + scoped_ptr<DictionaryValue> json_root(ReadJSONPrefs(json_data)); + if (!json_root.get()) + return MASTER_PROFILE_ERROR; + + int parse_result = 0; + + if (GetBooleanPref(json_root.get(), kDistroSkipFirstRunPref)) + parse_result |= MASTER_PROFILE_NO_FIRST_RUN_UI; + + if (GetBooleanPref(json_root.get(), kDistroShowWelcomePage)) + parse_result |= MASTER_PROFILE_SHOW_WELCOME; + + if (GetBooleanPref(json_root.get(), kDistroImportSearchPref)) + parse_result |= MASTER_PROFILE_IMPORT_SEARCH_ENGINE; + + if (GetBooleanPref(json_root.get(), kDistroImportHistoryPref)) + parse_result |= MASTER_PROFILE_IMPORT_HISTORY; + + return parse_result; +} + +} // installer_util diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h new file mode 100644 index 0000000..d7004cc --- /dev/null +++ b/chrome/installer/util/master_preferences.h @@ -0,0 +1,75 @@ +// Copyright (c) 2006-2008 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 functions processing master preference file used by +// setup and first run. + +#ifndef CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__ +#define CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__ + +#include <string> + +namespace installer_util { + +// 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"; + +// Boolean pref that triggers skipping the first run dialogs. +const wchar_t kDistroSkipFirstRunPref[] = L"distribution.skip_first_run_ui"; +// Boolean pref that triggers loading the welcome page. +const wchar_t kDistroShowWelcomePage[] = L"distribution.show_welcome_page"; +// Boolean pref that triggers silent import of the default search engine. +const wchar_t kDistroImportSearchPref[] = L"distribution.import_search_engine"; +// Boolean pref that triggers silent import of the browse history. +const wchar_t kDistroImportHistoryPref[] = L"distribution.import_history"; + +// 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, + // Improt search engine setting from the default browser. + MASTER_PROFILE_IMPORT_SEARCH_ENGINE = 0x1 << 4, + // Improt history from the default browser. + MASTER_PROFILE_IMPORT_HISTORY = 0x1 << 5, +}; + +// The master preferences is a JSON file with the same entries as the +// 'Default\Preferences' file. This function parses the distribution +// section of the preferences file. +// +// A prototypical 'master_preferences' file looks like this: +// +// { +// "distribution": { +// "skip_first_run_ui": true, +// "show_welcome_page": true, +// "import_search_engine": true, +// "import_history": false +// }, +// "browser": { +// "show_home_button": true +// }, +// "bookmark_bar": { +// "show_on_all_tabs": true +// }, +// "homepage": "http://example.org", +// "homepage_is_newtabpage": false +// } +// +// A reserved "distribution" entry in the file is used to group related +// 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); + +} + +#endif // CHROME_INSTALLER_UTIL_MASTER_PREFERENCES_H__ diff --git a/chrome/installer/util/util.vcproj b/chrome/installer/util/util.vcproj index c57ff78..284eb6a 100644 --- a/chrome/installer/util/util.vcproj +++ b/chrome/installer/util/util.vcproj @@ -145,6 +145,14 @@ > </File> <File + RelativePath=".\master_preferences.cc" + > + </File> + <File + RelativePath=".\master_preferences.h" + > + </File> + <File RelativePath="set_reg_value_work_item.cc" > </File> |