diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 23:11:46 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 23:11:46 +0000 |
commit | e67ced4317b42834974c31672bdc1b154f569b28 (patch) | |
tree | 5afc10ed18d8fca30071fc1e34855216c3e6d1f0 /chrome/browser/first_run.cc | |
parent | 61c9f03381e1fe7bdad521013fa43e4652a81fcc (diff) | |
download | chromium_src-e67ced4317b42834974c31672bdc1b154f569b28.zip chromium_src-e67ced4317b42834974c31672bdc1b154f569b28.tar.gz chromium_src-e67ced4317b42834974c31672bdc1b154f569b28.tar.bz2 |
Port the option to import bookmarks from a file to Linux
- Call ImportNow from browser_main.cc
- Move necessary functions and a class from first_run_win.cc to
first_run.cc and update first_run.h accordingly.
- Add some #defines for different OSes and some TODO(port) comments.
These changes will allow the use of the --import-from-file option to
import bookmarks from a file at first run.
I have built and tested this on Linux and Windows.
BUG=32728
TEST=run with --import-from-file
Patch from Brian G. Merrell <bgmerrell@gmail.com>
Review URL: http://codereview.chromium.org/1515004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43277 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run.cc')
-rw-r--r-- | chrome/browser/first_run.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc index c6d7ac7..7304494 100644 --- a/chrome/browser/first_run.cc +++ b/chrome/browser/first_run.cc @@ -14,8 +14,10 @@ #include "base/file_util.h" #include "base/path_service.h" +#include "chrome/browser/importer/importer.h" #include "chrome/browser/pref_service.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" namespace { @@ -112,6 +114,54 @@ bool FirstRun::SetOEMFirstRunBubblePref() { return true; } +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(); +} + +// TODO(port): Import switches need ported to both Mac and Linux. Not all +// import switches here are implemented for Linux. None are implemented for +// Mac (as this function will not be called on Mac). +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)) { +#if defined(OS_WIN) + return_code = ImportFromBrowser(profile, cmdline); +#else + NOTIMPLEMENTED(); +#endif + } + return return_code; +} + #if defined(OS_MACOSX) bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, const FilePath& master_prefs_path, MasterPrefs* out_prefs) { @@ -119,3 +169,27 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, return true; } #endif + +int FirstRunImportObserver::import_result() const { + return import_result_; +} + +void FirstRunImportObserver::ImportCanceled() { + import_result_ = ResultCodes::IMPORTER_CANCEL; + Finish(); +} +void FirstRunImportObserver::ImportComplete() { + import_result_ = ResultCodes::NORMAL_EXIT; + Finish(); +} + +void FirstRunImportObserver::RunLoop() { + loop_running_ = true; + MessageLoop::current()->Run(); +} + +void FirstRunImportObserver::Finish() { + if (loop_running_) + MessageLoop::current()->Quit(); +} + |