diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 04:45:54 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 04:45:54 +0000 |
commit | f988638e6ea5a3f16e289be9ac7ffd853f7a13e4 (patch) | |
tree | 21a390713263cede93537c0651656e83acbc5965 /chrome/browser | |
parent | 39b22b7c4c5c45183a5224449f0f82d7998a70e0 (diff) | |
download | chromium_src-f988638e6ea5a3f16e289be9ac7ffd853f7a13e4.zip chromium_src-f988638e6ea5a3f16e289be9ac7ffd853f7a13e4.tar.gz chromium_src-f988638e6ea5a3f16e289be9ac7ffd853f7a13e4.tar.bz2 |
Allow the use of the master_preferences file in Linux.
Also refactor FirstRunTabs to use GURL instead of wstring.
BUG=none
TEST=Add master_preferences file to directory containing the chrome binary and
execute chrome with the --first-run option.
Original patch by bgmerrell@gmail.com at
http://codereview.chromium.org/551160
Review URL: http://codereview.chromium.org/796001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_main.cc | 28 | ||||
-rw-r--r-- | chrome/browser/first_run.cc | 19 | ||||
-rw-r--r-- | chrome/browser/first_run.h | 7 | ||||
-rw-r--r-- | chrome/browser/first_run_gtk.cc | 83 | ||||
-rw-r--r-- | chrome/browser/first_run_win.cc | 15 |
5 files changed, 120 insertions, 32 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 91c6cad..00f6755 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -302,34 +302,32 @@ void SetFileDescriptorLimit(unsigned int max_descriptors) { } #endif -#if defined(OS_WIN) +#if !defined(OS_MACOSX) void AddFirstRunNewTabs(BrowserInit* browser_init, - const std::vector<std::wstring>& new_tabs) { - for (std::vector<std::wstring>::const_iterator it = new_tabs.begin(); + const std::vector<GURL>& new_tabs) { + for (std::vector<GURL>::const_iterator it = new_tabs.begin(); it != new_tabs.end(); ++it) { - GURL url(*it); - if (url.is_valid()) - browser_init->AddFirstRunTab(url); + if (it->is_valid()) + browser_init->AddFirstRunTab(*it); } } void AddDefaultBookmarks(BrowserInit* browser_init, - const std::vector<std::wstring>& bookmarks) { - for (std::vector<std::wstring>::const_iterator it = bookmarks.begin(); + const std::vector<GURL>& bookmarks) { + for (std::vector<GURL>::const_iterator it = bookmarks.begin(); it != bookmarks.end(); ++it) { - GURL url(*it); - if (url.is_valid()) - browser_init->AddDefaultBookmark(url); + if (it->is_valid()) + browser_init->AddDefaultBookmark(*it); } } -#else +#else // OS_MACOSX // TODO(cpu): implement first run experience for other platforms. void AddFirstRunNewTabs(BrowserInit* browser_init, - const std::vector<std::wstring>& new_tabs) { + const std::vector<GURL>& new_tabs) { } void AddDefaultBookmarks(BrowserInit* browser_init, - const std::vector<std::wstring>& bookmarks) { + const std::vector<GURL>& bookmarks) { } #endif @@ -625,7 +623,6 @@ int BrowserMain(const MainFunctionParams& parameters) { FirstRun::MasterPrefs master_prefs = {0}; bool first_run_ui_bypass = false; if (is_first_run) { -#if defined(OS_WIN) // On first run, we need to process the master preferences before the // browser's profile_manager object is created, but after ResourceBundle // is initialized. @@ -638,7 +635,6 @@ int BrowserMain(const MainFunctionParams& parameters) { // The master prefs might specify a set of initial bookmarks. if (master_prefs.bookmarks.size()) AddDefaultBookmarks(&browser_init, master_prefs.bookmarks); -#endif // OS_WIN // If we are running in App mode, we do not want to show the importer // (first run) UI. diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc index d9ca211..dacf4f6 100644 --- a/chrome/browser/first_run.cc +++ b/chrome/browser/first_run.cc @@ -100,3 +100,22 @@ bool FirstRun::SetShowWelcomePagePref() { return true; } +bool FirstRun::SetOEMFirstRunBubblePref() { + PrefService* local_state = g_browser_process->local_state(); + if (!local_state) + return false; + if (!local_state->FindPreference(prefs::kShouldUseOEMFirstRunBubble)) { + local_state->RegisterBooleanPref(prefs::kShouldUseOEMFirstRunBubble, + false); + local_state->SetBoolean(prefs::kShouldUseOEMFirstRunBubble, true); + } + return true; +} + +#if defined(OS_MACOSX) +bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, + const FilePath& master_prefs_path, MasterPrefs* out_prefs) { + NOTIMPLEMENTED(); + return false; +} +#endif diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index 08a101a4..7741e77 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -11,6 +11,7 @@ #include "app/gfx/native_widget_types.h" #include "base/basictypes.h" #include "chrome/browser/browser_process_impl.h" +#include "googleurl/src/gurl.h" class CommandLine; class FilePath; @@ -34,8 +35,8 @@ class FirstRun { bool homepage_defined; int do_import_items; int dont_import_items; - std::vector<std::wstring> new_tabs; - std::vector<std::wstring> bookmarks; + std::vector<GURL> new_tabs; + std::vector<GURL> bookmarks; }; #if defined(OS_WIN) // Creates the desktop shortcut to chrome for the current user. Returns @@ -49,6 +50,7 @@ class FirstRun { // FirstRun::ImportSettings(). This function might or might not show // a visible UI depending on the cmdline parameters. static int ImportNow(Profile* profile, const CommandLine& cmdline); +#endif // OS_WIN // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function locates this file from @@ -68,7 +70,6 @@ class FirstRun { static bool ProcessMasterPreferences(const FilePath& user_data_dir, const FilePath& master_prefs_path, MasterPrefs* out_prefs); -#endif // OS_WIN // Returns true if this is the first time chrome is run for this user. static bool IsChromeFirstRun(); diff --git a/chrome/browser/first_run_gtk.cc b/chrome/browser/first_run_gtk.cc index 3d4a091..59f3041 100644 --- a/chrome/browser/first_run_gtk.cc +++ b/chrome/browser/first_run_gtk.cc @@ -4,7 +4,20 @@ #include "chrome/browser/first_run.h" +#include "app/resource_bundle.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/path_service.h" #include "chrome/browser/gtk/first_run_dialog.h" +#include "chrome/browser/profile_manager.h" +#include "chrome/browser/shell_integration.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/result_codes.h" +#include "chrome/installer/util/google_update_settings.h" +#include "chrome/installer/util/master_preferences.h" +#include "chrome/installer/util/util_constants.h" +#include "googleurl/src/gurl.h" bool OpenFirstRunDialog(Profile* profile, bool homepage_defined, int import_items, @@ -12,3 +25,73 @@ bool OpenFirstRunDialog(Profile* profile, bool homepage_defined, ProcessSingleton* process_singleton) { return FirstRunDialog::Show(profile, process_singleton); } + +FilePath GetDefaultPrefFilePath(bool create_profile_dir, + const FilePath& user_data_dir) { + FilePath default_pref_dir = + ProfileManager::GetDefaultProfileDir(user_data_dir); + if (create_profile_dir) { + if (!file_util::PathExists(default_pref_dir)) { + if (!file_util::CreateDirectory(default_pref_dir)) + return FilePath(); + } + } + return ProfileManager::GetProfilePrefsPath(default_pref_dir); +} + +bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, + const FilePath& master_prefs_path, + MasterPrefs* out_prefs) { + DCHECK(!user_data_dir.empty()); + FilePath master_prefs = master_prefs_path; + if (master_prefs.empty()) { + // The default location of the master prefs is next to the chrome binary. + if (!PathService::Get(base::DIR_EXE, &master_prefs)) + return true; + master_prefs = + master_prefs.AppendASCII(installer_util::kDefaultMasterPrefs); + } + + scoped_ptr<DictionaryValue> prefs( + installer_util::ParseDistributionPreferences(master_prefs)); + if (!prefs.get()) + return true; + + out_prefs->new_tabs = installer_util::GetFirstRunTabs(prefs.get()); + + std::string not_used; + out_prefs->homepage_defined = prefs->GetString(prefs::kHomePage, ¬_used); + + bool value = false; + if (installer_util::GetDistroBooleanPreference(prefs.get(), + installer_util::master_preferences::kAltFirstRunBubble, &value) && value) + FirstRun::SetOEMFirstRunBubblePref(); + + 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)) + return true; + + // Note we are skipping all other master preferences if skip-first-run-ui + // is *not* specified. + if (!installer_util::GetDistroBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroSkipFirstRunPref, &value) || + !value) + return true; + + // From here on we won't show first run so we need to do the work to set the + // required state given that FirstRunView is not going to be called. + FirstRun::SetShowFirstRunBubblePref(); + + if (installer_util::GetDistroBooleanPreference(prefs.get(), + installer_util::master_preferences::kDistroShowWelcomePage, &value) && + value) + FirstRun::SetShowWelcomePagePref(); + + return false; +} + diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc index c57126c..2f3eda7 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -235,7 +235,8 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, // TODO(port): port installer_util and use this. if (!PathService::Get(base::DIR_EXE, &master_prefs)) return true; - master_prefs = master_prefs.Append(installer_util::kDefaultMasterPrefs); + master_prefs = + master_prefs.AppendASCII(installer_util::kDefaultMasterPrefs); } scoped_ptr<DictionaryValue> prefs( @@ -705,18 +706,6 @@ int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) { return observer.import_result(); } -bool FirstRun::SetOEMFirstRunBubblePref() { - PrefService* local_state = g_browser_process->local_state(); - if (!local_state) - return false; - if (!local_state->FindPreference(prefs::kShouldUseOEMFirstRunBubble)) { - local_state->RegisterBooleanPref(prefs::kShouldUseOEMFirstRunBubble, - false); - local_state->SetBoolean(prefs::kShouldUseOEMFirstRunBubble, true); - } - return true; -} - ////////////////////////////////////////////////////////////////////////// namespace { |