summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run
diff options
context:
space:
mode:
authorjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 01:01:28 +0000
committerjennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-05 01:01:28 +0000
commit3553f52f5412b810badd20eeb27a3b22396c78c6 (patch)
tree06da8f4cec505cc116b036afd02ea675ed9e312f /chrome/browser/first_run
parent83a2610a09404d1aa6365a21d49eb89be2be379c (diff)
downloadchromium_src-3553f52f5412b810badd20eeb27a3b22396c78c6.zip
chromium_src-3553f52f5412b810badd20eeb27a3b22396c78c6.tar.gz
chromium_src-3553f52f5412b810badd20eeb27a3b22396c78c6.tar.bz2
Refactor FirstRun class to first_run namespace progressively. This cl refactors:
IsOrganicFirstRun() AutoImport() ImportSettings() SetShowFirstRunBubblePref() SetMinimalFirstRunBubblePref() SetShowWelcomePagePref() SetPersonalDataManagerFirstRunPref() PlatformSetup() BUG=108137 TEST=NONE Review URL: http://codereview.chromium.org/9016051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116423 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run')
-rw-r--r--chrome/browser/first_run/first_run.cc426
-rw-r--r--chrome/browser/first_run/first_run.h95
-rw-r--r--chrome/browser/first_run/first_run_browsertest.cc8
-rw-r--r--chrome/browser/first_run/first_run_internal.h39
-rw-r--r--chrome/browser/first_run/first_run_linux.cc60
-rw-r--r--chrome/browser/first_run/first_run_mac.mm52
-rw-r--r--chrome/browser/first_run/first_run_posix.cc71
-rw-r--r--chrome/browser/first_run/first_run_win.cc139
8 files changed, 493 insertions, 397 deletions
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index 0211efc..71b5d50 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -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.
@@ -75,7 +75,7 @@ void SetImportItem(PrefService* user_prefs,
if (import_type == importer::HISTORY ||
((import_type != importer::FAVORITES) &&
- FirstRun::IsOrganicFirstRun())) {
+ first_run::internal::IsOrganicFirstRun())) {
// History is always imported unless turned off in master_preferences.
// Search engines are only imported in certain builds unless overridden
// in master_preferences.Home page is imported in organic builds only unless
@@ -116,6 +116,114 @@ namespace internal {
const char* const kSentinelFile = "First Run";
FirstRunState first_run_ = FIRST_RUN_UNKNOWN;
+// -- Platform-specific functions --
+
+#if !defined(OS_LINUX)
+bool IsOrganicFirstRun() {
+ std::string brand;
+ google_util::GetBrand(&brand);
+ return google_util::IsOrganicFirstRun(brand);
+}
+#endif
+
+#if !defined(USE_AURA)
+void AutoImportPlatformCommon(
+ scoped_refptr<ImporterHost> importer_host,
+ Profile* profile,
+ bool homepage_defined,
+ int import_items,
+ int dont_import_items,
+ bool search_engine_experiment,
+ bool randomize_search_engine_experiment,
+ bool make_chrome_default) {
+ FilePath local_state_path;
+ PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
+ bool local_state_file_exists = file_util::PathExists(local_state_path);
+
+ scoped_refptr<ImporterList> importer_list(new ImporterList(NULL));
+ importer_list->DetectSourceProfilesHack();
+
+ // Do import if there is an available profile for us to import.
+ if (importer_list->count() > 0) {
+ // Don't show the warning dialog if import fails.
+ importer_host->set_headless();
+ int items = 0;
+
+ if (IsOrganicFirstRun()) {
+ // Home page is imported in organic builds only unless turned off or
+ // defined in master_preferences.
+ if (homepage_defined) {
+ dont_import_items |= importer::HOME_PAGE;
+ if (import_items & importer::HOME_PAGE)
+ import_items &= ~importer::HOME_PAGE;
+ }
+ // Search engines are not imported automatically in organic builds if the
+ // user already has a user preferences directory.
+ if (local_state_file_exists) {
+ dont_import_items |= importer::SEARCH_ENGINES;
+ if (import_items & importer::SEARCH_ENGINES)
+ import_items &= ~importer::SEARCH_ENGINES;
+ }
+ }
+
+ PrefService* user_prefs = profile->GetPrefs();
+
+ SetImportItem(user_prefs,
+ prefs::kImportHistory,
+ import_items,
+ dont_import_items,
+ importer::HISTORY,
+ items);
+ SetImportItem(user_prefs,
+ prefs::kImportHomepage,
+ import_items,
+ dont_import_items,
+ importer::HOME_PAGE,
+ items);
+ SetImportItem(user_prefs,
+ prefs::kImportSearchEngine,
+ import_items,
+ dont_import_items,
+ importer::SEARCH_ENGINES,
+ items);
+ SetImportItem(user_prefs,
+ prefs::kImportBookmarks,
+ import_items,
+ dont_import_items,
+ importer::FAVORITES,
+ items);
+
+ ImportSettings(profile, importer_host, importer_list, items);
+ }
+
+ content::RecordAction(UserMetricsAction("FirstRunDef_Accept"));
+
+ // Launch the search engine dialog only for certain builds, and only if the
+ // user has not already set preferences.
+ if (IsOrganicFirstRun() && !local_state_file_exists) {
+ // The home page string may be set in the preferences, but the user should
+ // initially use Chrome with the NTP as home page in organic builds.
+ profile->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, true);
+ ShowFirstRunDialog(profile, randomize_search_engine_experiment);
+ }
+
+ if (make_chrome_default)
+ ShellIntegration::SetAsDefaultBrowser();
+
+ // Don't display the minimal bubble if there is no default search provider.
+ TemplateURLService* search_engines_model =
+ TemplateURLServiceFactory::GetForProfile(profile);
+ if (search_engines_model &&
+ search_engines_model->GetDefaultSearchProvider()) {
+ SetShowFirstRunBubblePref(true);
+ // Set the first run bubble to minimal.
+ SetMinimalFirstRunBubblePref();
+ }
+ SetShowWelcomePagePref();
+ SetPersonalDataManagerFirstRunPref();
+}
+#endif // !defined(USE_AURA)
+
} // namespace internal
} // namespace first_run
@@ -149,6 +257,51 @@ bool RemoveSentinel() {
return file_util::Delete(first_run_sentinel, false);
}
+bool SetShowFirstRunBubblePref(bool show_bubble) {
+ PrefService* local_state = g_browser_process->local_state();
+ if (!local_state)
+ return false;
+ if (!local_state->HasPrefPath(prefs::kShouldShowFirstRunBubble))
+ local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, show_bubble);
+ return true;
+}
+
+bool SetMinimalFirstRunBubblePref() {
+ PrefService* local_state = g_browser_process->local_state();
+ if (!local_state)
+ return false;
+ if (!local_state->FindPreference(prefs::kShouldUseMinimalFirstRunBubble)) {
+ local_state->RegisterBooleanPref(prefs::kShouldUseMinimalFirstRunBubble,
+ false);
+ local_state->SetBoolean(prefs::kShouldUseMinimalFirstRunBubble, true);
+ }
+ return true;
+}
+
+bool SetShowWelcomePagePref() {
+ PrefService* local_state = g_browser_process->local_state();
+ if (!local_state)
+ return false;
+ if (!local_state->FindPreference(prefs::kShouldShowWelcomePage)) {
+ local_state->RegisterBooleanPref(prefs::kShouldShowWelcomePage, false);
+ local_state->SetBoolean(prefs::kShouldShowWelcomePage, true);
+ }
+ return true;
+}
+
+bool SetPersonalDataManagerFirstRunPref() {
+ PrefService* local_state = g_browser_process->local_state();
+ if (!local_state)
+ return false;
+ if (!local_state->FindPreference(
+ prefs::kAutofillPersonalDataManagerFirstRun)) {
+ local_state->RegisterBooleanPref(
+ prefs::kAutofillPersonalDataManagerFirstRun, false);
+ local_state->SetBoolean(prefs::kAutofillPersonalDataManagerFirstRun, true);
+ }
+ return true;
+}
+
} // namespace first_run
// FirstRun -------------------------------------------------------------------
@@ -284,7 +437,7 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
if (prefs.GetBool(
installer::master_preferences::kDistroSuppressFirstRunBubble,
&value) && value)
- FirstRun::SetShowFirstRunBubblePref(false);
+ first_run::SetShowFirstRunBubblePref(false);
if (prefs.GetBool(
installer::master_preferences::kDistroImportHistoryPref,
@@ -338,7 +491,7 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
#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.
- FirstRun::SetShowFirstRunBubblePref(true);
+ first_run::SetShowFirstRunBubblePref(true);
#endif
// We need to be able to create the first run sentinel or else we cannot
@@ -349,7 +502,7 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
if (prefs.GetBool(installer::master_preferences::kDistroShowWelcomePage,
&value) && value) {
- FirstRun::SetShowWelcomePagePref();
+ first_run::SetShowWelcomePagePref();
}
std::string import_bookmarks_path;
@@ -360,7 +513,7 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
#if defined(USE_AURA)
// TODO(saintlou):
#elif defined(OS_WIN)
- if (!IsOrganicFirstRun()) {
+ 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;
@@ -380,7 +533,7 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
// the importer process and blocks until done or until it fails.
scoped_refptr<ImporterList> importer_list(new ImporterList(NULL));
importer_list->DetectSourceProfilesHack();
- if (!FirstRun::ImportSettings(NULL,
+ if (!first_run::internal::ImportSettingsWin(NULL,
importer_list->GetSourceProfileAt(0).importer_type,
out_prefs->do_import_items,
FilePath::FromWStringHack(UTF8ToWide(import_bookmarks_path)),
@@ -419,42 +572,6 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
}
// static
-bool FirstRun::SetShowFirstRunBubblePref(bool show_bubble) {
- PrefService* local_state = g_browser_process->local_state();
- if (!local_state)
- return false;
- if (!local_state->HasPrefPath(prefs::kShouldShowFirstRunBubble))
- local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, show_bubble);
- return true;
-}
-
-// static
-bool FirstRun::SetShowWelcomePagePref() {
- PrefService* local_state = g_browser_process->local_state();
- if (!local_state)
- return false;
- if (!local_state->FindPreference(prefs::kShouldShowWelcomePage)) {
- local_state->RegisterBooleanPref(prefs::kShouldShowWelcomePage, false);
- local_state->SetBoolean(prefs::kShouldShowWelcomePage, true);
- }
- return true;
-}
-
-// static
-bool FirstRun::SetPersonalDataManagerFirstRunPref() {
- PrefService* local_state = g_browser_process->local_state();
- if (!local_state)
- return false;
- if (!local_state->FindPreference(
- prefs::kAutofillPersonalDataManagerFirstRun)) {
- local_state->RegisterBooleanPref(
- prefs::kAutofillPersonalDataManagerFirstRun, false);
- local_state->SetBoolean(prefs::kAutofillPersonalDataManagerFirstRun, true);
- }
- return true;
-}
-
-// static
bool FirstRun::ShouldShowSearchEngineSelector(const TemplateURLService* model) {
return model && !model->is_default_search_managed();
}
@@ -472,19 +589,6 @@ bool FirstRun::SetOEMFirstRunBubblePref() {
}
// static
-bool FirstRun::SetMinimalFirstRunBubblePref() {
- PrefService* local_state = g_browser_process->local_state();
- if (!local_state)
- return false;
- if (!local_state->FindPreference(prefs::kShouldUseMinimalFirstRunBubble)) {
- local_state->RegisterBooleanPref(prefs::kShouldUseMinimalFirstRunBubble,
- false);
- local_state->SetBoolean(prefs::kShouldUseMinimalFirstRunBubble, true);
- }
- return true;
-}
-
-// static
int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) {
FilePath file_path = cmdline.GetSwitchValuePath(switches::kImportFromFile);
if (file_path.empty()) {
@@ -510,213 +614,3 @@ int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) {
importer_observer.RunLoop();
return importer_observer.import_result();
}
-
-// static
-void FirstRun::AutoImport(
- Profile* profile,
- bool homepage_defined,
- int import_items,
- int dont_import_items,
- bool search_engine_experiment,
- bool randomize_search_engine_experiment,
- bool make_chrome_default,
- ProcessSingleton* process_singleton) {
-#if !defined(USE_AURA)
- // We need to avoid dispatching new tabs when we are importing because
- // that will lead to data corruption or a crash. Because there is no UI for
- // the import process, we pass NULL as the window to bring to the foreground
- // when a CopyData message comes in; this causes the message to be silently
- // discarded, which is the correct behavior during the import process.
- process_singleton->Lock(NULL);
-
- PlatformSetup();
-
- FilePath local_state_path;
- PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
- bool local_state_file_exists = file_util::PathExists(local_state_path);
-
- scoped_refptr<ImporterHost> importer_host;
- // TODO(csilv,mirandac): Out-of-process import has only been qualified on
- // MacOS X, so we will only use it on that platform since it is required.
- // Remove this conditional logic once oop import is qualified for
- // Linux/Windows. http://crbug.com/22142
-#if defined(OS_MACOSX)
- importer_host = new ExternalProcessImporterHost;
-#else
- importer_host = new ImporterHost;
-#endif
-
- scoped_refptr<ImporterList> importer_list(new ImporterList(NULL));
- importer_list->DetectSourceProfilesHack();
-
- // Do import if there is an available profile for us to import.
- if (importer_list->count() > 0) {
- // Don't show the warning dialog if import fails.
- importer_host->set_headless();
- int items = 0;
-
- if (IsOrganicFirstRun()) {
- // Home page is imported in organic builds only unless turned off or
- // defined in master_preferences.
- if (homepage_defined) {
- dont_import_items |= importer::HOME_PAGE;
- if (import_items & importer::HOME_PAGE)
- import_items &= ~importer::HOME_PAGE;
- }
- // Search engines are not imported automatically in organic builds if the
- // user already has a user preferences directory.
- if (local_state_file_exists) {
- dont_import_items |= importer::SEARCH_ENGINES;
- if (import_items & importer::SEARCH_ENGINES)
- import_items &= ~importer::SEARCH_ENGINES;
- }
- }
-
- PrefService* user_prefs = profile->GetPrefs();
-
- SetImportItem(user_prefs,
- prefs::kImportHistory,
- import_items,
- dont_import_items,
- importer::HISTORY,
- items);
- SetImportItem(user_prefs,
- prefs::kImportHomepage,
- import_items,
- dont_import_items,
- importer::HOME_PAGE,
- items);
- SetImportItem(user_prefs,
- prefs::kImportSearchEngine,
- import_items,
- dont_import_items,
- importer::SEARCH_ENGINES,
- items);
- SetImportItem(user_prefs,
- prefs::kImportBookmarks,
- import_items,
- dont_import_items,
- importer::FAVORITES,
- items);
-
- ImportSettings(profile, importer_host, importer_list, items);
- }
-
- content::RecordAction(UserMetricsAction("FirstRunDef_Accept"));
-
- // Launch the search engine dialog only for certain builds, and only if the
- // user has not already set preferences.
- if (IsOrganicFirstRun() && !local_state_file_exists) {
- // The home page string may be set in the preferences, but the user should
- // initially use Chrome with the NTP as home page in organic builds.
- profile->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, true);
- first_run::ShowFirstRunDialog(profile, randomize_search_engine_experiment);
- }
-
- if (make_chrome_default)
- ShellIntegration::SetAsDefaultBrowser();
-
- // Don't display the minimal bubble if there is no default search provider.
- TemplateURLService* search_engines_model =
- TemplateURLServiceFactory::GetForProfile(profile);
- if (search_engines_model &&
- search_engines_model->GetDefaultSearchProvider()) {
- FirstRun::SetShowFirstRunBubblePref(true);
- // Set the first run bubble to minimal.
- FirstRun::SetMinimalFirstRunBubblePref();
- }
- FirstRun::SetShowWelcomePagePref();
- FirstRun::SetPersonalDataManagerFirstRunPref();
-
- process_singleton->Unlock();
- first_run::CreateSentinel();
-#endif
-}
-
-#if defined(OS_LINUX)
-// static
-bool FirstRun::IsOrganicFirstRun() {
- // We treat all installs as organic.
- return true;
-}
-#else
-// static
-bool FirstRun::IsOrganicFirstRun() {
- std::string brand;
- google_util::GetBrand(&brand);
- return google_util::IsOrganicFirstRun(brand);
-}
-#endif // OS_LINUX
-
-#if defined(OS_POSIX)
-namespace {
-
-// This class acts as an observer for the ImporterProgressObserver::ImportEnded
-// callback. When the import process is started, certain errors may cause
-// ImportEnded() to be called synchronously, but the typical case is that
-// ImportEnded() is called asynchronously. Thus we have to handle both cases.
-class ImportEndedObserver : public importer::ImporterProgressObserver {
- public:
- ImportEndedObserver() : ended_(false),
- should_quit_message_loop_(false) {}
- virtual ~ImportEndedObserver() {}
-
- // importer::ImporterProgressObserver:
- virtual void ImportStarted() OVERRIDE {}
- virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {}
- virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {}
- virtual void ImportEnded() OVERRIDE {
- ended_ = true;
- if (should_quit_message_loop_)
- MessageLoop::current()->Quit();
- }
-
- void set_should_quit_message_loop() {
- should_quit_message_loop_ = true;
- }
-
- bool ended() {
- return ended_;
- }
-
- private:
- // Set if the import has ended.
- bool ended_;
-
- // Set by the client (via set_should_quit_message_loop) if, when the import
- // ends, this class should quit the message loop.
- bool should_quit_message_loop_;
-};
-
-} // namespace
-
-// static
-bool FirstRun::ImportSettings(Profile* profile,
- scoped_refptr<ImporterHost> importer_host,
- scoped_refptr<ImporterList> importer_list,
- int items_to_import) {
- const importer::SourceProfile& source_profile =
- importer_list->GetSourceProfileAt(0);
-
- // Ensure that importers aren't requested to import items that they do not
- // support.
- items_to_import &= source_profile.services_supported;
-
- scoped_ptr<ImportEndedObserver> observer(new ImportEndedObserver);
- importer_host->SetObserver(observer.get());
- importer_host->StartImportSettings(source_profile,
- profile,
- items_to_import,
- new ProfileWriter(profile),
- true);
- // If the import process has not errored out, block on it.
- if (!observer->ended()) {
- observer->set_should_quit_message_loop();
- MessageLoop::current()->Run();
- }
-
- // Unfortunately there's no success/fail signal in ImporterHost.
- return true;
-}
-
-#endif // OS_POSIX
diff --git a/chrome/browser/first_run/first_run.h b/chrome/browser/first_run/first_run.h
index 043dbc4..17de340 100644
--- a/chrome/browser/first_run/first_run.h
+++ b/chrome/browser/first_run/first_run.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.
@@ -48,6 +48,42 @@ bool CreateSentinel();
// sentinel file could not be removed.
bool RemoveSentinel();
+// Sets the kShouldShowFirstRunBubble local state pref so that the browser
+// shows the bubble once the main message loop gets going (or refrains from
+// showing the bubble, if |show_bubble| is false). Returns false if the pref
+// could not be set. This function can be called multiple times, but only the
+// initial call will actually set the preference.
+bool SetShowFirstRunBubblePref(bool show_bubble);
+
+// Sets the kShouldUseMinimalFirstRunBubble local state pref so that the
+// browser shows the minimal first run bubble once the main message loop
+// gets going. Returns false if the pref could not be set.
+bool SetMinimalFirstRunBubblePref();
+
+// Sets the kShouldShowWelcomePage local state pref so that the browser
+// loads the welcome tab once the message loop gets going. Returns false
+// if the pref could not be set.
+bool SetShowWelcomePagePref();
+
+// Sets the kAutofillPersonalDataManagerFirstRun local state pref so that the
+// browser loads PersonalDataManager once the main message loop gets going.
+// Returns false if the pref could not be set.
+bool SetPersonalDataManagerFirstRunPref();
+
+// -- Platform-specific functions --
+
+// Automatically import history and home page (and search engine, if
+// ShouldShowSearchEngineDialog is true).
+void AutoImport(Profile* profile,
+ bool homepage_defined,
+ int import_items,
+ int dont_import_items,
+ bool search_engine_experiment,
+ bool randomize_search_engine_experiment,
+ bool make_chrome_default,
+ ProcessSingleton* process_singleton);
+
+
} // namespace first_run
// This class contains the chrome first-run installation actions needed to
@@ -90,18 +126,6 @@ class FirstRun {
// cmdline parameters.
static int ImportNow(Profile* profile, const CommandLine& cmdline);
- // Automatically import history and home page (and search engine, if
- // ShouldShowSearchEngineDialog is true).
- static void AutoImport(
- Profile* profile,
- bool homepage_defined,
- int import_items,
- int dont_import_items,
- bool search_engine_experiment,
- bool randomize_search_engine_experiment,
- bool make_chrome_default,
- ProcessSingleton* process_singleton);
-
// 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
@@ -118,52 +142,16 @@ class FirstRun {
static bool ProcessMasterPreferences(const FilePath& user_data_dir,
MasterPrefs* out_prefs);
- // Sets the kShouldShowFirstRunBubble local state pref so that the browser
- // shows the bubble once the main message loop gets going (or refrains from
- // showing the bubble, if |show_bubble| is false). Returns false if the pref
- // could not be set. This function can be called multiple times, but only the
- // initial call will actually set the preference.
- static bool SetShowFirstRunBubblePref(bool show_bubble);
-
// Sets the kShouldUseOEMFirstRunBubble local state pref so that the
// browser shows the OEM first run bubble once the main message loop
// gets going. Returns false if the pref could not be set.
static bool SetOEMFirstRunBubblePref();
- // Sets the kShouldUseMinimalFirstRunBubble local state pref so that the
- // browser shows the minimal first run bubble once the main message loop
- // gets going. Returns false if the pref could not be set.
- static bool SetMinimalFirstRunBubblePref();
-
- // Sets the kShouldShowWelcomePage local state pref so that the browser
- // loads the welcome tab once the message loop gets going. Returns false
- // if the pref could not be set.
- static bool SetShowWelcomePagePref();
-
- // Sets the kAutofillPersonalDataManagerFirstRun local state pref so that the
- // browser loads PersonalDataManager once the main message loop gets going.
- // Returns false if the pref could not be set.
- static bool SetPersonalDataManagerFirstRunPref();
-
// Whether the search engine selection dialog should be shown on first run.
static bool ShouldShowSearchEngineSelector(const TemplateURLService* model);
// -- Platform-specific functions --
- // Imports settings. This may be done in a separate process depending on the
- // platform, but it will always block until done. The return value indicates
- // success.
- static bool ImportSettings(Profile* profile,
- scoped_refptr<ImporterHost> importer_host,
- scoped_refptr<ImporterList> importer_list,
- int items_to_import);
-
- // Does platform specific setup. Called at the start of AutoImport.
- static void PlatformSetup();
-
- // Returns whether the first run should be "organic".
- static bool IsOrganicFirstRun();
-
// Returns the path for the master preferences file.
static FilePath MasterPrefsPath();
@@ -196,15 +184,6 @@ class FirstRun {
// is running.
static void DoDelayedInstallExtensions();
- // Imports settings in a separate process. It is the implementation of the
- // public version. |skip_first_run_ui| is true if no first run UI should
- // appear (search engine dialog, Firefox import warning dialog).
- static bool ImportSettings(Profile* profile,
- int importer_type,
- int items_to_import,
- const FilePath& import_path,
- bool skip_first_run_ui);
-
#if !defined(USE_AURA)
// Import browser items in this process. The browser and the items to
// import are encoded in the command line.
diff --git a/chrome/browser/first_run/first_run_browsertest.cc b/chrome/browser/first_run/first_run_browsertest.cc
index 27e1176..47c2ef6 100644
--- a/chrome/browser/first_run/first_run_browsertest.cc
+++ b/chrome/browser/first_run/first_run_browsertest.cc
@@ -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.
@@ -14,7 +14,7 @@ typedef InProcessBrowserTest FirstRunBrowserTest;
IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShowFirstRunBubblePref) {
EXPECT_TRUE(g_browser_process->local_state()->FindPreference(
prefs::kShouldShowFirstRunBubble));
- EXPECT_TRUE(FirstRun::SetShowFirstRunBubblePref(true));
+ EXPECT_TRUE(first_run::SetShowFirstRunBubblePref(true));
ASSERT_TRUE(g_browser_process->local_state()->FindPreference(
prefs::kShouldShowFirstRunBubble));
EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
@@ -24,7 +24,7 @@ IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShowFirstRunBubblePref) {
IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShowWelcomePagePref) {
EXPECT_FALSE(g_browser_process->local_state()->FindPreference(
prefs::kShouldShowWelcomePage));
- EXPECT_TRUE(FirstRun::SetShowWelcomePagePref());
+ EXPECT_TRUE(first_run::SetShowWelcomePagePref());
ASSERT_TRUE(g_browser_process->local_state()->FindPreference(
prefs::kShouldShowWelcomePage));
EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
@@ -44,7 +44,7 @@ IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetOEMFirstRunBubblePref) {
IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetMinimalFirstRunBubblePref) {
EXPECT_FALSE(g_browser_process->local_state()->FindPreference(
prefs::kShouldUseMinimalFirstRunBubble));
- EXPECT_TRUE(FirstRun::SetMinimalFirstRunBubblePref());
+ EXPECT_TRUE(first_run::SetMinimalFirstRunBubblePref());
ASSERT_TRUE(g_browser_process->local_state()->FindPreference(
prefs::kShouldUseMinimalFirstRunBubble));
EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
diff --git a/chrome/browser/first_run/first_run_internal.h b/chrome/browser/first_run/first_run_internal.h
index 7cd9497..64fb224 100644
--- a/chrome/browser/first_run/first_run_internal.h
+++ b/chrome/browser/first_run/first_run_internal.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.
@@ -45,6 +45,43 @@ extern const char* const kSentinelFile;
// implementation.
bool GetFirstRunSentinelFilePath(FilePath* path);
+// This function has a common implementationin for all non-linux platforms, and
+// a linux specific implementation.
+bool IsOrganicFirstRun();
+
+// Imports settings. This may be done in a separate process depending on the
+// platform, but it will always block until done. The return value indicates
+// success.
+// This functions has a common implementation for OS_POSIX, and a
+// windows specific implementation.
+bool ImportSettings(Profile* profile,
+ scoped_refptr<ImporterHost> importer_host,
+ scoped_refptr<ImporterList> importer_list,
+ int items_to_import);
+
+#if defined(OS_WIN)
+// TODO(jennyz): This fuction will be moved to first_run_win.cc anonymous
+// namespace once we refactor its calling code in first_run.cc later.
+bool ImportSettingsWin(Profile* profile,
+ int importer_type,
+ int items_to_import,
+ const FilePath& import_bookmarks_path,
+ bool skip_first_run_ui);
+#endif // OS_WIN
+
+#if !defined(USE_AURA)
+// AutoImport code which is common to all platforms.
+void AutoImportPlatformCommon(
+ scoped_refptr<ImporterHost> importer_host,
+ Profile* profile,
+ bool homepage_defined,
+ int import_items,
+ int dont_import_items,
+ bool search_engine_experiment,
+ bool randomize_search_engine_experiment,
+ bool make_chrome_default);
+#endif // !defined(USE_AURA)
+
} // namespace internal
} // namespace first_run
diff --git a/chrome/browser/first_run/first_run_linux.cc b/chrome/browser/first_run/first_run_linux.cc
index eb5251a..e76d0f7 100644
--- a/chrome/browser/first_run/first_run_linux.cc
+++ b/chrome/browser/first_run/first_run_linux.cc
@@ -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.
@@ -13,6 +13,9 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/first_run/first_run_internal.h"
+#include "chrome/browser/importer/importer_host.h"
+#include "chrome/browser/process_singleton.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/util/google_update_settings.h"
@@ -21,6 +24,55 @@
#include "googleurl/src/gurl.h"
#include "ui/base/ui_base_switches.h"
+namespace first_run {
+namespace internal {
+
+bool IsOrganicFirstRun() {
+ // We treat all installs as organic.
+ return true;
+}
+
+} // namespace internal
+} // namespace first_run
+
+namespace first_run {
+
+void AutoImport(
+ Profile* profile,
+ bool homepage_defined,
+ int import_items,
+ int dont_import_items,
+ bool search_engine_experiment,
+ bool randomize_search_engine_experiment,
+ bool make_chrome_default,
+ ProcessSingleton* process_singleton) {
+#if !defined(USE_AURA)
+ // We need to avoid dispatching new tabs when we are importing because
+ // that will lead to data corruption or a crash. Because there is no UI for
+ // the import process, we pass NULL as the window to bring to the foreground
+ // when a CopyData message comes in; this causes the message to be silently
+ // discarded, which is the correct behavior during the import process.
+ process_singleton->Lock(NULL);
+
+ scoped_refptr<ImporterHost> importer_host;
+ importer_host = new ImporterHost;
+
+ internal::AutoImportPlatformCommon(importer_host,
+ profile,
+ homepage_defined,
+ import_items,
+ dont_import_items,
+ search_engine_experiment,
+ randomize_search_engine_experiment,
+ make_chrome_default);
+
+ process_singleton->Unlock();
+ CreateSentinel();
+#endif // !defined(USE_AURA)
+}
+
+} // namespace first_run
+
// TODO(port): This is just a piece of the silent import functionality from
// ImportSettings for Windows. It would be nice to get the rest of it ported.
bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) {
@@ -48,12 +100,6 @@ bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) {
}
// static
-void FirstRun::PlatformSetup() {
- // Things that Windows does here (creating a desktop icon, for example) are
- // handled at install time on Linux.
-}
-
-// static
FilePath FirstRun::MasterPrefsPath() {
// The standard location of the master prefs is next to the chrome binary.
FilePath master_prefs;
diff --git a/chrome/browser/first_run/first_run_mac.mm b/chrome/browser/first_run/first_run_mac.mm
index 2d9fe08..d394ddd 100644
--- a/chrome/browser/first_run/first_run_mac.mm
+++ b/chrome/browser/first_run/first_run_mac.mm
@@ -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.
@@ -6,7 +6,51 @@
#include "base/file_path.h"
#include "base/string_util.h"
+#include "chrome/browser/first_run/first_run_internal.h"
+#include "chrome/browser/importer/importer_host.h"
+#include "chrome/browser/importer/external_process_importer_host.h"
#include "chrome/browser/mac/master_prefs.h"
+#include "chrome/browser/process_singleton.h"
+
+namespace first_run {
+
+void AutoImport(
+ Profile* profile,
+ bool homepage_defined,
+ int import_items,
+ int dont_import_items,
+ bool search_engine_experiment,
+ bool randomize_search_engine_experiment,
+ bool make_chrome_default,
+ ProcessSingleton* process_singleton) {
+ // We need to avoid dispatching new tabs when we are importing because
+ // that will lead to data corruption or a crash. Because there is no UI for
+ // the import process, we pass NULL as the window to bring to the foreground
+ // when a CopyData message comes in; this causes the message to be silently
+ // discarded, which is the correct behavior during the import process.
+ process_singleton->Lock(NULL);
+
+ scoped_refptr<ImporterHost> importer_host;
+ // TODO(csilv,mirandac): Out-of-process import has only been qualified on
+ // MacOS X, so we will only use it on that platform since it is required.
+ // Remove this conditional logic once oop import is qualified for
+ // Linux/Windows. http://crbug.com/22142
+ importer_host = new ExternalProcessImporterHost;
+
+ internal::AutoImportPlatformCommon(importer_host,
+ profile,
+ homepage_defined,
+ import_items,
+ dont_import_items,
+ search_engine_experiment,
+ randomize_search_engine_experiment,
+ make_chrome_default);
+
+ process_singleton->Unlock();
+ first_run::CreateSentinel();
+}
+
+} //namespace first_run
bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) {
// http://crbug.com/48880
@@ -14,12 +58,6 @@ bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) {
}
// static
-void FirstRun::PlatformSetup() {
- // Things that Windows does here (creating a desktop icon, for example) are
- // not needed.
-}
-
-// static
FilePath FirstRun::MasterPrefsPath() {
return master_prefs::MasterPrefsPath();
}
diff --git a/chrome/browser/first_run/first_run_posix.cc b/chrome/browser/first_run/first_run_posix.cc
index 330f3fa..edced4e 100644
--- a/chrome/browser/first_run/first_run_posix.cc
+++ b/chrome/browser/first_run/first_run_posix.cc
@@ -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.
@@ -16,6 +16,47 @@
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/master_preferences_constants.h"
+namespace {
+
+// This class acts as an observer for the ImporterProgressObserver::ImportEnded
+// callback. When the import process is started, certain errors may cause
+// ImportEnded() to be called synchronously, but the typical case is that
+// ImportEnded() is called asynchronously. Thus we have to handle both cases.
+class ImportEndedObserver : public importer::ImporterProgressObserver {
+ public:
+ ImportEndedObserver() : ended_(false),
+ should_quit_message_loop_(false) {}
+ virtual ~ImportEndedObserver() {}
+
+ // importer::ImporterProgressObserver:
+ virtual void ImportStarted() OVERRIDE {}
+ virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {}
+ virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {}
+ virtual void ImportEnded() OVERRIDE {
+ ended_ = true;
+ if (should_quit_message_loop_)
+ MessageLoop::current()->Quit();
+ }
+
+ void set_should_quit_message_loop() {
+ should_quit_message_loop_ = true;
+ }
+
+ bool ended() {
+ return ended_;
+ }
+
+ private:
+ // Set if the import has ended.
+ bool ended_;
+
+ // Set by the client (via set_should_quit_message_loop) if, when the import
+ // ends, this class should quit the message loop.
+ bool should_quit_message_loop_;
+};
+
+} // namespace
+
namespace first_run {
namespace internal {
@@ -30,6 +71,34 @@ bool GetFirstRunSentinelFilePath(FilePath* path) {
return true;
}
+bool ImportSettings(Profile* profile,
+ scoped_refptr<ImporterHost> importer_host,
+ scoped_refptr<ImporterList> importer_list,
+ int items_to_import) {
+ const importer::SourceProfile& source_profile =
+ importer_list->GetSourceProfileAt(0);
+
+ // Ensure that importers aren't requested to import items that they do not
+ // support.
+ items_to_import &= source_profile.services_supported;
+
+ scoped_ptr<ImportEndedObserver> observer(new ImportEndedObserver);
+ importer_host->SetObserver(observer.get());
+ importer_host->StartImportSettings(source_profile,
+ profile,
+ items_to_import,
+ new ProfileWriter(profile),
+ true);
+ // If the import process has not errored out, block on it.
+ if (!observer->ended()) {
+ observer->set_should_quit_message_loop();
+ MessageLoop::current()->Run();
+ }
+
+ // Unfortunately there's no success/fail signal in ImporterHost.
+ return true;
+}
+
} // namespace internal
} // namespace first_run
diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc
index 4d10848..ec346cb 100644
--- a/chrome/browser/first_run/first_run_win.cc
+++ b/chrome/browser/first_run/first_run_win.cc
@@ -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.
@@ -27,6 +27,7 @@
#include "chrome/browser/importer/importer_host.h"
#include "chrome/browser/importer/importer_list.h"
#include "chrome/browser/importer/importer_progress_dialog.h"
+#include "chrome/browser/process_singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
@@ -135,6 +136,13 @@ bool CreateChromeQuickLaunchShortcut() {
true); // create if doesn't exist.
}
+void PlatformSetup() {
+ CreateChromeDesktopShortcut();
+ // Windows 7 has deprecated the quick launch bar.
+ if (base::win::GetVersion() < base::win::VERSION_WIN7)
+ CreateChromeQuickLaunchShortcut();
+}
+
} // namespace
bool FirstRun::LaunchSetupWithParam(const std::string& param,
@@ -182,7 +190,7 @@ void FirstRun::DoDelayedInstallExtensions() {
namespace {
-// This class is used by FirstRun::ImportSettings to determine when the import
+// This class is used by first_run::ImportSettings to determine when the import
// process has ended and what was the result of the operation as reported by
// the process exit code. This class executes in the context of the main chrome
// process.
@@ -302,53 +310,13 @@ bool DecodeImportParams(const std::string& encoded,
} // namespace
namespace first_run {
-
namespace internal{
-bool GetFirstRunSentinelFilePath(FilePath* path) {
- FilePath first_run_sentinel;
-
- FilePath exe_path;
- if (!PathService::Get(base::DIR_EXE, &exe_path))
- return false;
- if (InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
- first_run_sentinel = exe_path;
- } else {
- if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
- return false;
- }
-
- *path = first_run_sentinel.AppendASCII(kSentinelFile);
- return true;
-}
-
-} // namespace internal
-
-} // namespace first_run
-
-// static
-void FirstRun::PlatformSetup() {
- CreateChromeDesktopShortcut();
- // Windows 7 has deprecated the quick launch bar.
- if (base::win::GetVersion() < base::win::VERSION_WIN7)
- CreateChromeQuickLaunchShortcut();
-}
-
-// static
-FilePath FirstRun::MasterPrefsPath() {
- // The standard location of the master prefs is next to the chrome binary.
- FilePath master_prefs;
- if (!PathService::Get(base::DIR_EXE, &master_prefs))
- return FilePath();
- return master_prefs.AppendASCII(installer::kDefaultMasterPrefs);
-}
-
-// static
-bool FirstRun::ImportSettings(Profile* profile,
- int importer_type,
- int items_to_import,
- const FilePath& import_bookmarks_path,
- bool skip_first_run_ui) {
+bool ImportSettingsWin(Profile* profile,
+ int importer_type,
+ int items_to_import,
+ const FilePath& import_bookmarks_path,
+ bool skip_first_run_ui) {
const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
CommandLine import_cmd(cmdline.GetProgram());
@@ -394,12 +362,11 @@ bool FirstRun::ImportSettings(Profile* profile,
return (import_runner.exit_code() == content::RESULT_CODE_NORMAL_EXIT);
}
-// static
-bool FirstRun::ImportSettings(Profile* profile,
- scoped_refptr<ImporterHost> importer_host,
- scoped_refptr<ImporterList> importer_list,
- int items_to_import) {
- return ImportSettings(
+bool ImportSettings(Profile* profile,
+ scoped_refptr<ImporterHost> importer_host,
+ scoped_refptr<ImporterList> importer_list,
+ int items_to_import) {
+ return internal::ImportSettingsWin(
profile,
importer_list->GetSourceProfileAt(0).importer_type,
items_to_import,
@@ -407,6 +374,72 @@ bool FirstRun::ImportSettings(Profile* profile,
false);
}
+bool GetFirstRunSentinelFilePath(FilePath* path) {
+ FilePath first_run_sentinel;
+
+ FilePath exe_path;
+ if (!PathService::Get(base::DIR_EXE, &exe_path))
+ return false;
+ if (InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
+ first_run_sentinel = exe_path;
+ } else {
+ if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
+ return false;
+ }
+
+ *path = first_run_sentinel.AppendASCII(kSentinelFile);
+ return true;
+}
+
+} // namespace internal
+} // namespace first_run
+
+namespace first_run {
+
+void AutoImport(
+ Profile* profile,
+ bool homepage_defined,
+ int import_items,
+ int dont_import_items,
+ bool search_engine_experiment,
+ bool randomize_search_engine_experiment,
+ bool make_chrome_default,
+ ProcessSingleton* process_singleton) {
+#if !defined(USE_AURA)
+ // We need to avoid dispatching new tabs when we are importing because
+ // that will lead to data corruption or a crash. Because there is no UI for
+ // the import process, we pass NULL as the window to bring to the foreground
+ // when a CopyData message comes in; this causes the message to be silently
+ // discarded, which is the correct behavior during the import process.
+ process_singleton->Lock(NULL);
+
+ PlatformSetup();
+
+ scoped_refptr<ImporterHost> importer_host;
+ importer_host = new ImporterHost;
+
+ internal::AutoImportPlatformCommon(importer_host, profile, homepage_defined,
+ import_items, dont_import_items,
+ search_engine_experiment,
+ randomize_search_engine_experiment,
+ make_chrome_default);
+
+ process_singleton->Unlock();
+ CreateSentinel();
+#endif // !defined(USE_AURA)
+}
+
+} // namespace first_run
+
+// static
+FilePath FirstRun::MasterPrefsPath() {
+ // The standard location of the master prefs is next to the chrome binary.
+ FilePath master_prefs;
+ if (!PathService::Get(base::DIR_EXE, &master_prefs))
+ return FilePath();
+ return master_prefs.AppendASCII(installer::kDefaultMasterPrefs);
+}
+
#if !defined(USE_AURA)
int FirstRun::ImportFromBrowser(Profile* profile,
const CommandLine& cmdline) {