summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/browser_main.cc6
-rw-r--r--chrome/browser/first_run.cc78
-rw-r--r--chrome/browser/first_run.h50
-rw-r--r--chrome/installer/util/master_preferences.cc67
-rw-r--r--chrome/installer/util/master_preferences.h75
-rw-r--r--chrome/installer/util/util.vcproj8
6 files changed, 184 insertions, 100 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 0da4522..c28edc8 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -345,10 +345,9 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
local_state->SetBoolean(prefs::kMetricsReportingEnabled, true);
// On first run, we need to process the master preferences before the
// browser's profile_manager object is created.
- FirstRun::MasterPrefResult master_pref_res =
- FirstRun::ProcessMasterPreferences(user_data_dir, std::wstring());
first_run_ui_bypass =
- (master_pref_res == FirstRun::MASTER_PROFILE_NO_FIRST_RUN_UI);
+ !FirstRun::ProcessMasterPreferences(user_data_dir,
+ std::wstring(), NULL);
}
ResourceBundle::InitSharedInstance(
@@ -608,4 +607,3 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
return result_code;
}
-
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;
}
-
-
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h
index 85bac8d..4cdd2b6 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -45,55 +45,24 @@ class FirstRun {
// a visible UI depending on the cmdline parameters.
static int ImportNow(Profile* profile, const CommandLine& cmdline);
- // These are the possible results of calling ProcessMasterPreferences.
- // Some of the results can be combined, so they are bit flags.
- enum MasterPrefResult {
- MASTER_PROFILE_NOT_FOUND = 0,
- MASTER_PROFILE_ERROR = 1,
- MASTER_PROFILE_SHOW_EULA = 2,
- MASTER_PROFILE_NO_FIRST_RUN_UI = 4,
- MASTER_PROFILE_DO_FIRST_RUN_UI = 8
- };
-
// The master preferences is a JSON file with the same entries as the
// 'Default\Preferences' file. This function locates this file from
// master_pref_path or if that path is empty from the default location
// which is '<path to chrome.exe>\master_preferences', and process it
// so it becomes the default preferences in profile pointed by user_data_dir.
+ // After processing the file, the function returns true if showing the
+ // first run dialog is needed, and returns false if skipping first run
+ // dialogs. The detailed settings in the preference file is reported via
+ // preference_details.
//
// This function destroys any existing prefs file and it is meant to be
// invoked only on first run.
//
- // 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.
- //
- // Currently only the following return values are used:
- // MASTER_PROFILE_NOT_FOUND : Typical outcome for organic installs.
- // MASTER_PROFILE_ERROR : A critical error processing the master profile.
- // MASTER_PROFILE_NO_FIRST_RUN_UI : skip first run dialogs.
- // MASTER_PROFILE_DO_FIRST_RUN_UI : show the first run dialogs.
- static MasterPrefResult ProcessMasterPreferences(
- const std::wstring& user_data_dir,
- const std::wstring& master_prefs_path);
+ // See chrome/installer/util/master_preferences.h for a description of
+ // 'master_preferences' file.
+ static bool ProcessMasterPreferences(const std::wstring& user_data_dir,
+ const std::wstring& master_prefs_path,
+ int* preference_details);
// Sets the kShouldShowFirstRunBubble local state pref so that the browser
// shows the bubble once the main message loop gets going. Returns false if
@@ -145,4 +114,3 @@ class FirstRunBrowserProcess : public BrowserProcessImpl {
void OpenFirstRunDialog(Profile* profile);
#endif // CHROME_BROWSER_FIRST_RUN_H_
-
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>