diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 22:01:25 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 22:01:25 +0000 |
commit | 594f4ff352685bb83b71d1402264bc2cf2116e67 (patch) | |
tree | 6f1807217f5e8bc50603e5b20008e7160d49dbe7 | |
parent | 26b0f376d66975c03c3d24afd72257f34c9bb5f6 (diff) | |
download | chromium_src-594f4ff352685bb83b71d1402264bc2cf2116e67.zip chromium_src-594f4ff352685bb83b71d1402264bc2cf2116e67.tar.gz chromium_src-594f4ff352685bb83b71d1402264bc2cf2116e67.tar.bz2 |
Add import_bookmarks_from_file option to master pref that
sliently import bookmarks from file in first run.
BUG=32728
TEST=unit test
Review URL: http://codereview.chromium.org/1257001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42545 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/first_run.h | 6 | ||||
-rw-r--r-- | chrome/browser/first_run_win.cc | 31 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 21 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.h | 7 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences_constants.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences_constants.h | 3 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences_unittest.cc | 11 |
7 files changed, 76 insertions, 5 deletions
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index 910edf56..d8a5cfd 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -106,6 +106,12 @@ class FirstRun { // 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); #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 e4959e0..0e0925d 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -355,13 +355,18 @@ bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir, value) import_items += importer::HOME_PAGE; - if (import_items) { + std::wstring import_bookmarks_path; + installer_util::GetDistroStringPreference(prefs.get(), + installer_util::master_preferences::kDistroImportBookmarksFromFilePref, + &import_bookmarks_path); + + if (import_items || !import_bookmarks_path.empty()) { // There is something to import from the default browser. This launches // the importer process and blocks until done or until it fails. scoped_refptr<ImporterHost> importer_host = new ImporterHost(); if (!FirstRun::ImportSettings(NULL, importer_host->GetSourceProfileInfoAt(0).browser_type, - import_items, NULL)) { + import_items, import_bookmarks_path, NULL)) { LOG(WARNING) << "silent import failed"; } } @@ -625,7 +630,9 @@ bool DecodeImportParams(const std::wstring& encoded, } // namespace bool FirstRun::ImportSettings(Profile* profile, int browser_type, - int items_to_import, HWND parent_window) { + int items_to_import, + const std::wstring& import_bookmarks_path, + HWND parent_window) { const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); CommandLine import_cmd(cmdline.GetProgram()); // Propagate user data directory switch. @@ -642,8 +649,15 @@ bool FirstRun::ImportSettings(Profile* profile, int browser_type, switches::kLang, ASCIIToWide(g_browser_process->GetApplicationLocale())); - import_cmd.CommandLine::AppendSwitchWithValue(switches::kImport, - EncodeImportParams(browser_type, items_to_import, parent_window)); + if (items_to_import) { + import_cmd.CommandLine::AppendSwitchWithValue(switches::kImport, + EncodeImportParams(browser_type, items_to_import, parent_window)); + } + + if (!import_bookmarks_path.empty()) { + import_cmd.CommandLine::AppendSwitchWithValue( + switches::kImportFromFile, import_bookmarks_path.c_str()); + } if (cmdline.HasSwitch(switches::kChromeFrame)) { import_cmd.AppendSwitch(switches::kChromeFrame); @@ -672,6 +686,13 @@ bool FirstRun::ImportSettings(Profile* profile, int browser_type, return (import_runner.exit_code() == ResultCodes::NORMAL_EXIT); } +bool FirstRun::ImportSettings(Profile* profile, int browser_type, + int items_to_import, + HWND parent_window) { + return ImportSettings(profile, browser_type, items_to_import, + std::wstring(), parent_window); +} + int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) { std::wstring file_path = cmdline.GetSwitchValue(switches::kImportFromFile); if (file_path.empty()) { diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index 2a6a4e7..3406e33 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -65,6 +65,27 @@ bool GetDistroBooleanPreference(const DictionaryValue* prefs, return true; } +bool GetDistroStringPreference(const DictionaryValue* prefs, + const std::wstring& name, + std::wstring* value) { + if (!prefs || !value) + return false; + + DictionaryValue* distro = NULL; + if (!prefs->GetDictionary(kDistroDict, &distro) || !distro) + return false; + + std::wstring str_value; + if (!distro->GetString(name, &str_value)) + return false; + + if (str_value.empty()) + return false; + + *value = str_value; + return true; +} + bool GetDistroIntegerPreference(const DictionaryValue* prefs, const std::wstring& name, int* value) { diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h index e244e96..8d64be5 100644 --- a/chrome/installer/util/master_preferences.h +++ b/chrome/installer/util/master_preferences.h @@ -34,6 +34,12 @@ bool GetDistroBooleanPreference(const DictionaryValue* prefs, const std::wstring& name, bool* value); +// This function gets value of a string preference from master +// preferences. Returns true if the value is read successfully, otherwise false. +bool GetDistroStringPreference(const DictionaryValue* prefs, + const std::wstring& name, + std::wstring* value); + // This function gets value of an integer preference from master // preferences. Returns true if the value is read successfully, otherwise false. bool GetDistroIntegerPreference(const DictionaryValue* prefs, @@ -53,6 +59,7 @@ bool GetDistroIntegerPreference(const DictionaryValue* prefs, // "chrome_shortcut_icon_index": 0, // "create_all_shortcuts": true, // "import_bookmarks": false, +// "import_bookmarks_from_file": "c:\\path", // "import_history": false, // "import_home_page": false, // "import_search_engine": true, diff --git a/chrome/installer/util/master_preferences_constants.cc b/chrome/installer/util/master_preferences_constants.cc index 6519e4c..cae9a6d 100644 --- a/chrome/installer/util/master_preferences_constants.cc +++ b/chrome/installer/util/master_preferences_constants.cc @@ -11,6 +11,8 @@ namespace master_preferences { const wchar_t kChromeShortcutIconIndex[] = L"chrome_shortcut_icon_index"; const wchar_t kCreateAllShortcuts[] = L"create_all_shortcuts"; const wchar_t kDistroImportBookmarksPref[] = L"import_bookmarks"; + const wchar_t kDistroImportBookmarksFromFilePref[] = + L"import_bookmarks_from_file"; const wchar_t kDistroImportHistoryPref[] = L"import_history"; const wchar_t kDistroImportHomePagePref[] = L"import_home_page"; const wchar_t kDistroImportSearchPref[] = L"import_search_engine"; diff --git a/chrome/installer/util/master_preferences_constants.h b/chrome/installer/util/master_preferences_constants.h index 5bcd5d3..c67d7ab 100644 --- a/chrome/installer/util/master_preferences_constants.h +++ b/chrome/installer/util/master_preferences_constants.h @@ -25,6 +25,9 @@ extern const wchar_t kChromeShortcutIconIndex[]; extern const wchar_t kCreateAllShortcuts[]; // Boolean pref that triggers silent import of the default browser bookmarks. extern const wchar_t kDistroImportBookmarksPref[]; +// String pref that triggers silent import of bookmarks from the html file at +// given path. +extern const wchar_t kDistroImportBookmarksFromFilePref[]; // Boolean pref that triggers silent import of the default browser history. extern const wchar_t kDistroImportHistoryPref[]; // Boolean pref that triggers silent import of the default browser homepage. diff --git a/chrome/installer/util/master_preferences_unittest.cc b/chrome/installer/util/master_preferences_unittest.cc index 65fcc6d..ba91cbc 100644 --- a/chrome/installer/util/master_preferences_unittest.cc +++ b/chrome/installer/util/master_preferences_unittest.cc @@ -40,6 +40,7 @@ TEST_F(MasterPreferencesTest, ParseDistroParams) { " \"import_search_engine\": true,\n" " \"import_history\": true,\n" " \"import_bookmarks\": true,\n" + " \"import_bookmarks_from_file\": \"c:\\\\foo\",\n" " \"import_home_page\": true,\n" " \"create_all_shortcuts\": true,\n" " \"do_not_launch_chrome\": true,\n" @@ -79,6 +80,11 @@ TEST_F(MasterPreferencesTest, ParseDistroParams) { EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(), installer_util::master_preferences::kDistroImportBookmarksPref, &value) && value); + std::wstring str_value; + EXPECT_TRUE(installer_util::GetDistroStringPreference(prefs.get(), + installer_util::master_preferences::kDistroImportBookmarksFromFilePref, + &str_value)); + EXPECT_STREQ(L"c:\\foo", str_value.c_str()); EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(), installer_util::master_preferences::kDistroImportHomePagePref, &value) && value); @@ -130,6 +136,7 @@ TEST_F(MasterPreferencesTest, ParseMissingDistroParams) { " \"skip_first_run_ui\": true,\n" " \"import_search_engine\": true,\n" " \"import_bookmarks\": false,\n" + " \"import_bookmarks_from_file\": \"\",\n" " \"create_all_shortcuts\": true,\n" " \"do_not_launch_chrome\": true,\n" " \"chrome_shortcut_icon_index\": \"bac\"\n" @@ -155,6 +162,10 @@ TEST_F(MasterPreferencesTest, ParseMissingDistroParams) { EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(), installer_util::master_preferences::kDistroImportBookmarksPref, &value)); EXPECT_FALSE(value); + std::wstring str_value; + EXPECT_FALSE(installer_util::GetDistroStringPreference(prefs.get(), + installer_util::master_preferences::kDistroImportBookmarksFromFilePref, + &str_value)); EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(), installer_util::master_preferences::kDistroImportHomePagePref, &value)); |