diff options
author | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-23 21:26:03 +0000 |
---|---|---|
committer | cpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-23 21:26:03 +0000 |
commit | 64747810906162dda8a49bfab5dd15036be67228 (patch) | |
tree | 00282e2acb141d89dfb8c739ed0429b3cb4aa434 /chrome/browser/first_run_gtk.cc | |
parent | f59f116d39a53d20b1b2647da4a2fdcb1ffa21ad (diff) | |
download | chromium_src-64747810906162dda8a49bfab5dd15036be67228.zip chromium_src-64747810906162dda8a49bfab5dd15036be67228.tar.gz chromium_src-64747810906162dda8a49bfab5dd15036be67228.tar.bz2 |
Enable silent import of bookmarks for Linux
Patch contributed by Brian G. Merrell (bgmerrell)
- Add ImportBookmarks first run function for Linux, which implements only a
piece of Windows' ImportSettings function
- Use string16 instead of wstring, which required changing some code in the
master_preferences files and the Windows-specific first run code.
With this patch, bookmarks can be silently imported the same way that they
are silently imported in Windows. See the bug below for specifics.
BUG=32728
TEST=unit test or specify "import_bookmarks_from_file" in the
master_preferences file and run chromium with --first-run (see
http://code.google.com/p/chromium/issues/detail?id=32728#c11 for details)
Review URL: http://codereview.chromium.org/1733012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45491 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run_gtk.cc')
-rw-r--r-- | chrome/browser/first_run_gtk.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/chrome/browser/first_run_gtk.cc b/chrome/browser/first_run_gtk.cc index 87406c4..a424d60 100644 --- a/chrome/browser/first_run_gtk.cc +++ b/chrome/browser/first_run_gtk.cc @@ -4,6 +4,7 @@ #include "chrome/browser/first_run.h" +#include "app/app_switches.h" #include "app/resource_bundle.h" #include "base/file_path.h" #include "base/file_util.h" @@ -93,6 +94,48 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, value) FirstRun::SetShowWelcomePagePref(); + // 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 (!FirstRun::CreateSentinel()) + return false; + + std::wstring import_bookmarks_path; + installer_util::GetDistroStringPreference(prefs.get(), + installer_util::master_preferences::kDistroImportBookmarksFromFilePref, + &import_bookmarks_path); + + if (!import_bookmarks_path.empty()) { + // There are bookmarks to import from a file. + if (!FirstRun::ImportBookmarks(import_bookmarks_path)) { + LOG(WARNING) << "silent bookmark import failed"; + } + } return false; } +// 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 std::wstring& import_bookmarks_path) { + const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); + CommandLine import_cmd(cmdline.GetProgram()); + + // Propagate user data directory switch. + if (cmdline.HasSwitch(switches::kUserDataDir)) { + import_cmd.AppendSwitchWithValue( + switches::kUserDataDir, + cmdline.GetSwitchValueASCII(switches::kUserDataDir)); + } + // Since ImportSettings is called before the local state is stored on disk + // we pass the language as an argument. GetApplicationLocale checks the + // current command line as fallback. + import_cmd.AppendSwitchWithValue( + switches::kLang, + ASCIIToWide(g_browser_process->GetApplicationLocale())); + + import_cmd.CommandLine::AppendSwitchWithValue( + switches::kImportFromFile, import_bookmarks_path); + // Time to launch the process that is going to do the import. We'll wait + // for the process to return. + return base::LaunchApp(import_cmd, true, false, NULL); +} |