summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-28 02:30:18 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-28 02:30:18 +0000
commitbaacb23598bfad687e1388fe2956e43d0ef0c7d8 (patch)
tree2ab9f58057b317551bfb04e8c8b9e2c999ba6c92
parent70f9df11715b7903b1fe3ecf8b3e4a0909bd80cf (diff)
downloadchromium_src-baacb23598bfad687e1388fe2956e43d0ef0c7d8.zip
chromium_src-baacb23598bfad687e1388fe2956e43d0ef0c7d8.tar.gz
chromium_src-baacb23598bfad687e1388fe2956e43d0ef0c7d8.tar.bz2
Progressively refactor FirstRun code to first_run namespace(part 5). This cl refactors:
MasterPrefs and some long code block into functions: LoadMasterPrefs CopyPrefFile SetupMasterPrefsFromInstallPrefs This helps to make FirstRun::ProcessMasterPreferences() become shorter and reduce the code duplication when we refactor ProcessMasterPreferences to different platforms in the next step. BUG=108137 TEST=NONE Review URL: http://codereview.chromium.org/9296021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119567 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_browser_main.cc2
-rw-r--r--chrome/browser/chrome_browser_main.h2
-rw-r--r--chrome/browser/first_run/first_run.cc207
-rw-r--r--chrome/browser/first_run/first_run.h33
-rw-r--r--chrome/browser/first_run/first_run_internal.h20
5 files changed, 157 insertions, 107 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 28a69ce..b3f02d2 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -1204,7 +1204,7 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
#endif
// These members must be initialized before returning from this function.
- master_prefs_.reset(new FirstRun::MasterPrefs);
+ master_prefs_.reset(new first_run::MasterPrefs);
browser_init_.reset(new BrowserInit);
std::string try_chrome =
diff --git a/chrome/browser/chrome_browser_main.h b/chrome/browser/chrome_browser_main.h
index b6b809e..4bf3e58 100644
--- a/chrome/browser/chrome_browser_main.h
+++ b/chrome/browser/chrome_browser_main.h
@@ -178,7 +178,7 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
scoped_refptr<chrome_browser_metrics::TrackingSynchronizer>
tracking_synchronizer_;
scoped_ptr<ProcessSingleton> process_singleton_;
- scoped_ptr<FirstRun::MasterPrefs> master_prefs_;
+ scoped_ptr<first_run::MasterPrefs> master_prefs_;
bool record_search_engine_;
TranslateManager* translate_manager_;
Profile* profile_;
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index 5fa9b89..122e898 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -144,6 +144,93 @@ namespace internal {
const char* const kSentinelFile = "First Run";
FirstRunState first_run_ = FIRST_RUN_UNKNOWN;
+installer::MasterPreferences* LoadMasterPrefs(FilePath* master_prefs_path)
+{
+ *master_prefs_path = FilePath(MasterPrefsPath());
+ if (master_prefs_path->empty())
+ return NULL;
+ installer::MasterPreferences* install_prefs =
+ new installer::MasterPreferences(*master_prefs_path);
+ if (!install_prefs->read_from_file())
+ return NULL;
+
+ return install_prefs;
+}
+
+bool CopyPrefFile(const FilePath& user_data_dir,
+ const FilePath& master_prefs_path) {
+ FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir);
+ if (user_prefs.empty())
+ return false;
+
+ // The master prefs are regular prefs so we can just copy the file
+ // to the default place and they just work.
+ return file_util::CopyFile(master_prefs_path, user_prefs);
+}
+
+void SetupMasterPrefsFromInstallPrefs(
+ MasterPrefs* out_prefs,
+ installer::MasterPreferences* install_prefs) {
+ bool value = false;
+ if (install_prefs->GetBool(
+ installer::master_preferences::kDistroImportSearchPref, &value)) {
+ if (value) {
+ out_prefs->do_import_items |= importer::SEARCH_ENGINES;
+ } else {
+ out_prefs->dont_import_items |= importer::SEARCH_ENGINES;
+ }
+ }
+
+ // If we're suppressing the first-run bubble, set that preference now.
+ // Otherwise, wait until the user has completed first run to set it, so the
+ // user is guaranteed to see the bubble iff he or she has completed the first
+ // run process.
+ if (install_prefs->GetBool(
+ installer::master_preferences::kDistroSuppressFirstRunBubble,
+ &value) && value)
+ first_run::SetShowFirstRunBubblePref(false);
+
+ if (install_prefs->GetBool(
+ installer::master_preferences::kDistroImportHistoryPref,
+ &value)) {
+ if (value) {
+ out_prefs->do_import_items |= importer::HISTORY;
+ } else {
+ out_prefs->dont_import_items |= importer::HISTORY;
+ }
+ }
+
+ std::string not_used;
+ out_prefs->homepage_defined = install_prefs->GetString(
+ prefs::kHomePage, &not_used);
+
+ if (install_prefs->GetBool(
+ installer::master_preferences::kDistroImportHomePagePref,
+ &value)) {
+ if (value) {
+ out_prefs->do_import_items |= importer::HOME_PAGE;
+ } else {
+ out_prefs->dont_import_items |= importer::HOME_PAGE;
+ }
+ }
+
+ // Bookmarks are never imported unless specifically turned on.
+ if (install_prefs->GetBool(
+ installer::master_preferences::kDistroImportBookmarksPref,
+ &value)) {
+ if (value)
+ out_prefs->do_import_items |= importer::FAVORITES;
+ else
+ out_prefs->dont_import_items |= importer::FAVORITES;
+ }
+
+ if (install_prefs->GetBool(
+ installer::master_preferences::kMakeChromeDefaultForUser,
+ &value) && value) {
+ out_prefs->make_chrome_default = true;
+ }
+}
+
// -- Platform-specific functions --
#if !defined(OS_LINUX) && !defined(OS_BSD)
@@ -262,6 +349,18 @@ int ImportBookmarkFromFileIfNeeded(Profile* profile,
namespace first_run {
+MasterPrefs::MasterPrefs()
+ : ping_delay(0),
+ homepage_defined(false),
+ do_import_items(0),
+ dont_import_items(0),
+ run_search_engine_experiment(false),
+ randomize_search_engine_experiment(false),
+ make_chrome_default(false) {
+}
+
+MasterPrefs::~MasterPrefs() {}
+
bool IsChromeFirstRun() {
if (internal::first_run_ != internal::FIRST_RUN_UNKNOWN)
return internal::first_run_ == internal::FIRST_RUN_TRUE;
@@ -326,44 +425,33 @@ bool SetPersonalDataManagerFirstRunPref() {
// FirstRun -------------------------------------------------------------------
-FirstRun::MasterPrefs::MasterPrefs()
- : ping_delay(0),
- homepage_defined(false),
- do_import_items(0),
- dont_import_items(0),
- make_chrome_default(false) {
-}
-
-FirstRun::MasterPrefs::~MasterPrefs() {}
-
// static
bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
- MasterPrefs* out_prefs) {
+ first_run::MasterPrefs* out_prefs) {
DCHECK(!user_data_dir.empty());
- FilePath master_prefs = first_run::MasterPrefsPath();
- if (master_prefs.empty())
- return true;
- installer::MasterPreferences prefs(master_prefs);
- if (!prefs.read_from_file())
+ FilePath master_prefs_path;
+ scoped_ptr<installer::MasterPreferences>
+ install_prefs(first_run::internal::LoadMasterPrefs(&master_prefs_path));
+ if (!install_prefs.get())
return true;
- out_prefs->new_tabs = prefs.GetFirstRunTabs();
+ out_prefs->new_tabs = install_prefs->GetFirstRunTabs();
bool value = false;
#if defined(OS_WIN)
// RLZ is currently a Windows-only phenomenon. When it comes to the Mac/
// Linux, enable it here.
- if (!prefs.GetInt(installer::master_preferences::kDistroPingDelay,
+ if (!install_prefs->GetInt(installer::master_preferences::kDistroPingDelay,
&out_prefs->ping_delay)) {
// 90 seconds is the default that we want to use in case master
// preferences is missing, corrupt or ping_delay is missing.
out_prefs->ping_delay = 90;
}
- if (prefs.GetBool(installer::master_preferences::kRequireEula, &value) &&
- value) {
+ if (install_prefs->GetBool(installer::master_preferences::kRequireEula,
+ &value) && value) {
// Show the post-installation EULA. This is done by setup.exe and the
// result determines if we continue or not. We wait here until the user
// dismisses the dialog.
@@ -391,85 +479,25 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
}
#endif
- FilePath user_prefs = GetDefaultPrefFilePath(true, user_data_dir);
- if (user_prefs.empty())
- 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))
+ if (!first_run::internal::CopyPrefFile(user_data_dir, master_prefs_path))
return true;
#if defined(OS_WIN)
DictionaryValue* extensions = 0;
- if (prefs.GetExtensionsBlock(&extensions)) {
+ if (install_prefs->GetExtensionsBlock(&extensions)) {
VLOG(1) << "Extensions block found in master preferences";
DoDelayedInstallExtensions();
}
#endif
- if (prefs.GetBool(installer::master_preferences::kDistroImportSearchPref,
- &value)) {
- if (value) {
- out_prefs->do_import_items |= importer::SEARCH_ENGINES;
- } else {
- out_prefs->dont_import_items |= importer::SEARCH_ENGINES;
- }
- }
-
- // If we're suppressing the first-run bubble, set that preference now.
- // Otherwise, wait until the user has completed first run to set it, so the
- // user is guaranteed to see the bubble iff he or she has completed the first
- // run process.
- if (prefs.GetBool(
- installer::master_preferences::kDistroSuppressFirstRunBubble,
- &value) && value)
- first_run::SetShowFirstRunBubblePref(false);
-
- if (prefs.GetBool(
- installer::master_preferences::kDistroImportHistoryPref,
- &value)) {
- if (value) {
- out_prefs->do_import_items |= importer::HISTORY;
- } else {
- out_prefs->dont_import_items |= importer::HISTORY;
- }
- }
-
- std::string not_used;
- out_prefs->homepage_defined = prefs.GetString(prefs::kHomePage, &not_used);
-
- if (prefs.GetBool(
- installer::master_preferences::kDistroImportHomePagePref,
- &value)) {
- if (value) {
- out_prefs->do_import_items |= importer::HOME_PAGE;
- } else {
- out_prefs->dont_import_items |= importer::HOME_PAGE;
- }
- }
-
- // Bookmarks are never imported unless specifically turned on.
- if (prefs.GetBool(
- installer::master_preferences::kDistroImportBookmarksPref,
- &value)) {
- if (value)
- out_prefs->do_import_items |= importer::FAVORITES;
- else
- out_prefs->dont_import_items |= importer::FAVORITES;
- }
-
- if (prefs.GetBool(
- installer::master_preferences::kMakeChromeDefaultForUser,
- &value) && value) {
- out_prefs->make_chrome_default = true;
- }
+ first_run::internal::SetupMasterPrefsFromInstallPrefs(out_prefs,
+ install_prefs.get());
// TODO(mirandac): Refactor skip-first-run-ui process into regular first run
// import process. http://crbug.com/49647
// Note we are skipping all other master preferences if skip-first-run-ui
// is *not* specified. (That is, we continue only if skipping first run ui.)
- if (!prefs.GetBool(
+ if (!install_prefs->GetBool(
installer::master_preferences::kDistroSkipFirstRunPref,
&value) || !value) {
return true;
@@ -487,13 +515,14 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
if (!first_run::CreateSentinel())
return false;
- if (prefs.GetBool(installer::master_preferences::kDistroShowWelcomePage,
- &value) && value) {
+ if (install_prefs->GetBool(
+ installer::master_preferences::kDistroShowWelcomePage, &value)
+ && value) {
first_run::SetShowWelcomePagePref();
}
std::string import_bookmarks_path;
- prefs.GetString(
+ install_prefs->GetString(
installer::master_preferences::kDistroImportBookmarksFromFilePref,
&import_bookmarks_path);
@@ -543,7 +572,7 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
// no policy has been set by the admin.
if (!g_browser_process->local_state()->IsManagedPreference(
prefs::kDefaultBrowserSettingEnabled)) {
- if (prefs.GetBool(
+ if (install_prefs->GetBool(
installer::master_preferences::kMakeChromeDefaultForUser,
&value) && value) {
ShellIntegration::SetAsDefaultBrowser();
diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h
index 0d255b1..e9d6ea4 100644
--- a/chrome/browser/first_run/first_run.h
+++ b/chrome/browser/first_run/first_run.h
@@ -38,6 +38,22 @@ class TemplateURLService;
// install work for this user. After that the sentinel file is created.
namespace first_run {
+// See ProcessMasterPreferences for more info about this structure.
+struct MasterPrefs {
+ MasterPrefs();
+ ~MasterPrefs();
+
+ int ping_delay;
+ bool homepage_defined;
+ int do_import_items;
+ int dont_import_items;
+ bool run_search_engine_experiment;
+ bool randomize_search_engine_experiment;
+ bool make_chrome_default;
+ std::vector<GURL> new_tabs;
+ std::vector<GURL> bookmarks;
+};
+
// Returns true if this is the first time chrome is run for this user.
bool IsChromeFirstRun();
@@ -98,19 +114,6 @@ FilePath MasterPrefsPath();
// install work for this user. After that the sentinel file is created.
class FirstRun {
public:
- // See ProcessMasterPreferences for more info about this structure.
- struct MasterPrefs {
- MasterPrefs();
- ~MasterPrefs();
-
- int ping_delay;
- bool homepage_defined;
- int do_import_items;
- int dont_import_items;
- bool make_chrome_default;
- std::vector<GURL> new_tabs;
- std::vector<GURL> bookmarks;
- };
// The master preferences is a JSON file with the same entries as the
// 'Default\Preferences' file. This function locates this file from a standard
@@ -126,11 +129,9 @@ class FirstRun {
// See chrome/installer/util/master_preferences.h for a description of
// 'master_preferences' file.
static bool ProcessMasterPreferences(const FilePath& user_data_dir,
- MasterPrefs* out_prefs);
+ first_run::MasterPrefs* out_prefs);
private:
- friend class FirstRunTest;
- FRIEND_TEST_ALL_PREFIXES(Toolbar5ImporterTest, BookmarkParse);
// -- Platform-specific functions --
diff --git a/chrome/browser/first_run/first_run_internal.h b/chrome/browser/first_run/first_run_internal.h
index 5f66f3e..b5c2934 100644
--- a/chrome/browser/first_run/first_run_internal.h
+++ b/chrome/browser/first_run/first_run_internal.h
@@ -23,6 +23,10 @@ class Profile;
class ProcessSingleton;
class TemplateURLService;
+namespace installer {
+class MasterPreferences;
+}
+
namespace first_run {
namespace internal {
@@ -38,6 +42,22 @@ extern FirstRunState first_run_;
// The kSentinelFile file absence will tell us it is a first run.
extern const char* const kSentinelFile;
+// Loads master preferences from the master preference file into the installer
+// master preferences. Passes the master preference file path out in
+// master_prefs_path. Returns the pointer to installer::MasterPreferences object
+// if successful; otherwise, returns NULL.
+installer::MasterPreferences* LoadMasterPrefs(FilePath* master_prefs_path);
+
+// Copies user preference file to master preference file. Returns true if
+// successful.
+bool CopyPrefFile(const FilePath& user_data_dir,
+ const FilePath& master_prefs_path);
+
+// Sets up master preferences by preferences passed by installer.
+void SetupMasterPrefsFromInstallPrefs(
+ MasterPrefs* out_prefs,
+ installer::MasterPreferences* install_prefs);
+
// -- Platform-specific functions --
// Gives the full path to the sentinel file. The file might not exist.