summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run.cc
diff options
context:
space:
mode:
authorhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-04 22:23:17 +0000
committerhuanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-04 22:23:17 +0000
commitcac407bd57b7f7b3f9d85e1951a07d68f8400d0a (patch)
tree60f20e4ef815964c4689f928134e645509c07249 /chrome/browser/first_run.cc
parent95ce68cc99b05ef26aa7b54bfb08a477960220aa (diff)
downloadchromium_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/browser/first_run.cc')
-rw-r--r--chrome/browser/first_run.cc78
1 files changed, 23 insertions, 55 deletions
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index 51cc1f8..ece99a5 100644
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -26,8 +26,8 @@
#include "chrome/browser/views/first_run_view.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
-#include "chrome/common/json_value_serializer.h"
#include "chrome/common/pref_service.h"
+#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/shell_util.h"
#include "chrome/views/accelerator_handler.h"
#include "chrome/views/window.h"
@@ -41,19 +41,6 @@ const wchar_t kSentinelFile[] = L"First Run";
const wchar_t kChromeUpgradeExe[] = L"new_chrome.exe";
const wchar_t kChromeBackupExe[] = L"old_chrome.exe";
-// 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 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";
-// Boolean pref that triggers loading the welcome page.
-const wchar_t kDistroShowWelcomePage[] = L"distribution.show_welcome_page";
-
// Gives the full path to the sentinel file. The file might not exist.
bool GetFirstRunSentinelFilePath(std::wstring* path) {
std::wstring first_run_sentinel;
@@ -91,24 +78,6 @@ std::wstring GetDefaultPrefFilePath(bool create_profile_dir,
return ProfileManager::GetDefaultProfilePath(default_pref_dir);
}
-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
bool FirstRun::IsChromeFirstRun() {
@@ -159,53 +128,54 @@ bool FirstRun::CreateSentinel() {
return true;
}
-FirstRun::MasterPrefResult FirstRun::ProcessMasterPreferences(
- const std::wstring& user_data_dir,
- const std::wstring& master_prefs_path) {
+bool FirstRun::ProcessMasterPreferences(
+ const std::wstring& user_data_dir,
+ const std::wstring& master_prefs_path,
+ int* preference_details) {
DCHECK(!user_data_dir.empty());
+ if (preference_details)
+ *preference_details = 0;
+
std::wstring master_prefs;
if (master_prefs_path.empty()) {
// The default location of the master prefs is next to the chrome exe.
std::wstring master_path;
if (!PathService::Get(base::DIR_EXE, &master_path))
- return MASTER_PROFILE_ERROR;
- file_util::AppendToPath(&master_path, kDefaultMasterPrefs);
+ return true;
+ file_util::AppendToPath(&master_path, installer_util::kDefaultMasterPrefs);
master_prefs = master_path;
} else {
master_prefs = master_prefs_path;
}
- std::string json_data;
- if (!file_util::ReadFileToString(master_prefs, &json_data))
- return MASTER_PROFILE_NOT_FOUND;
+ int parse_result = installer_util::ParseDistributionPreferences(master_prefs);
+ if (preference_details)
+ *preference_details = parse_result;
- LOG(INFO) << "master profile found";
+ if (parse_result & installer_util::MASTER_PROFILE_ERROR)
+ return true;
std::wstring user_prefs = GetDefaultPrefFilePath(true, user_data_dir);
if (user_prefs.empty())
- return MASTER_PROFILE_ERROR;
-
- scoped_ptr<DictionaryValue> json_root(ReadJSONPrefs(json_data));
- if (!json_root.get())
- return MASTER_PROFILE_ERROR;
+ return true;
// The master prefs are regular prefs so we can just copy the file
// to the default place and they just work.
if (!file_util::CopyFile(master_prefs, user_prefs))
- return MASTER_PROFILE_ERROR;
+ return true;
- if (!GetBooleanPref(json_root.get(), kDistroSkipFirstRunPref))
- return MASTER_PROFILE_DO_FIRST_RUN_UI;
+ if (!(parse_result & installer_util::MASTER_PROFILE_NO_FIRST_RUN_UI))
+ return true;
FirstRun::SetShowFirstRunBubblePref();
- if (GetBooleanPref(json_root.get(), kDistroShowWelcomePage))
+ if (parse_result & installer_util::MASTER_PROFILE_SHOW_WELCOME)
FirstRun::SetShowWelcomePagePref();
int import_items = 0;
- if (GetBooleanPref(json_root.get(), kDistroImportSearchPref))
+ if (parse_result & installer_util::MASTER_PROFILE_IMPORT_SEARCH_ENGINE)
import_items += SEARCH_ENGINES;
- if (GetBooleanPref(json_root.get(), kDistroImportHistoryPref))
+ if (parse_result & installer_util::MASTER_PROFILE_IMPORT_HISTORY)
import_items += HISTORY;
if (import_items) {
@@ -215,7 +185,7 @@ FirstRun::MasterPrefResult FirstRun::ProcessMasterPreferences(
LOG(WARNING) << "silent import failed";
}
}
- return MASTER_PROFILE_NO_FIRST_RUN_UI;
+ return false;
}
bool Upgrade::SwapNewChromeExeIfPresent() {
@@ -493,5 +463,3 @@ bool FirstRun::SetShowWelcomePagePref() {
}
return true;
}
-
-