summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-15 03:59:49 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-15 03:59:49 +0000
commita2e6b8ef80d4191af038292e9fd76b60c2981f5f (patch)
tree50792377f35d8181c616a6557e3227e7a8d2e029 /chrome/browser/first_run
parent3969d2b5bf878d0d70f7790da335a6fb0995cb0d (diff)
downloadchromium_src-a2e6b8ef80d4191af038292e9fd76b60c2981f5f.zip
chromium_src-a2e6b8ef80d4191af038292e9fd76b60c2981f5f.tar.gz
chromium_src-a2e6b8ef80d4191af038292e9fd76b60c2981f5f.tar.bz2
Progressively refactor FirstRun class to first_run namespace(part 7).
This cl refactors the rest of FirstRun class to first_run namespace, majorly ProcessMasterPreferences and its related functions. It includes the change to the following functions: ProcessMasterPreferences SkipFirstRunUI SetImportPreferencesAndLaunchImport ShowPostInstallEULAIfNeeded DoDelayedInstallExtensionsIfNeeded BUG=108137 TEST=NONE Review URL: http://codereview.chromium.org/9339003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run')
-rw-r--r--chrome/browser/first_run/first_run.cc184
-rw-r--r--chrome/browser/first_run/first_run.h88
-rw-r--r--chrome/browser/first_run/first_run_import_observer.h4
-rw-r--r--chrome/browser/first_run/first_run_internal.h22
-rw-r--r--chrome/browser/first_run/first_run_posix.cc55
-rw-r--r--chrome/browser/first_run/first_run_win.cc164
6 files changed, 243 insertions, 274 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index e07aa19..550ec77 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -43,12 +43,6 @@
#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
-#if defined(OS_WIN)
-// TODO(port): move more code in back from the first_run_win.cc module.
-#include "chrome/installer/util/google_update_settings.h"
-#include "chrome/installer/util/install_util.h"
-#endif
-
using content::UserMetricsAction;
namespace {
@@ -198,7 +192,7 @@ void SetupMasterPrefsFromInstallPrefs(
if (install_prefs->GetBool(
installer::master_preferences::kDistroSuppressFirstRunBubble,
&value) && value)
- first_run::SetShowFirstRunBubblePref(false);
+ SetShowFirstRunBubblePref(false);
if (install_prefs->GetBool(
installer::master_preferences::kDistroImportHistoryPref,
@@ -270,6 +264,17 @@ void SetShowWelcomePagePrefIfNeeded(
}
}
+bool SkipFirstRunUI(installer::MasterPreferences* install_prefs) {
+ // 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.)
+ bool value = false;
+ return (install_prefs->GetBool(
+ installer::master_preferences::kDistroSkipFirstRunPref,
+ &value) || !value);
+}
+
// -- Platform-specific functions --
#if !defined(OS_LINUX) && !defined(OS_BSD)
@@ -383,21 +388,6 @@ int ImportBookmarkFromFileIfNeeded(Profile* profile,
return return_code;
}
-// TODO(jennyz): move this fucntion to first_run_win.cc for further refactoring.
-#if defined(OS_WIN)
-void SetRLZPref(first_run::MasterPrefs* out_prefs,
- installer::MasterPreferences* install_prefs) {
- // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/
- // Linux, enable it here.
- 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;
- }
-}
-#endif
-
} // namespace internal
} // namespace first_run
@@ -536,153 +526,3 @@ void FirstRunBubbleLauncher::Observe(
}
} // namespace first_run
-
-// FirstRun -------------------------------------------------------------------
-
-// static
-bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
- first_run::MasterPrefs* out_prefs) {
- DCHECK(!user_data_dir.empty());
-
- 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 = install_prefs->GetFirstRunTabs();
-
- bool value = false;
-
-#if defined(OS_WIN)
- first_run::internal::SetRLZPref(out_prefs, install_prefs.get());
- ShowPostInstallEULAIfNeeded(install_prefs.get());
-#endif
-
- if (!first_run::internal::CopyPrefFile(user_data_dir, master_prefs_path))
- return true;
-
-#if defined(OS_WIN)
- DoDelayedInstallExtensionsIfNeeded(install_prefs.get());
-#endif
-
- 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 (!install_prefs->GetBool(
- installer::master_preferences::kDistroSkipFirstRunPref,
- &value) || !value) {
- return true;
- }
-
-#if !defined(OS_WIN)
- // From here on we won't show first run so we need to do the work to show the
- // bubble anyway, unless it's already been explicitly suppressed.
- first_run::SetShowFirstRunBubblePref(true);
-#endif
-
- // We need to be able to create the first run sentinel or else we cannot
- // proceed because ImportSettings will launch the importer process which
- // would end up here if the sentinel is not present.
- if (!first_run::CreateSentinel())
- return false;
-
- first_run::internal::SetShowWelcomePagePrefIfNeeded(install_prefs.get());
-
- std::string import_bookmarks_path;
- install_prefs->GetString(
- installer::master_preferences::kDistroImportBookmarksFromFilePref,
- &import_bookmarks_path);
-
-#if defined(USE_AURA)
- // TODO(saintlou):
-#elif defined(OS_WIN)
- if (!first_run::internal::IsOrganicFirstRun()) {
- // If search engines aren't explicitly imported, don't import.
- if (!(out_prefs->do_import_items & importer::SEARCH_ENGINES)) {
- out_prefs->dont_import_items |= importer::SEARCH_ENGINES;
- }
- // If home page isn't explicitly imported, don't import.
- if (!(out_prefs->do_import_items & importer::HOME_PAGE)) {
- out_prefs->dont_import_items |= importer::HOME_PAGE;
- }
- // If history isn't explicitly forbidden, do import.
- if (!(out_prefs->dont_import_items & importer::HISTORY)) {
- out_prefs->do_import_items |= importer::HISTORY;
- }
- }
-
- if (out_prefs->do_import_items || !import_bookmarks_path.empty()) {
- // There is something to import from the default browser. This launches
- // the importer process and blocks until done or until it fails.
- scoped_refptr<ImporterList> importer_list(new ImporterList(NULL));
- importer_list->DetectSourceProfilesHack();
- if (!first_run::internal::ImportSettingsWin(NULL,
- importer_list->GetSourceProfileAt(0).importer_type,
- out_prefs->do_import_items,
- FilePath::FromWStringHack(UTF8ToWide(import_bookmarks_path)),
- true)) {
- LOG(WARNING) << "silent import failed";
- }
- }
-#else
- if (!import_bookmarks_path.empty()) {
- // There are bookmarks to import from a file.
- FilePath path = FilePath::FromWStringHack(UTF8ToWide(
- import_bookmarks_path));
- if (!first_run::internal::ImportBookmarks(path)) {
- LOG(WARNING) << "silent bookmark import failed";
- }
- }
-#endif
-
- first_run::internal::SetDefaultBrowser(install_prefs.get());
- return false;
-}
-
-#if defined(OS_WIN)
-void FirstRun::ShowPostInstallEULAIfNeeded(
- installer::MasterPreferences* install_prefs) {
- bool value = false;
- 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.
-
- // The actual eula text is in a resource in chrome. We extract it to
- // a text file so setup.exe can use it as an inner frame.
- FilePath inner_html;
- if (WriteEULAtoTempFile(&inner_html)) {
- int retcode = 0;
- if (!LaunchSetupWithParam(installer::switches::kShowEula,
- inner_html.value(), &retcode) ||
- (retcode != installer::EULA_ACCEPTED &&
- retcode != installer::EULA_ACCEPTED_OPT_IN)) {
- LOG(WARNING) << "EULA rejected. Fast exit.";
- ::ExitProcess(1);
- }
- if (retcode == installer::EULA_ACCEPTED) {
- VLOG(1) << "EULA : no collection";
- GoogleUpdateSettings::SetCollectStatsConsent(false);
- } else if (retcode == installer::EULA_ACCEPTED_OPT_IN) {
- VLOG(1) << "EULA : collection consent";
- GoogleUpdateSettings::SetCollectStatsConsent(true);
- }
- }
- }
-}
-
-void FirstRun::DoDelayedInstallExtensionsIfNeeded(
- installer::MasterPreferences* install_prefs) {
- DictionaryValue* extensions = 0;
- if (install_prefs->GetExtensionsBlock(&extensions)) {
- VLOG(1) << "Extensions block found in master preferences";
- FirstRun::DoDelayedInstallExtensions();
- }
-}
-#endif
diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h
index 4b6fee4..7804578 100644
--- a/chrome/browser/first_run/first_run.h
+++ b/chrome/browser/first_run/first_run.h
@@ -22,14 +22,6 @@ class GURL;
class Profile;
class ProcessSingleton;
-namespace installer {
-class MasterPreferences;
-}
-
-// TODO(jennyz): All FirstRun class code will be refactored to first_run
-// namespace progressively with several changelists to be landed. Therefore,
-// we keep first_run namespace and FirstRun in the same file temporarily.
-
// This namespace contains the chrome first-run installation actions needed to
// fully test the custom installer. It also contains the opposite actions to
// execute during uninstall. When the first run UI is ready we won't
@@ -104,6 +96,22 @@ int ImportNow(Profile* profile, const CommandLine& cmdline);
// Returns the path for the master preferences file.
FilePath MasterPrefsPath();
+// The master preferences is a JSON file with the same entries as the
+// 'Default\Preferences' file. This function locates this file from a standard
+// location and processes it so it becomes the default preferences in the
+// profile pointed to by |user_data_dir|. After processing the file, the
+// function returns true if and only if showing the first run dialog is
+// needed. The detailed settings in the preference file are reported via
+// |preference_details|.
+//
+// This function destroys any existing prefs file and it is meant to be
+// invoked only on first run.
+//
+// See chrome/installer/util/master_preferences.h for a description of
+// 'master_preferences' file.
+bool ProcessMasterPreferences(const FilePath& user_data_dir,
+ MasterPrefs* out_prefs);
+
// Show the first run search engine bubble at the first appropriate opportunity.
// This bubble may be delayed by other UI, like global errors and sync promos.
class FirstRunBubbleLauncher : public content::NotificationObserver {
@@ -128,68 +136,4 @@ class FirstRunBubbleLauncher : public content::NotificationObserver {
} // namespace first_run
-// This class contains the chrome first-run installation actions needed to
-// fully test the custom installer. It also contains the opposite actions to
-// execute during uninstall. When the first run UI is ready we won't
-// do the actions unconditionally. Currently the only action is to create a
-// desktop shortcut.
-//
-// The way we detect first-run is by looking at a 'sentinel' file.
-// If it does not exist we understand that we need to do the first time
-// install work for this user. After that the sentinel file is created.
-class FirstRun {
- public:
-
- // The master preferences is a JSON file with the same entries as the
- // 'Default\Preferences' file. This function locates this file from a standard
- // location and processes it so it becomes the default preferences in the
- // profile pointed to by |user_data_dir|. After processing the file, the
- // function returns true if and only if showing the first run dialog is
- // needed. The detailed settings in the preference file are reported via
- // |preference_details|.
- //
- // This function destroys any existing prefs file and it is meant to be
- // invoked only on first run.
- //
- // See chrome/installer/util/master_preferences.h for a description of
- // 'master_preferences' file.
- static bool ProcessMasterPreferences(const FilePath& user_data_dir,
- first_run::MasterPrefs* out_prefs);
-
- private:
-
- // -- Platform-specific functions --
-
-#if defined(OS_WIN)
- // TODO(jennyz): Move the following functions to anonymous namespace of
- // first_run_win.cc in the future refactoring.
-
- // Writes the EULA to a temporary file, returned in |*eula_path|, and returns
- // true if successful.
- static bool WriteEULAtoTempFile(FilePath* eula_path);
-
- // Launches the setup exe with the given parameter/value on the command-line,
- // waits for its termination, returns its exit code in |*ret_code|, and
- // returns true if the exit code is valid.
- static bool LaunchSetupWithParam(const std::string& param,
- const std::wstring& value,
- int* ret_code);
-
- // Installs a task to do an extensions update check once the extensions system
- // is running.
- static void DoDelayedInstallExtensions();
-
- // Shows post installation EULA if needed.
- static void ShowPostInstallEULAIfNeeded(
- installer::MasterPreferences* install_prefs);
-
- static void DoDelayedInstallExtensionsIfNeeded(
- installer::MasterPreferences* install_prefs);
-
-#endif
-
- // This class is for scoping purposes.
- DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun);
-};
-
#endif // CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_
diff --git a/chrome/browser/first_run/first_run_import_observer.h b/chrome/browser/first_run/first_run_import_observer.h
index 50d1d5c..a051c9d 100644
--- a/chrome/browser/first_run/first_run_import_observer.h
+++ b/chrome/browser/first_run/first_run_import_observer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -10,7 +10,7 @@
#include "base/compiler_specific.h"
#include "chrome/browser/importer/importer_observer.h"
-// This class is used by FirstRun::ImportNow to get notified of the outcome of
+// This class is used by first_run::ImportNow to get notified of the outcome of
// the import operation. It differs from ImportProcessRunner in that this
// class executes in the context of the importing child process.
// The values that it handles are meant to be used as the process exit code.
diff --git a/chrome/browser/first_run/first_run_internal.h b/chrome/browser/first_run/first_run_internal.h
index 869c769..098a969 100644
--- a/chrome/browser/first_run/first_run_internal.h
+++ b/chrome/browser/first_run/first_run_internal.h
@@ -63,6 +63,9 @@ void SetShowWelcomePagePrefIfNeeded(
void SetDefaultBrowser(installer::MasterPreferences* install_prefs);
+// Returns true if the first-run-ui process should be skipped.
+bool SkipFirstRunUI(installer::MasterPreferences* install_prefs);
+
// -- Platform-specific functions --
// Gives the full path to the sentinel file. The file might not exist.
@@ -84,21 +87,10 @@ bool ImportSettings(Profile* profile,
scoped_refptr<ImporterList> importer_list,
int items_to_import);
-#if defined(OS_WIN)
-// TODO(jennyz): The following functions will be moved to first_run_win.cc
-// anonymous namespace once we move ProcessMasterPreferences() to first_run
-// namespace.
-
-bool ImportSettingsWin(Profile* profile,
- int importer_type,
- int items_to_import,
- const FilePath& import_bookmarks_path,
- bool skip_first_run_ui);
-
-// Sets RLZ preference.
-void SetRLZPref(first_run::MasterPrefs* out_prefs,
- installer::MasterPreferences* install_prefs);
-#endif // OS_WIN
+// Sets import preferences and launch the import process.
+void SetImportPreferencesAndLaunchImport(
+ MasterPrefs* out_prefs,
+ installer::MasterPreferences* install_prefs);
#if !defined(USE_AURA)
// AutoImport code which is common to all platforms.
diff --git a/chrome/browser/first_run/first_run_posix.cc b/chrome/browser/first_run/first_run_posix.cc
index 6e92269..db09bd9 100644
--- a/chrome/browser/first_run/first_run_posix.cc
+++ b/chrome/browser/first_run/first_run_posix.cc
@@ -98,6 +98,23 @@ bool ImportSettings(Profile* profile,
return true;
}
+void SetImportPreferencesAndLaunchImport(
+ MasterPrefs* out_prefs,
+ installer::MasterPreferences* install_prefs) {
+ std::string import_bookmarks_path;
+ install_prefs->GetString(
+ installer::master_preferences::kDistroImportBookmarksFromFilePref,
+ &import_bookmarks_path);
+ if (!import_bookmarks_path.empty()) {
+ // There are bookmarks to import from a file.
+ FilePath path = FilePath::FromWStringHack(UTF8ToWide(
+ import_bookmarks_path));
+ if (!ImportBookmarks(path)) {
+ LOG(WARNING) << "silent bookmark import failed";
+ }
+ }
+}
+
} // namespace internal
} // namespace first_run
@@ -110,5 +127,43 @@ int ImportNow(Profile* profile, const CommandLine& cmdline) {
return internal::ImportBookmarkFromFileIfNeeded(profile, cmdline);
}
+bool ProcessMasterPreferences(const FilePath& user_data_dir,
+ MasterPrefs* out_prefs) {
+ DCHECK(!user_data_dir.empty());
+
+ FilePath master_prefs_path;
+ scoped_ptr<installer::MasterPreferences>
+ install_prefs(internal::LoadMasterPrefs(&master_prefs_path));
+ if (!install_prefs.get())
+ return true;
+
+ out_prefs->new_tabs = install_prefs->GetFirstRunTabs();
+
+ if (!internal::CopyPrefFile(user_data_dir, master_prefs_path))
+ return true;
+
+ internal::SetupMasterPrefsFromInstallPrefs(out_prefs,
+ install_prefs.get());
+
+ if (!internal::SkipFirstRunUI(install_prefs.get()))
+ return true;
+
+ // From here on we won't show first run so we need to do the work to show the
+ // bubble anyway, unless it's already been explicitly suppressed.
+ SetShowFirstRunBubblePref(true);
+
+ // We need to be able to create the first run sentinel or else we cannot
+ // proceed because ImportSettings will launch the importer process which
+ // would end up here if the sentinel is not present.
+ if (!CreateSentinel())
+ return false;
+
+ internal::SetShowWelcomePagePrefIfNeeded(install_prefs.get());
+ internal::SetImportPreferencesAndLaunchImport(out_prefs, install_prefs.get());
+ internal::SetDefaultBrowser(install_prefs.get());
+
+ return false;
+}
+
} // namespace first_run
diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc
index 22e2a26..0725819 100644
--- a/chrome/browser/first_run/first_run_win.cc
+++ b/chrome/browser/first_run/first_run_win.cc
@@ -37,8 +37,10 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/worker_thread_ticker.h"
#include "chrome/installer/util/browser_distribution.h"
+#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/master_preferences.h"
+#include "chrome/installer/util/master_preferences_constants.h"
#include "chrome/installer/util/shell_util.h"
#include "chrome/installer/util/util_constants.h"
#include "content/public/browser/notification_service.h"
@@ -147,11 +149,12 @@ void PlatformSetup(Profile* profile) {
CreateChromeQuickLaunchShortcut();
}
-} // namespace
-
-bool FirstRun::LaunchSetupWithParam(const std::string& param,
- const std::wstring& value,
- int* ret_code) {
+// Launches the setup exe with the given parameter/value on the command-line,
+// waits for its termination, returns its exit code in |*ret_code|, and
+// returns true if the exit code is valid.
+bool LaunchSetupWithParam(const std::string& param,
+ const FilePath::StringType& value,
+ int* ret_code) {
FilePath exe_path;
if (!PathService::Get(base::DIR_MODULE, &exe_path))
return false;
@@ -175,7 +178,9 @@ bool FirstRun::LaunchSetupWithParam(const std::string& param,
return (TRUE == ::GetExitCodeProcess(ph, reinterpret_cast<DWORD*>(ret_code)));
}
-bool FirstRun::WriteEULAtoTempFile(FilePath* eula_path) {
+// Writes the EULA to a temporary file, returned in |*eula_path|, and returns
+// true if successful.
+bool WriteEULAtoTempFile(FilePath* eula_path) {
base::StringPiece terms =
ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_TERMS_HTML);
if (terms.empty())
@@ -188,10 +193,66 @@ bool FirstRun::WriteEULAtoTempFile(FilePath* eula_path) {
return good;
}
-void FirstRun::DoDelayedInstallExtensions() {
+void ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) {
+ bool value = false;
+ 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.
+
+ // The actual eula text is in a resource in chrome. We extract it to
+ // a text file so setup.exe can use it as an inner frame.
+ FilePath inner_html;
+ if (WriteEULAtoTempFile(&inner_html)) {
+ int retcode = 0;
+ if (!LaunchSetupWithParam(installer::switches::kShowEula,
+ inner_html.value(), &retcode) ||
+ (retcode != installer::EULA_ACCEPTED &&
+ retcode != installer::EULA_ACCEPTED_OPT_IN)) {
+ LOG(WARNING) << "EULA rejected. Fast exit.";
+ ::ExitProcess(1);
+ }
+ if (retcode == installer::EULA_ACCEPTED) {
+ VLOG(1) << "EULA : no collection";
+ GoogleUpdateSettings::SetCollectStatsConsent(false);
+ } else if (retcode == installer::EULA_ACCEPTED_OPT_IN) {
+ VLOG(1) << "EULA : collection consent";
+ GoogleUpdateSettings::SetCollectStatsConsent(true);
+ }
+ }
+ }
+}
+
+// Installs a task to do an extensions update check once the extensions system
+// is running.
+void DoDelayedInstallExtensions() {
new FirstRunDelayedTasks(FirstRunDelayedTasks::INSTALL_EXTENSIONS);
}
+void DoDelayedInstallExtensionsIfNeeded(
+ installer::MasterPreferences* install_prefs) {
+ DictionaryValue* extensions = 0;
+ if (install_prefs->GetExtensionsBlock(&extensions)) {
+ VLOG(1) << "Extensions block found in master preferences";
+ DoDelayedInstallExtensions();
+ }
+}
+
+void SetRLZPref(first_run::MasterPrefs* out_prefs,
+ installer::MasterPreferences* install_prefs) {
+ // RLZ is currently a Windows-only phenomenon. When it comes to the Mac/
+ // Linux, enable it here.
+ 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;
+ }
+}
+
+} // namespace
+
namespace {
// This class is used by first_run::ImportSettings to determine when the import
@@ -354,11 +415,6 @@ int ImportFromBrowser(Profile* profile,
}
#endif // !defined(USE_AURA)
-} // namespace
-
-namespace first_run {
-namespace internal{
-
bool ImportSettingsWin(Profile* profile,
int importer_type,
int items_to_import,
@@ -409,11 +465,16 @@ bool ImportSettingsWin(Profile* profile,
return (import_runner.exit_code() == content::RESULT_CODE_NORMAL_EXIT);
}
+} // namespace
+
+namespace first_run {
+namespace internal{
+
bool ImportSettings(Profile* profile,
scoped_refptr<ImporterHost> importer_host,
scoped_refptr<ImporterList> importer_list,
int items_to_import) {
- return internal::ImportSettingsWin(
+ return ImportSettingsWin(
profile,
importer_list->GetSourceProfileAt(0).importer_type,
items_to_import,
@@ -438,6 +499,44 @@ bool GetFirstRunSentinelFilePath(FilePath* path) {
return true;
}
+void SetImportPreferencesAndLaunchImport(
+ MasterPrefs* out_prefs,
+ installer::MasterPreferences* install_prefs) {
+ std::string import_bookmarks_path;
+ install_prefs->GetString(
+ installer::master_preferences::kDistroImportBookmarksFromFilePref,
+ &import_bookmarks_path);
+
+ if (!IsOrganicFirstRun()) {
+ // If search engines aren't explicitly imported, don't import.
+ if (!(out_prefs->do_import_items & importer::SEARCH_ENGINES)) {
+ out_prefs->dont_import_items |= importer::SEARCH_ENGINES;
+ }
+ // If home page isn't explicitly imported, don't import.
+ if (!(out_prefs->do_import_items & importer::HOME_PAGE)) {
+ out_prefs->dont_import_items |= importer::HOME_PAGE;
+ }
+ // If history isn't explicitly forbidden, do import.
+ if (!(out_prefs->dont_import_items & importer::HISTORY)) {
+ out_prefs->do_import_items |= importer::HISTORY;
+ }
+ }
+
+ if (out_prefs->do_import_items || !import_bookmarks_path.empty()) {
+ // There is something to import from the default browser. This launches
+ // the importer process and blocks until done or until it fails.
+ scoped_refptr<ImporterList> importer_list(new ImporterList(NULL));
+ importer_list->DetectSourceProfilesHack();
+ if (!ImportSettingsWin(NULL,
+ importer_list->GetSourceProfileAt(0).importer_type,
+ out_prefs->do_import_items,
+ FilePath::FromWStringHack(UTF8ToWide(import_bookmarks_path)),
+ true)) {
+ LOG(WARNING) << "silent import failed";
+ }
+ }
+}
+
} // namespace internal
} // namespace first_run
@@ -490,4 +589,43 @@ FilePath MasterPrefsPath() {
return master_prefs.AppendASCII(installer::kDefaultMasterPrefs);
}
+bool ProcessMasterPreferences(const FilePath& user_data_dir,
+ MasterPrefs* out_prefs) {
+ DCHECK(!user_data_dir.empty());
+
+ FilePath master_prefs_path;
+ scoped_ptr<installer::MasterPreferences>
+ install_prefs(internal::LoadMasterPrefs(&master_prefs_path));
+ if (!install_prefs.get())
+ return true;
+
+ out_prefs->new_tabs = install_prefs->GetFirstRunTabs();
+
+ SetRLZPref(out_prefs, install_prefs.get());
+ ShowPostInstallEULAIfNeeded(install_prefs.get());
+
+ if (!internal::CopyPrefFile(user_data_dir, master_prefs_path))
+ return true;
+
+ DoDelayedInstallExtensionsIfNeeded(install_prefs.get());
+
+ internal::SetupMasterPrefsFromInstallPrefs(out_prefs,
+ install_prefs.get());
+
+ if (!internal::SkipFirstRunUI(install_prefs.get()))
+ return true;
+
+ // We need to be able to create the first run sentinel or else we cannot
+ // proceed because ImportSettings will launch the importer process which
+ // would end up here if the sentinel is not present.
+ if (!CreateSentinel())
+ return false;
+
+ internal::SetShowWelcomePagePrefIfNeeded(install_prefs.get());
+ internal::SetImportPreferencesAndLaunchImport(out_prefs, install_prefs.get());
+ internal::SetDefaultBrowser(install_prefs.get());
+
+ return false;
+}
+
} // namespace first_run