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 | |
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
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 6 | ||||
-rw-r--r-- | chrome/browser/first_run.cc | 74 | ||||
-rw-r--r-- | chrome/browser/first_run.h | 44 | ||||
-rw-r--r-- | chrome/browser/first_run_win.cc | 79 |
5 files changed, 114 insertions, 90 deletions
@@ -71,3 +71,4 @@ Chamal De Silva <chamal.desilva@gmail.com> Jay Soffian <jaysoffian@gmail.com> Brian G. Merrell <bgmerrell@gmail.com> Matthew Willis <appamatto@gmail.com> +Novell Inc. diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 3913c1d..1fe0e88 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -905,12 +905,14 @@ int BrowserMain(const MainFunctionParams& parameters) { OptionallyRunChromeOSLoginManager(parsed_command_line); } +#if !defined(OS_MACOSX) // Importing other browser settings is done in a browser-like process // that exits when this task has finished. -#if defined(OS_WIN) + // TODO(port): Port to Mac if (parsed_command_line.HasSwitch(switches::kImport) || - parsed_command_line.HasSwitch(switches::kImportFromFile)) + parsed_command_line.HasSwitch(switches::kImportFromFile)) { return FirstRun::ImportNow(profile, parsed_command_line); + } #endif // When another process is running, use it instead of starting us. 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(); +} + diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index d8a5cfd..2fe71ce 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -10,6 +10,8 @@ #include "base/basictypes.h" #include "chrome/browser/browser_process_impl.h" +#include "chrome/browser/importer/importer.h" +#include "chrome/common/result_codes.h" #include "gfx/native_widget_types.h" #include "googleurl/src/gurl.h" @@ -45,11 +47,12 @@ 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 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 + // Import bookmarks and/or browser items (depending on platform support) + // 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); // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function locates this file from @@ -100,19 +103,19 @@ class FirstRun { 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); // Imports settings in a separate process. It is the implementation of the // public version. static bool ImportSettings(Profile* profile, int browser_type, int items_to_import, const std::wstring& import_path, gfx::NativeView parent_window); + // 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 + // 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); // This class is for scoping purposes. DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun); }; @@ -175,6 +178,27 @@ class FirstRunBrowserProcess : public BrowserProcessImpl { DISALLOW_COPY_AND_ASSIGN(FirstRunBrowserProcess); }; +// This class is used by FirstRun::ImportNow to get notified of the outcome of +// the import operation. It differs from ImportProcessRunner in that this +// class executes in the context of importing child process. +// The values that it handles are meant to be used as the process exit code. +class FirstRunImportObserver : public ImportObserver { + public: + FirstRunImportObserver() + : loop_running_(false), import_result_(ResultCodes::NORMAL_EXIT) { + } + int import_result() const; + virtual void ImportCanceled(); + virtual void ImportComplete(); + void RunLoop(); + private: + void Finish(); + bool loop_running_; + int import_result_; + DISALLOW_COPY_AND_ASSIGN(FirstRunImportObserver); +}; + + // Show the First Run UI to the user, allowing them to create shortcuts for // the app, import their bookmarks and other data from another browser into // |profile| and perhaps some other tasks. diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc index 0e0925d..0620baa 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -569,43 +569,6 @@ class HungImporterMonitor : public WorkerThreadTicker::Callback { DISALLOW_COPY_AND_ASSIGN(HungImporterMonitor); }; -// This class is used by FirstRun::ImportNow to get notified of the outcome of -// the import operation. It differs from ImportProcessRunner in that this -// class executes in the context of importing child process. -// The values that it handles are meant to be used as the process exit code. -class FirstRunImportObserver : public ImportObserver { - public: - FirstRunImportObserver() - : loop_running_(false), import_result_(ResultCodes::NORMAL_EXIT) { - } - int import_result() const { - return import_result_; - } - virtual void ImportCanceled() { - import_result_ = ResultCodes::IMPORTER_CANCEL; - Finish(); - } - virtual void ImportComplete() { - import_result_ = ResultCodes::NORMAL_EXIT; - Finish(); - } - - void RunLoop() { - loop_running_ = true; - MessageLoop::current()->Run(); - } - - private: - void Finish() { - if (loop_running_) - MessageLoop::current()->Quit(); - } - - bool loop_running_; - int import_result_; - DISALLOW_COPY_AND_ASSIGN(FirstRunImportObserver); -}; - std::wstring EncodeImportParams(int browser_type, int options, HWND window) { return StringPrintf(L"%d@%d@%d", browser_type, options, window); } @@ -693,34 +656,6 @@ bool FirstRun::ImportSettings(Profile* profile, int browser_type, std::wstring(), parent_window); } -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); @@ -757,19 +692,6 @@ int FirstRun::ImportFromBrowser(Profile* profile, 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 { @@ -1046,3 +968,4 @@ Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { TryChromeDialog td; return td.ShowModal(); } + |