From 02aae3fac31e8ac28c5ee8c4b70e70dcef599dd0 Mon Sep 17 00:00:00 2001 From: "huanr@chromium.org" <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Mon, 22 Mar 2010 22:31:27 +0000 Subject: Add the option of importing bookmarks from file to first run. BUG=32728 TEST=run with --import-from-file Review URL: http://codereview.chromium.org/1077007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42266 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser_main.cc | 6 ++++-- chrome/browser/first_run.h | 15 ++++++++++---- chrome/browser/first_run_win.cc | 44 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 7 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index c160379..0971b4a 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -495,7 +495,8 @@ int BrowserMain(const MainFunctionParams& parameters) { parsed_command_line.HasSwitch(switches::kFirstRun); scoped_ptr<BrowserProcessImpl> browser_process; - if (parsed_command_line.HasSwitch(switches::kImport)) { + if (parsed_command_line.HasSwitch(switches::kImport) || + parsed_command_line.HasSwitch(switches::kImportFromFile)) { // We use different BrowserProcess when importing so no GoogleURLTracker is // instantiated (as it makes a URLRequest and we don't have an IO thread, // see bug #1292702). @@ -817,7 +818,8 @@ int BrowserMain(const MainFunctionParams& parameters) { // Importing other browser settings is done in a browser-like process // that exits when this task has finished. #if defined(OS_WIN) - if (parsed_command_line.HasSwitch(switches::kImport)) + if (parsed_command_line.HasSwitch(switches::kImport) || + parsed_command_line.HasSwitch(switches::kImportFromFile)) return FirstRun::ImportNow(profile, parsed_command_line); #endif diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index 2bcecb0..910edf56 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -45,10 +45,9 @@ class FirstRun { // Creates the quick launch shortcut to chrome for the current user. Returns // false if it fails. It will overwrite the shortcut if it exists. static bool CreateChromeQuickLaunchShortcut(); - // Import browser items in this process. The browser and the items to - // import are encoded int the command line. This function is paired with - // FirstRun::ImportSettings(). This function might or might not show - // a visible UI depending on the cmdline parameters. + // Import bookmarks and browser items in this process. This function is + // paired with 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 @@ -100,6 +99,14 @@ class FirstRun { static bool SetShowWelcomePagePref(); private: +#if defined(OS_WIN) + // Import bookmarks from an html file. The path to the file is provided in + // the command line. + static int ImportFromFile(Profile* profile, const CommandLine& cmdline); + // Import browser items in this process. The browser and the items to + // import are encoded int the command line. + static int ImportFromBrowser(Profile* profile, const CommandLine& cmdline); +#endif // OS_WIN // This class is for scoping purposes. DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun); }; diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc index e3a3b52..e4959e0 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -672,7 +672,36 @@ bool FirstRun::ImportSettings(Profile* profile, int browser_type, return (import_runner.exit_code() == ResultCodes::NORMAL_EXIT); } -int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) { +int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) { + std::wstring file_path = cmdline.GetSwitchValue(switches::kImportFromFile); + if (file_path.empty()) { + NOTREACHED(); + return false; + } + scoped_refptr<ImporterHost> importer_host = new ImporterHost(); + FirstRunImportObserver observer; + + importer_host->set_headless(); + + ProfileInfo profile_info; + profile_info.browser_type = importer::BOOKMARKS_HTML; + profile_info.source_path = file_path; + + StartImportingWithUI( + NULL, + importer::FAVORITES, + importer_host, + profile_info, + profile, + &observer, + true); + + observer.RunLoop(); + return observer.import_result(); +} + +int FirstRun::ImportFromBrowser(Profile* profile, + const CommandLine& cmdline) { std::wstring import_info = cmdline.GetSwitchValue(switches::kImport); if (import_info.empty()) { NOTREACHED(); @@ -707,6 +736,19 @@ int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) { return observer.import_result(); } +int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) { + int return_code = true; + if (cmdline.HasSwitch(switches::kImportFromFile)) { + // Silently import preset bookmarks from file. + // This is an OEM scenario. + return_code = ImportFromFile(profile, cmdline); + } + if (cmdline.HasSwitch(switches::kImport)) { + return_code = ImportFromBrowser(profile, cmdline); + } + return return_code; +} + ////////////////////////////////////////////////////////////////////////// namespace { -- cgit v1.1