diff options
-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, 90 insertions, 114 deletions
@@ -71,4 +71,3 @@ 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 1fe0e88..3913c1d 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -905,14 +905,12 @@ 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. - // TODO(port): Port to Mac +#if defined(OS_WIN) 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 7304494..c6d7ac7 100644 --- a/chrome/browser/first_run.cc +++ b/chrome/browser/first_run.cc @@ -14,10 +14,8 @@ #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 { @@ -114,54 +112,6 @@ 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) { @@ -169,27 +119,3 @@ 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 2fe71ce..d8a5cfd 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -10,8 +10,6 @@ #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" @@ -47,12 +45,11 @@ 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(); -#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. + // 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 // The master preferences is a JSON file with the same entries as the // 'Default\Preferences' file. This function locates this file from @@ -103,19 +100,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); }; @@ -178,27 +175,6 @@ 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 0620baa..0e0925d 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -569,6 +569,43 @@ 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); } @@ -656,6 +693,34 @@ 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); @@ -692,6 +757,19 @@ 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 { @@ -968,4 +1046,3 @@ Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { TryChromeDialog td; return td.ShowModal(); } - |