diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-05 19:22:51 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-05 19:22:51 +0000 |
commit | 5072aee46aa709d9a67a3c988c5934bec67d71e5 (patch) | |
tree | 214a9ba02d8b022b58ef50b112762a5c02cddf9b /chrome/browser | |
parent | 636b49b9cad66fe061fe4d6e1f69bdf4bee1a780 (diff) | |
download | chromium_src-5072aee46aa709d9a67a3c988c5934bec67d71e5.zip chromium_src-5072aee46aa709d9a67a3c988c5934bec67d71e5.tar.gz chromium_src-5072aee46aa709d9a67a3c988c5934bec67d71e5.tar.bz2 |
Revert "Refactor ImporterHost as preparation for OOP switch", which caused purify XP leak:
std::_W::_Allocate(unsigned int,wchar_t *) [unit_tests.exe]
Alloc Location
...
chrome/browser/importer/ie_importer.cc IEImporter::StartImport(ProfileInfo,WORD,ImporterBridge *)
base/tuple.h ?DispatchToMethod@VImporter@@P81@AEXUProfileInfo@@GPAVImporterBridge@@@ZU2@GV?$scoped_refptr@VImporterBridge@@@@@@YAXPAVImporter@@P80@AEXUProfileInfo@@GPAVImporterBridge@@@ZABU?$Tuple3@UProfileInfo@@GV?$scoped_refptr@VImporterBridge@@@@@@@Z
^^^
This reverts commit r28007 and r27996.
TBR=jeremy
Review URL: http://codereview.chromium.org/260011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28019 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
20 files changed, 475 insertions, 670 deletions
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index 943cb9e..3a38b2f 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -13,7 +13,6 @@ #include "base/string_util.h" #include "base/values.h" #include "chrome/browser/importer/firefox_importer_utils.h" -#include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/mork_reader.h" #include "chrome/browser/importer/nss_decryptor.h" #include "chrome/browser/search_engines/template_url.h" @@ -36,16 +35,18 @@ Firefox2Importer::~Firefox2Importer() { } void Firefox2Importer::StartImport(ProfileInfo profile_info, - uint16 items, - ImporterBridge* bridge) { - bridge_ = bridge; + uint16 items, ProfileWriter* writer, + MessageLoop* delagate_loop, + ImporterHost* host) { + writer_ = writer; source_path_ = profile_info.source_path; app_path_ = profile_info.app_path; + importer_host_ = host; parsing_bookmarks_html_file_ = (profile_info.browser_type == BOOKMARKS_HTML); // The order here is important! - bridge_->NotifyStarted(); + NotifyStarted(); if ((items & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. @@ -53,27 +54,27 @@ void Firefox2Importer::StartImport(ProfileInfo profile_info, // will also import favicons and we store favicon for a URL only if the URL // exist in history or bookmarks. if ((items & HISTORY) && !cancelled()) { - bridge_->NotifyItemStarted(HISTORY); + NotifyItemStarted(HISTORY); ImportHistory(); - bridge_->NotifyItemEnded(HISTORY); + NotifyItemEnded(HISTORY); } if ((items & FAVORITES) && !cancelled()) { - bridge_->NotifyItemStarted(FAVORITES); + NotifyItemStarted(FAVORITES); ImportBookmarks(); - bridge_->NotifyItemEnded(FAVORITES); + NotifyItemEnded(FAVORITES); } if ((items & SEARCH_ENGINES) && !cancelled()) { - bridge_->NotifyItemStarted(SEARCH_ENGINES); + NotifyItemStarted(SEARCH_ENGINES); ImportSearchEngines(); - bridge_->NotifyItemEnded(SEARCH_ENGINES); + NotifyItemEnded(SEARCH_ENGINES); } if ((items & PASSWORDS) && !cancelled()) { - bridge_->NotifyItemStarted(PASSWORDS); + NotifyItemStarted(PASSWORDS); ImportPasswords(); - bridge_->NotifyItemEnded(PASSWORDS); + NotifyItemEnded(PASSWORDS); } - bridge_->NotifyEnded(); + NotifyEnded(); } // static @@ -263,19 +264,21 @@ void Firefox2Importer::ImportBookmarks() { // Write data into profile. if (!bookmarks.empty() && !cancelled()) { - int options = 0; - if (import_to_bookmark_bar()) - options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR; - bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddBookmarkEntry, bookmarks, + first_folder_name, + import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0)); } if (!parsing_bookmarks_html_file_ && !template_urls.empty() && !cancelled()) { - bridge_->SetKeywords(template_urls, -1, false); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddKeywords, template_urls, -1, false)); } else { STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); } if (!favicons.empty()) { - bridge_->SetFavIcons(favicons); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddFavicons, favicons)); } } @@ -302,7 +305,8 @@ void Firefox2Importer::ImportPasswords() { if (!cancelled()) { for (size_t i = 0; i < forms.size(); ++i) { - bridge_->SetPasswordForm(forms[i]); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddPasswordForm, forms[i])); } } } @@ -310,7 +314,7 @@ void Firefox2Importer::ImportPasswords() { void Firefox2Importer::ImportHistory() { std::wstring file = source_path_; file_util::AppendToPath(&file, L"history.dat"); - ImportHistoryFromFirefox2(file, bridge_); + ImportHistoryFromFirefox2(file, main_loop_, writer_); } void Firefox2Importer::ImportSearchEngines() { @@ -319,16 +323,17 @@ void Firefox2Importer::ImportSearchEngines() { std::vector<TemplateURL*> search_engines; ParseSearchEnginesFromXMLFiles(files, &search_engines); - - int default_index = - GetFirefoxDefaultSearchEngineIndex(search_engines, source_path_); - bridge_->SetKeywords(search_engines, default_index, true); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddKeywords, search_engines, + GetFirefoxDefaultSearchEngineIndex(search_engines, source_path_), + true)); } void Firefox2Importer::ImportHomepage() { - GURL home_page = GetHomepage(source_path_); - if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { - bridge_->AddHomePage(home_page); + GURL homepage = GetHomepage(source_path_); + if (homepage.is_valid() && !IsDefaultHomepage(homepage, app_path_)) { + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddHomepage, homepage)); } } diff --git a/chrome/browser/importer/firefox2_importer.h b/chrome/browser/importer/firefox2_importer.h index d9aa263..8078c66 100644 --- a/chrome/browser/importer/firefox2_importer.h +++ b/chrome/browser/importer/firefox2_importer.h @@ -18,7 +18,9 @@ class Firefox2Importer : public Importer { // Importer methods. virtual void StartImport(ProfileInfo profile_info, uint16 items, - ImporterBridge* bridge); + ProfileWriter* writer, + MessageLoop* delagate_loop, + ImporterHost* host); // Loads the default bookmarks in the Firefox installed at |firefox_app_path|, // and stores their locations in |urls|. diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index 10d2855..a509f55 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -14,7 +14,6 @@ #include "base/string_util.h" #include "chrome/browser/importer/firefox2_importer.h" #include "chrome/browser/importer/firefox_importer_utils.h" -#include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/nss_decryptor.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/time_format.h" @@ -26,15 +25,17 @@ using base::Time; using webkit_glue::PasswordForm; void Firefox3Importer::StartImport(ProfileInfo profile_info, - uint16 items, - ImporterBridge* bridge) { - bridge_ = bridge; + uint16 items, ProfileWriter* writer, + MessageLoop* delagate_loop, + ImporterHost* host) { + writer_ = writer; source_path_ = profile_info.source_path; app_path_ = profile_info.app_path; + importer_host_ = host; // The order here is important! - bridge_->NotifyStarted(); + NotifyStarted(); if ((items & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. @@ -42,27 +43,27 @@ void Firefox3Importer::StartImport(ProfileInfo profile_info, // will also import favicons and we store favicon for a URL only if the URL // exist in history or bookmarks. if ((items & HISTORY) && !cancelled()) { - bridge_->NotifyItemStarted(HISTORY); + NotifyItemStarted(HISTORY); ImportHistory(); - bridge_->NotifyItemEnded(HISTORY); + NotifyItemEnded(HISTORY); } if ((items & FAVORITES) && !cancelled()) { - bridge_->NotifyItemStarted(FAVORITES); + NotifyItemStarted(FAVORITES); ImportBookmarks(); - bridge_->NotifyItemEnded(FAVORITES); + NotifyItemEnded(FAVORITES); } if ((items & SEARCH_ENGINES) && !cancelled()) { - bridge_->NotifyItemStarted(SEARCH_ENGINES); + NotifyItemStarted(SEARCH_ENGINES); ImportSearchEngines(); - bridge_->NotifyItemEnded(SEARCH_ENGINES); + NotifyItemEnded(SEARCH_ENGINES); } if ((items & PASSWORDS) && !cancelled()) { - bridge_->NotifyItemStarted(PASSWORDS); + NotifyItemStarted(PASSWORDS); ImportPasswords(); - bridge_->NotifyItemEnded(PASSWORDS); + NotifyItemEnded(PASSWORDS); } - bridge_->NotifyEnded(); + NotifyEnded(); } void Firefox3Importer::ImportHistory() { @@ -109,7 +110,8 @@ void Firefox3Importer::ImportHistory() { rows.push_back(row); } if (!rows.empty() && !cancelled()) { - bridge_->SetHistoryItems(rows); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddHistoryPage, rows)); } } @@ -242,22 +244,22 @@ void Firefox3Importer::ImportBookmarks() { // Write into profile. if (!bookmarks.empty() && !cancelled()) { - const std::wstring& first_folder_name = - l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); - int options = 0; - if (import_to_bookmark_bar()) - options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR; - bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddBookmarkEntry, bookmarks, + l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_FIREFOX), + import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0)); } if (!template_urls.empty() && !cancelled()) { - bridge_->SetKeywords(template_urls, -1, false); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddKeywords, template_urls, -1, false)); } else { STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); } if (!favicon_map.empty() && !cancelled()) { std::vector<history::ImportedFavIconUsage> favicons; LoadFavicons(db.get(), favicon_map, &favicons); - bridge_->SetFavIcons(favicons); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddFavicons, favicons)); } } @@ -287,7 +289,8 @@ void Firefox3Importer::ImportPasswords() { if (!cancelled()) { for (size_t i = 0; i < forms.size(); ++i) { - bridge_->SetPasswordForm(forms[i]); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddPasswordForm, forms[i])); } } } @@ -298,15 +301,16 @@ void Firefox3Importer::ImportSearchEngines() { std::vector<TemplateURL*> search_engines; ParseSearchEnginesFromXMLFiles(files, &search_engines); - int default_index = - GetFirefoxDefaultSearchEngineIndex(search_engines, source_path_); - bridge_->SetKeywords(search_engines, default_index, true); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddKeywords, search_engines, + GetFirefoxDefaultSearchEngineIndex(search_engines, source_path_), true)); } void Firefox3Importer::ImportHomepage() { - GURL home_page = GetHomepage(source_path_); - if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { - bridge_->AddHomePage(home_page); + GURL homepage = GetHomepage(source_path_); + if (homepage.is_valid() && !IsDefaultHomepage(homepage, app_path_)) { + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddHomepage, homepage)); } } diff --git a/chrome/browser/importer/firefox3_importer.h b/chrome/browser/importer/firefox3_importer.h index 926272b..9daa6b53a 100644 --- a/chrome/browser/importer/firefox3_importer.h +++ b/chrome/browser/importer/firefox3_importer.h @@ -26,7 +26,9 @@ class Firefox3Importer : public Importer { // Importer methods. virtual void StartImport(ProfileInfo profile_info, uint16 items, - ImporterBridge* bridge); + ProfileWriter* writer, + MessageLoop* delagate_loop_, + ImporterHost* host); private: typedef std::map<int64, std::set<GURL> > FaviconMap; @@ -74,6 +76,7 @@ class Firefox3Importer : public Importer { const FaviconMap& favicon_map, std::vector<history::ImportedFavIconUsage>* favicons); + ProfileWriter* writer_; std::wstring source_path_; std::wstring app_path_; diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 8c11064..9a2606b 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -25,7 +25,6 @@ #include "base/time.h" #include "base/win_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/password_manager/ie7_password.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/common/time_format.h" @@ -65,11 +64,14 @@ const GUID IEImporter::kUnittestGUID = { 0xa79029d6, 0x753e, 0x4e27, void IEImporter::StartImport(ProfileInfo profile_info, uint16 items, - ImporterBridge* bridge) { - bridge_ = bridge; + ProfileWriter* writer, + MessageLoop* delagate_loop, + ImporterHost* host) { + writer_ = writer; source_path_ = profile_info.source_path; + importer_host_ = host; - bridge_->NotifyStarted(); + NotifyStarted(); // Some IE settings (such as Protected Storage) are obtained via COM APIs. win_util::ScopedCOMInitializer com_initializer; @@ -78,30 +80,30 @@ void IEImporter::StartImport(ProfileInfo profile_info, ImportHomepage(); // Doesn't have a UI item. // The order here is important! if ((items & HISTORY) && !cancelled()) { - bridge_->NotifyItemStarted(HISTORY); + NotifyItemStarted(HISTORY); ImportHistory(); - bridge_->NotifyItemEnded(HISTORY); + NotifyItemEnded(HISTORY); } if ((items & FAVORITES) && !cancelled()) { - bridge_->NotifyItemStarted(FAVORITES); + NotifyItemStarted(FAVORITES); ImportFavorites(); - bridge_->NotifyItemEnded(FAVORITES); + NotifyItemEnded(FAVORITES); } if ((items & SEARCH_ENGINES) && !cancelled()) { - bridge_->NotifyItemStarted(SEARCH_ENGINES); + NotifyItemStarted(SEARCH_ENGINES); ImportSearchEngines(); - bridge_->NotifyItemEnded(SEARCH_ENGINES); + NotifyItemEnded(SEARCH_ENGINES); } if ((items & PASSWORDS) && !cancelled()) { - bridge_->NotifyItemStarted(PASSWORDS); + NotifyItemStarted(PASSWORDS); // Always import IE6 passwords. ImportPasswordsIE6(); if (CurrentIEVersion() >= 7) ImportPasswordsIE7(); - bridge_->NotifyItemEnded(PASSWORDS); + NotifyItemEnded(PASSWORDS); } - bridge_->NotifyEnded(); + NotifyEnded(); } void IEImporter::ImportFavorites() { @@ -115,12 +117,10 @@ void IEImporter::ImportFavorites() { ParseFavoritesFolder(info, &bookmarks); if (!bookmarks.empty() && !cancelled()) { - const std::wstring& first_folder_name = - l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_IE); - int options = 0; - if (import_to_bookmark_bar()) - options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR; - bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddBookmarkEntry, bookmarks, + l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_IE), + import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0)); } } @@ -239,7 +239,8 @@ void IEImporter::ImportPasswordsIE6() { } } - bridge_->SetPasswordForm(form); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddPasswordForm, form)); } } @@ -266,8 +267,10 @@ void IEImporter::ImportPasswordsIE7() { password_info.url_hash = reg_iterator.Name(); password_info.encrypted_data = value; password_info.date_created = Time::Now(); - - bridge_->AddIE7PasswordInfo(password_info); + main_loop_->PostTask(FROM_HERE, + NewRunnableMethod(writer_, + &ProfileWriter::AddIE7PasswordInfo, + password_info)); } } @@ -328,7 +331,8 @@ void IEImporter::ImportHistory() { } if (!rows.empty() && !cancelled()) { - bridge_->SetHistoryItems(rows); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddHistoryPage, rows)); } } } @@ -405,7 +409,9 @@ void IEImporter::ImportSearchEngines() { static_cast<int>(search_engines.size()) - 1; } } - bridge_->SetKeywords(search_engines, default_search_engine_index, true); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddKeywords, search_engines, default_search_engine_index, + true)); } void IEImporter::ImportHomepage() { @@ -432,7 +438,8 @@ void IEImporter::ImportHomepage() { return; } - bridge_->AddHomePage(homepage); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddHomepage, homepage)); } bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) { diff --git a/chrome/browser/importer/ie_importer.h b/chrome/browser/importer/ie_importer.h index a43b660..26e133c 100644 --- a/chrome/browser/importer/ie_importer.h +++ b/chrome/browser/importer/ie_importer.h @@ -15,7 +15,9 @@ class IEImporter : public Importer { // Importer methods. virtual void StartImport(ProfileInfo browser_info, uint16 items, - ImporterBridge* bridge); + ProfileWriter* writer, + MessageLoop* delagate_loop, + ImporterHost* host); private: FRIEND_TEST(ImporterTest, IEImporter); @@ -79,7 +81,7 @@ class IEImporter : public Importer { // providing a fake source. std::wstring source_path_; - DISALLOW_COPY_AND_ASSIGN(IEImporter); + DISALLOW_EVIL_CONSTRUCTORS(IEImporter); }; #endif // CHROME_BROWSER_IMPORTER_IE_IMPORTER_H_ diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 6f36d19..29911f6 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -19,8 +19,11 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/first_run.h" +#include "chrome/browser/importer/firefox2_importer.h" +#include "chrome/browser/importer/firefox3_importer.h" +#include "chrome/browser/importer/firefox_importer_utils.h" #include "chrome/browser/importer/firefox_profile_lock.h" -#include "chrome/browser/importer/importer_bridge.h" +#include "chrome/browser/importer/toolbar_importer.h" #include "chrome/browser/renderer_host/site_instance.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/shell_integration.h" @@ -35,13 +38,22 @@ // TODO(port): Port these files. #if defined(OS_WIN) -#include "app/win_util.h" #include "chrome/browser/views/importer_lock_view.h" #include "views/window/window.h" #elif defined(OS_LINUX) #include "chrome/browser/gtk/import_lock_dialog_gtk.h" #endif +#if defined(OS_WIN) +#include "app/win_util.h" +#include "chrome/browser/importer/ie_importer.h" +#include "chrome/browser/password_manager/ie7_password.h" +#endif +#if defined(OS_MACOSX) +#include "base/mac_util.h" +#include "chrome/browser/importer/safari_importer.h" +#endif + using webkit_glue::PasswordForm; // ProfileWriter. @@ -367,10 +379,33 @@ bool ProfileWriter::DoesBookmarkExist( // Importer. Importer::Importer() - : cancelled_(false), + : main_loop_(MessageLoop::current()), + delagate_loop_(NULL), + importer_host_(NULL), + cancelled_(false), import_to_bookmark_bar_(false) { } +void Importer::NotifyItemStarted(ImportItem item) { + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(importer_host_, + &ImporterHost::ImportItemStarted, item)); +} + +void Importer::NotifyItemEnded(ImportItem item) { + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(importer_host_, + &ImporterHost::ImportItemEnded, item)); +} + +void Importer::NotifyStarted() { + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(importer_host_, + &ImporterHost::ImportStarted)); +} + +void Importer::NotifyEnded() { + main_loop_->PostTask(FROM_HERE, + NewRunnableMethod(importer_host_, &ImporterHost::ImportEnded)); +} + // static bool Importer::ReencodeFavicon(const unsigned char* src_data, size_t src_len, std::vector<unsigned char>* png_data) { @@ -405,7 +440,7 @@ ImporterHost::ImporterHost() is_source_readable_(true), headless_(false), parent_window_(NULL) { - importer_list_.DetectSourceProfiles(); + DetectSourceProfiles(); } ImporterHost::ImporterHost(MessageLoop* file_loop) @@ -417,10 +452,11 @@ ImporterHost::ImporterHost(MessageLoop* file_loop) is_source_readable_(true), headless_(false), parent_window_(NULL) { - importer_list_.DetectSourceProfiles(); + DetectSourceProfiles(); } ImporterHost::~ImporterHost() { + STLDeleteContainerPointers(source_profiles_.begin(), source_profiles_.end()); if (NULL != importer_) importer_->Release(); } @@ -491,7 +527,7 @@ void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, // so that it doesn't block the UI. When the import is complete, observer // will be notified. writer_ = writer; - importer_ = importer_list_.CreateImporterByType(profile_info.browser_type); + importer_ = CreateImporterByType(profile_info.browser_type); // If we fail to create Importer, exit as we can not do anything. if (!importer_) { ImportEnded(); @@ -507,10 +543,8 @@ void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, import_to_bookmark_bar = (starred_urls.size() == 0); } importer_->set_import_to_bookmark_bar(import_to_bookmark_bar); - scoped_refptr<ImporterBridge> bridge( - new InProcessImporterBridge(writer_.get(), file_loop_, this)); task_ = NewRunnableMethod(importer_, &Importer::StartImport, - profile_info, items, bridge); + profile_info, items, writer_.get(), file_loop_, this); // We should lock the Firefox profile directory to prevent corruption. if (profile_info.browser_type == FIREFOX2 || @@ -619,3 +653,196 @@ void ImporterHost::ImportEnded() { observer_->ImportEnded(); Release(); } + +Importer* ImporterHost::CreateImporterByType(ProfileType type) { + switch (type) { +#if defined(OS_WIN) + case MS_IE: + return new IEImporter(); +#endif + case BOOKMARKS_HTML: + case FIREFOX2: + return new Firefox2Importer(); + case FIREFOX3: + return new Firefox3Importer(); + case GOOGLE_TOOLBAR5: + return new Toolbar5Importer(); +#if defined(OS_MACOSX) + case SAFARI: + return new SafariImporter(mac_util::GetUserLibraryPath()); +#endif // OS_MACOSX + } + NOTREACHED(); + return NULL; +} + +int ImporterHost::GetAvailableProfileCount() { + return static_cast<int>(source_profiles_.size()); +} + +std::wstring ImporterHost::GetSourceProfileNameAt(int index) const { + DCHECK(index < static_cast<int>(source_profiles_.size())); + return source_profiles_[index]->description; +} + +const ProfileInfo& ImporterHost::GetSourceProfileInfoAt(int index) const { + DCHECK(index < static_cast<int>(source_profiles_.size())); + return *source_profiles_[index]; +} + +const ProfileInfo& ImporterHost::GetSourceProfileInfoForBrowserType( + int browser_type) const { + int size = source_profiles_.size(); + for (int i = 0; i < size; i++) { + if (source_profiles_[i]->browser_type == browser_type) + return *source_profiles_[i]; + } + NOTREACHED(); + return *(new ProfileInfo()); +} + +void ImporterHost::DetectSourceProfiles() { +#if defined(OS_WIN) + // The order in which detect is called determines the order + // in which the options appear in the dropdown combo-box + if (ShellIntegration::IsFirefoxDefaultBrowser()) { + DetectFirefoxProfiles(); + DetectIEProfiles(); + } else { + DetectIEProfiles(); + DetectFirefoxProfiles(); + } + // TODO(brg) : Current UI requires win_util. + DetectGoogleToolbarProfiles(); +#else +#if defined(OS_MACOSX) + DetectSafariProfiles(); +#endif + DetectFirefoxProfiles(); +#endif +} + + +#if defined(OS_WIN) +void ImporterHost::DetectIEProfiles() { + // IE always exists and don't have multiple profiles. + ProfileInfo* ie = new ProfileInfo(); + ie->description = l10n_util::GetString(IDS_IMPORT_FROM_IE); + ie->browser_type = MS_IE; + ie->source_path.clear(); + ie->app_path.clear(); + ie->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS | + SEARCH_ENGINES; + source_profiles_.push_back(ie); +} +#endif + +void ImporterHost::DetectFirefoxProfiles() { + DictionaryValue root; + std::wstring ini_file = GetProfilesINI().ToWStringHack(); + ParseProfileINI(ini_file, &root); + + std::wstring source_path; + for (int i = 0; ; ++i) { + std::wstring current_profile = L"Profile" + IntToWString(i); + if (!root.HasKey(current_profile)) { + // Profiles are continuously numbered. So we exit when we can't + // find the i-th one. + break; + } + std::wstring is_relative, path, profile_path; + if (root.GetString(current_profile + L".IsRelative", &is_relative) && + root.GetString(current_profile + L".Path", &path)) { +#if defined(OS_WIN) + string16 path16 = WideToUTF16Hack(path); + ReplaceSubstringsAfterOffset( + &path16, 0, ASCIIToUTF16("/"), ASCIIToUTF16("\\")); + path.assign(UTF16ToWideHack(path16)); +#endif + + // IsRelative=1 means the folder path would be relative to the + // path of profiles.ini. IsRelative=0 refers to a custom profile + // location. + if (is_relative == L"1") { + profile_path = file_util::GetDirectoryFromPath(ini_file); + file_util::AppendToPath(&profile_path, path); + } else { + profile_path = path; + } + + // We only import the default profile when multiple profiles exist, + // since the other profiles are used mostly by developers for testing. + // Otherwise, Profile0 will be imported. + std::wstring is_default; + if ((root.GetString(current_profile + L".Default", &is_default) && + is_default == L"1") || i == 0) { + source_path = profile_path; + // We break out of the loop when we have found the default profile. + if (is_default == L"1") + break; + } + } + } + + // Detects which version of Firefox is installed. + ProfileType firefox_type; + std::wstring app_path; + int version = 0; +#if defined(OS_WIN) + version = GetCurrentFirefoxMajorVersionFromRegistry(); +#endif + if (version != 2 && version != 3) + GetFirefoxVersionAndPathFromProfile(source_path, &version, &app_path); + + if (version == 2) { + firefox_type = FIREFOX2; + } else if (version == 3) { + firefox_type = FIREFOX3; + } else { + // Ignores other versions of firefox. + return; + } + + if (!source_path.empty()) { + ProfileInfo* firefox = new ProfileInfo(); + firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX); + firefox->browser_type = firefox_type; + firefox->source_path = source_path; +#if defined(OS_WIN) + firefox->app_path = GetFirefoxInstallPathFromRegistry(); +#endif + if (firefox->app_path.empty()) + firefox->app_path = app_path; + firefox->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS | + SEARCH_ENGINES; + source_profiles_.push_back(firefox); + } +} + +void ImporterHost::DetectGoogleToolbarProfiles() { + if (!FirstRun::IsChromeFirstRun()) { + ProfileInfo* google_toolbar = new ProfileInfo(); + google_toolbar->browser_type = GOOGLE_TOOLBAR5; + google_toolbar->description = l10n_util::GetString( + IDS_IMPORT_FROM_GOOGLE_TOOLBAR); + google_toolbar->source_path.clear(); + google_toolbar->app_path.clear(); + google_toolbar->services_supported = FAVORITES; + source_profiles_.push_back(google_toolbar); + } +} + +#if defined(OS_MACOSX) +void ImporterHost::DetectSafariProfiles() { + uint16 items = NONE; + if (SafariImporter::CanImport(mac_util::GetUserLibraryPath(), &items)) { + ProfileInfo* safari = new ProfileInfo(); + safari->browser_type = SAFARI; + safari->description = l10n_util::GetString(IDS_IMPORT_FROM_SAFARI); + safari->source_path.clear(); + safari->app_path.clear(); + safari->services_supported = items; + source_profiles_.push_back(safari); + } +} +#endif // OS_MACOSX diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index 325b1d3..1b8499e 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -15,12 +15,10 @@ #include "base/ref_counted.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/history/history_types.h" -#include "chrome/browser/importer/importer_list.h" #include "chrome/browser/profile.h" #include "chrome/common/notification_registrar.h" #include "googleurl/src/gurl.h" -class ImporterBridge; class MessageLoop; class TemplateURL; @@ -30,6 +28,22 @@ namespace webkit_glue { struct PasswordForm; } +// An enumeration of the type of browsers that we support to import +// settings and data from them. +enum ProfileType { +#if defined(OS_WIN) + MS_IE, +#endif + FIREFOX2, + FIREFOX3, +#if defined(OS_MACOSX) + SAFARI, +#endif + GOOGLE_TOOLBAR5, + // Identifies a 'bookmarks.html' file. + BOOKMARKS_HTML +}; + // An enumeration of the type of data we want to import. enum ImportItem { NONE = 0x0000, @@ -42,13 +56,13 @@ enum ImportItem { ALL = 0x003f }; -struct ProfileInfo { +typedef struct { std::wstring description; ProfileType browser_type; std::wstring source_path; std::wstring app_path; uint16 services_supported; // bitmap of ImportItem -}; +} ProfileInfo; class FirefoxProfileLock; class Importer; @@ -250,35 +264,45 @@ class ImporterHost : public base::RefCounted<ImporterHost>, void ImportItemEnded(ImportItem item); void ImportEnded(); - int GetAvailableProfileCount() { - return importer_list_.GetAvailableProfileCount(); - } + Importer* CreateImporterByType(ProfileType type); - // Returns the name of the profile at the 'index' slot. The profiles are + // Returns the number of different browser profiles you can import from. + int GetAvailableProfileCount(); + + // Returns the name of the profile at the 'index' slot. The profiles are // ordered such that the profile at index 0 is the likely default browser. - std::wstring GetSourceProfileNameAt(int index) const { - return importer_list_.GetSourceProfileNameAt(index); - } + std::wstring GetSourceProfileNameAt(int index) const; // Returns the ProfileInfo at the specified index. The ProfileInfo should be // passed to StartImportSettings(). - const ProfileInfo& GetSourceProfileInfoAt(int index) const { - return importer_list_.GetSourceProfileInfoAt(index); - } - - // Returns the ProfileInfo with the given browser type. - const ProfileInfo& GetSourceProfileInfoForBrowserType(int browser_type) - const { - return importer_list_.GetSourceProfileInfoForBrowserType(browser_type); - } + const ProfileInfo& GetSourceProfileInfoAt(int index) const; + // Returns the ProfileInfo with the given browser type + const ProfileInfo& GetSourceProfileInfoForBrowserType(int browser_type) const; private: // If we're not waiting on any model to finish loading, invokes the task_. void InvokeTaskIfDone(); + // Detects the installed browsers and their associated profiles, then + // stores their information in a list. It returns the list of description + // of all profiles. + void DetectSourceProfiles(); + + // Helper methods for detecting available profiles. +#if defined(OS_WIN) + void DetectIEProfiles(); +#endif + void DetectFirefoxProfiles(); + void DetectGoogleToolbarProfiles(); +#if defined(OS_MACOSX) + void DetectSafariProfiles(); +#endif + NotificationRegistrar registrar_; - ImporterList importer_list_; + + // The list of profiles with the default one first. + std::vector<ProfileInfo*> source_profiles_; Observer* observer_; scoped_refptr<ProfileWriter> writer_; @@ -313,6 +337,8 @@ class ImporterHost : public base::RefCounted<ImporterHost>, // The base class of all importers. class Importer : public base::RefCounted<Importer> { public: + virtual ~Importer() { } + // All importers should implement this method by adding their // import logic. And it will be run in file thread by ImporterHost. // @@ -321,7 +347,9 @@ class Importer : public base::RefCounted<Importer> { // stuff have been finished. virtual void StartImport(ProfileInfo profile_info, uint16 items, - ImporterBridge* bridge) = 0; + ProfileWriter* writer, + MessageLoop* delegate_loop, + ImporterHost* host) = 0; // Cancels the import process. virtual void Cancel() { cancelled_ = true; } @@ -335,6 +363,20 @@ class Importer : public base::RefCounted<Importer> { protected: Importer(); + // Notifies the coordinator that the collection of data for the specified + // item has begun. + void NotifyItemStarted(ImportItem item); + + // Notifies the coordinator that the collection of data for the specified + // item has completed. + void NotifyItemEnded(ImportItem item); + + // Notifies the coordinator that the import operation has begun. + void NotifyStarted(); + + // Notifies the coordinator that the entire import operation has completed. + void NotifyEnded(); + // Given raw image data, decodes the icon, re-sampling to the correct size as // necessary, and re-encodes as PNG data in the given output vector. Returns // true on success. @@ -343,7 +385,15 @@ class Importer : public base::RefCounted<Importer> { bool import_to_bookmark_bar() const { return import_to_bookmark_bar_; } - scoped_refptr<ImporterBridge> bridge_; + // The importer should know the main thread so that ProfileWriter + // will be invoked in thread instead. + MessageLoop* main_loop_; + + // The message loop in which the importer operates. + MessageLoop* delagate_loop_; + + // The coordinator host for this importer. + ImporterHost* importer_host_; private: // True if the caller cancels the import process. diff --git a/chrome/browser/importer/importer_bridge.cc b/chrome/browser/importer/importer_bridge.cc deleted file mode 100644 index dfe98fd..0000000 --- a/chrome/browser/importer/importer_bridge.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/importer/importer_bridge.h" - -#include "base/message_loop.h" -#include "chrome/browser/importer/importer.h" -#if defined(OS_WIN) -#include "chrome/browser/password_manager/ie7_password.h" -#endif -#include "webkit/glue/password_form.h" - -InProcessImporterBridge::InProcessImporterBridge(ProfileWriter* writer, - MessageLoop* delegate_loop, - ImporterHost* host) - : ImporterBridge(writer, delegate_loop, host), - main_loop_(MessageLoop::current()), - delegate_loop_(NULL) { -} - -void InProcessImporterBridge::AddBookmarkEntries( - const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, - const std::wstring& first_folder_name, - int options) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, - &ProfileWriter::AddBookmarkEntry, bookmarks, first_folder_name, - options)); -} - -void InProcessImporterBridge::AddHomePage(const GURL &home_page) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, - &ProfileWriter::AddHomepage, home_page)); -} - -#if defined(OS_WIN) -void InProcessImporterBridge::AddIE7PasswordInfo( - const IE7PasswordInfo password_info) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, - &ProfileWriter::AddIE7PasswordInfo, password_info)); -} -#endif // OS_WIN - -void InProcessImporterBridge::SetFavIcons( - const std::vector<history::ImportedFavIconUsage>& fav_icons) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, - &ProfileWriter::AddFavicons, fav_icons)); -} - -void InProcessImporterBridge::SetHistoryItems( - const std::vector<history::URLRow> &rows) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, - &ProfileWriter::AddHistoryPage, rows)); -} - -void InProcessImporterBridge::SetKeywords( - const std::vector<TemplateURL*>& template_urls, - int default_keyword_index, - bool unique_on_host_and_path) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, - &ProfileWriter::AddKeywords, template_urls, default_keyword_index, - unique_on_host_and_path)); -} - -void InProcessImporterBridge::SetPasswordForm( - const webkit_glue::PasswordForm& form) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, - &ProfileWriter::AddPasswordForm, form)); -} - -void InProcessImporterBridge::NotifyItemStarted(ImportItem item) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(host_, - &ImporterHost::ImportItemStarted, item)); -} - -void InProcessImporterBridge::NotifyItemEnded(ImportItem item) { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(host_, - &ImporterHost::ImportItemEnded, item)); -} - -void InProcessImporterBridge::NotifyStarted() { - main_loop_->PostTask(FROM_HERE, NewRunnableMethod(host_, - &ImporterHost::ImportStarted)); -} - -void InProcessImporterBridge::NotifyEnded() { - main_loop_->PostTask(FROM_HERE, - NewRunnableMethod(host_, &ImporterHost::ImportEnded)); -} diff --git a/chrome/browser/importer/importer_bridge.h b/chrome/browser/importer/importer_bridge.h deleted file mode 100644 index 60d26875..0000000 --- a/chrome/browser/importer/importer_bridge.h +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ -#define CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ - -#include "build/build_config.h" - -#include <vector> - -#include "base/basictypes.h" -#include "base/string16.h" - -#include "chrome/browser/importer/importer.h" -// TODO: remove this, see friend declaration in ImporterBridge. -#include "chrome/browser/importer/toolbar_importer.h" - -class ImporterBridge : public base::RefCounted<ImporterBridge> { - public: - ImporterBridge(ProfileWriter* writer, - MessageLoop* delegate_loop, - ImporterHost* host) - : writer_(writer), - delegate_loop_(delegate_loop), - host_(host) { - } - virtual ~ImporterBridge() {} - - virtual void AddBookmarkEntries( - const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, - const std::wstring& first_folder_name, - int options) = 0; - virtual void AddHomePage(const GURL &home_page) = 0; - -#if defined(OS_WIN) - virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info) = 0; -#endif - - virtual void SetFavIcons( - const std::vector<history::ImportedFavIconUsage>& fav_icons) = 0; - virtual void SetHistoryItems(const std::vector<history::URLRow> &rows) = 0; - virtual void SetKeywords(const std::vector<TemplateURL*> &template_urls, - int default_keyword_index, - bool unique_on_host_and_path) = 0; - virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) = 0; - - // Notifies the coordinator that the collection of data for the specified - // item has begun. - virtual void NotifyItemStarted(ImportItem item) = 0; - - // Notifies the coordinator that the collection of data for the specified - // item has completed. - virtual void NotifyItemEnded(ImportItem item) = 0; - - // Notifies the coordinator that the import operation has begun. - virtual void NotifyStarted() = 0; - - // Notifies the coordinator that the entire import operation has completed. - virtual void NotifyEnded() = 0; - - protected: - - // TODO: In order to run Toolbar5Importer OOP we need to cut this - // connection, but as an interim step we allow Toolbar5Import to break - // the abstraction here and assume import is in-process. - friend class Toolbar5Importer; - - ProfileWriter* writer_; - MessageLoop* delegate_loop_; - ImporterHost* host_; - - DISALLOW_COPY_AND_ASSIGN(ImporterBridge); -}; - -class InProcessImporterBridge : public ImporterBridge { - public: - InProcessImporterBridge(ProfileWriter* writer, - MessageLoop* delegate_loop, - ImporterHost* host); - - // Methods inherited from ImporterBridge. - virtual void AddBookmarkEntries( - const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, - const std::wstring& first_folder_name, - int options); - virtual void AddHomePage(const GURL &home_page); - -#if defined(OS_WIN) - virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info); -#endif - - virtual void SetFavIcons( - const std::vector<history::ImportedFavIconUsage>& fav_icons); - virtual void SetHistoryItems(const std::vector<history::URLRow> &rows); - virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, - int default_keyword_index, - bool unique_on_host_and_path); - virtual void SetPasswordForm(const webkit_glue::PasswordForm& form); - - virtual void NotifyItemStarted(ImportItem item); - virtual void NotifyItemEnded(ImportItem item); - virtual void NotifyStarted(); - virtual void NotifyEnded(); - - private: - MessageLoop* main_loop_; - MessageLoop* delegate_loop_; - DISALLOW_COPY_AND_ASSIGN(InProcessImporterBridge); -}; - -#endif // CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc deleted file mode 100644 index 4f3c815..0000000 --- a/chrome/browser/importer/importer_list.cc +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/importer/importer_list.h" - -#include "app/l10n_util.h" -#include "base/file_util.h" -#include "base/stl_util-inl.h" -#include "chrome/browser/first_run.h" -#include "chrome/browser/importer/firefox2_importer.h" -#include "chrome/browser/importer/firefox3_importer.h" -#include "chrome/browser/importer/firefox_importer_utils.h" -#include "chrome/browser/importer/importer_bridge.h" -#include "chrome/browser/importer/toolbar_importer.h" -#include "chrome/browser/shell_integration.h" -#include "grit/generated_resources.h" - -#if defined(OS_WIN) -#include "app/win_util.h" -#include "chrome/browser/importer/ie_importer.h" -#include "chrome/browser/password_manager/ie7_password.h" -#endif -#if defined(OS_MACOSX) -#include "base/mac_util.h" -#include "chrome/browser/importer/safari_importer.h" -#endif - -ImporterList::ImporterList() { -} - -ImporterList::~ImporterList() { - STLDeleteContainerPointers(source_profiles_.begin(), source_profiles_.end()); -} - -void ImporterList::DetectSourceProfiles() { -#if defined(OS_WIN) - // The order in which detect is called determines the order - // in which the options appear in the dropdown combo-box - if (ShellIntegration::IsFirefoxDefaultBrowser()) { - DetectFirefoxProfiles(); - DetectIEProfiles(); - } else { - DetectIEProfiles(); - DetectFirefoxProfiles(); - } - // TODO(brg) : Current UI requires win_util. - DetectGoogleToolbarProfiles(); -#else -#if defined(OS_MACOSX) - DetectSafariProfiles(); -#endif - DetectFirefoxProfiles(); -#endif -} - -Importer* ImporterList::CreateImporterByType(ProfileType type) { - switch (type) { -#if defined(OS_WIN) - case MS_IE: - return new IEImporter(); -#endif - case BOOKMARKS_HTML: - case FIREFOX2: - return new Firefox2Importer(); - case FIREFOX3: - return new Firefox3Importer(); - case GOOGLE_TOOLBAR5: - return new Toolbar5Importer(); -#if defined(OS_MACOSX) - case SAFARI: - return new SafariImporter(mac_util::GetUserLibraryPath()); -#endif // OS_MACOSX - } - NOTREACHED(); - return NULL; -} - -int ImporterList::GetAvailableProfileCount() { - return static_cast<int>(source_profiles_.size()); -} - -std::wstring ImporterList::GetSourceProfileNameAt(int index) const { - DCHECK(index < static_cast<int>(source_profiles_.size())); - return source_profiles_[index]->description; -} - -const ProfileInfo& ImporterList::GetSourceProfileInfoAt(int index) const { - DCHECK(index < static_cast<int>(source_profiles_.size())); - return *source_profiles_[index]; -} - -const ProfileInfo& ImporterList::GetSourceProfileInfoForBrowserType( - int browser_type) const { - int size = source_profiles_.size(); - for (int i = 0; i < size; i++) { - if (source_profiles_[i]->browser_type == browser_type) - return *source_profiles_[i]; - } - NOTREACHED(); - return *(new ProfileInfo()); -} - -#if defined(OS_WIN) -void ImporterList::DetectIEProfiles() { - // IE always exists and don't have multiple profiles. - ProfileInfo* ie = new ProfileInfo(); - ie->description = l10n_util::GetString(IDS_IMPORT_FROM_IE); - ie->browser_type = MS_IE; - ie->source_path.clear(); - ie->app_path.clear(); - ie->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS | - SEARCH_ENGINES; - source_profiles_.push_back(ie); -} -#endif - -void ImporterList::DetectFirefoxProfiles() { - DictionaryValue root; - std::wstring ini_file = GetProfilesINI().ToWStringHack(); - ParseProfileINI(ini_file, &root); - - std::wstring source_path; - for (int i = 0; ; ++i) { - std::wstring current_profile = L"Profile" + IntToWString(i); - if (!root.HasKey(current_profile)) { - // Profiles are continuously numbered. So we exit when we can't - // find the i-th one. - break; - } - std::wstring is_relative, path, profile_path; - if (root.GetString(current_profile + L".IsRelative", &is_relative) && - root.GetString(current_profile + L".Path", &path)) { -#if defined(OS_WIN) - string16 path16 = WideToUTF16Hack(path); - ReplaceSubstringsAfterOffset( - &path16, 0, ASCIIToUTF16("/"), ASCIIToUTF16("\\")); - path.assign(UTF16ToWideHack(path16)); -#endif - - // IsRelative=1 means the folder path would be relative to the - // path of profiles.ini. IsRelative=0 refers to a custom profile - // location. - if (is_relative == L"1") { - profile_path = file_util::GetDirectoryFromPath(ini_file); - file_util::AppendToPath(&profile_path, path); - } else { - profile_path = path; - } - - // We only import the default profile when multiple profiles exist, - // since the other profiles are used mostly by developers for testing. - // Otherwise, Profile0 will be imported. - std::wstring is_default; - if ((root.GetString(current_profile + L".Default", &is_default) && - is_default == L"1") || i == 0) { - source_path = profile_path; - // We break out of the loop when we have found the default profile. - if (is_default == L"1") - break; - } - } - } - - // Detects which version of Firefox is installed. - ProfileType firefox_type; - std::wstring app_path; - int version = 0; -#if defined(OS_WIN) - version = GetCurrentFirefoxMajorVersionFromRegistry(); -#endif - if (version != 2 && version != 3) - GetFirefoxVersionAndPathFromProfile(source_path, &version, &app_path); - - if (version == 2) { - firefox_type = FIREFOX2; - } else if (version == 3) { - firefox_type = FIREFOX3; - } else { - // Ignores other versions of firefox. - return; - } - - if (!source_path.empty()) { - ProfileInfo* firefox = new ProfileInfo(); - firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX); - firefox->browser_type = firefox_type; - firefox->source_path = source_path; -#if defined(OS_WIN) - firefox->app_path = GetFirefoxInstallPathFromRegistry(); -#endif - if (firefox->app_path.empty()) - firefox->app_path = app_path; - firefox->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS | - SEARCH_ENGINES; - source_profiles_.push_back(firefox); - } -} - -void ImporterList::DetectGoogleToolbarProfiles() { - if (!FirstRun::IsChromeFirstRun()) { - ProfileInfo* google_toolbar = new ProfileInfo(); - google_toolbar->browser_type = GOOGLE_TOOLBAR5; - google_toolbar->description = l10n_util::GetString( - IDS_IMPORT_FROM_GOOGLE_TOOLBAR); - google_toolbar->source_path.clear(); - google_toolbar->app_path.clear(); - google_toolbar->services_supported = FAVORITES; - source_profiles_.push_back(google_toolbar); - } -} - -#if defined(OS_MACOSX) -void ImporterList::DetectSafariProfiles() { - uint16 items = NONE; - if (SafariImporter::CanImport(mac_util::GetUserLibraryPath(), &items)) { - ProfileInfo* safari = new ProfileInfo(); - safari->browser_type = SAFARI; - safari->description = l10n_util::GetString(IDS_IMPORT_FROM_SAFARI); - safari->source_path.clear(); - safari->app_path.clear(); - safari->services_supported = items; - source_profiles_.push_back(safari); - } -} -#endif // OS_MACOSX diff --git a/chrome/browser/importer/importer_list.h b/chrome/browser/importer/importer_list.h deleted file mode 100644 index 4574a29..0000000 --- a/chrome/browser/importer/importer_list.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_ -#define CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_ - -#include <string> -#include <vector> - -#include "build/build_config.h" - -#include "base/basictypes.h" - -class Importer; -struct ProfileInfo; - -// An enumeration of the type of browsers that we support to import -// settings and data from them. -enum ProfileType { -#if defined(OS_WIN) - MS_IE, -#endif - FIREFOX2, - FIREFOX3, -#if defined(OS_MACOSX) - SAFARI, -#endif - GOOGLE_TOOLBAR5, - // Identifies a 'bookmarks.html' file. - BOOKMARKS_HTML -}; - -class ImporterList { - public: - ImporterList(); - ~ImporterList(); - - // Detects the installed browsers and their associated profiles, then - // stores their information in a list. It returns the list of description - // of all profiles. - void DetectSourceProfiles(); - - Importer* CreateImporterByType(ProfileType type); - - // Returns the number of different browser profiles you can import from. - int GetAvailableProfileCount(); - - // Returns the name of the profile at the 'index' slot. The profiles are - // ordered such that the profile at index 0 is the likely default browser. - std::wstring GetSourceProfileNameAt(int index) const; - - // Returns the ProfileInfo at the specified index. The ProfileInfo should be - // passed to StartImportSettings(). - const ProfileInfo& GetSourceProfileInfoAt(int index) const; - - // Returns the ProfileInfo with the given browser type. - const ProfileInfo& GetSourceProfileInfoForBrowserType(int browser_type) const; - - // Helper methods for detecting available profiles. -#if defined(OS_WIN) - void DetectIEProfiles(); -#endif - void DetectFirefoxProfiles(); - void DetectGoogleToolbarProfiles(); -#if defined(OS_MACOSX) - void DetectSafariProfiles(); -#endif - - private: - // The list of profiles with the default one first. - std::vector<ProfileInfo*> source_profiles_; - - DISALLOW_COPY_AND_ASSIGN(ImporterList); -}; - -#endif // CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_ diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index b6ef1f6..739465d 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -20,7 +20,6 @@ #include "base/stl_util-inl.h" #include "chrome/browser/importer/ie_importer.h" #include "chrome/browser/importer/importer.h" -#include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/password_manager/ie7_password.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" diff --git a/chrome/browser/importer/mork_reader.cc b/chrome/browser/importer/mork_reader.cc index 75dd7dc..5352902 100644 --- a/chrome/browser/importer/mork_reader.cc +++ b/chrome/browser/importer/mork_reader.cc @@ -51,7 +51,6 @@ #include "chrome/browser/history/history_types.h" #include "chrome/browser/importer/firefox_importer_utils.h" #include "chrome/browser/importer/importer.h" -#include "chrome/browser/importer/importer_bridge.h" using base::Time; @@ -545,7 +544,8 @@ void AddToHistory(MorkReader::ColumnDataList* column_values, // It sets up the file stream and loops over the lines in the file to // parse them, then adds the resulting row set to history. -void ImportHistoryFromFirefox2(std::wstring file, ImporterBridge* bridge) { +void ImportHistoryFromFirefox2(std::wstring file, MessageLoop* loop, + ProfileWriter* writer) { MorkReader reader; reader.Read(file); @@ -582,5 +582,6 @@ void ImportHistoryFromFirefox2(std::wstring file, ImporterBridge* bridge) { for (MorkReader::iterator i = reader.begin(); i != reader.end(); ++i) AddToHistory(i->second, data, &rows); if (!rows.empty()) - bridge->SetHistoryItems(rows); + loop->PostTask(FROM_HERE, NewRunnableMethod(writer, + &ProfileWriter::AddHistoryPage, rows)); } diff --git a/chrome/browser/importer/mork_reader.h b/chrome/browser/importer/mork_reader.h index 4cdc010..d4844a0 100644 --- a/chrome/browser/importer/mork_reader.h +++ b/chrome/browser/importer/mork_reader.h @@ -50,7 +50,6 @@ #include "base/basictypes.h" -class ImporterBridge; class MessageLoop; class ProfileWriter; @@ -161,6 +160,7 @@ class MorkReader { }; // ImportHistoryFromFirefox2 is the main entry point to the importer. -void ImportHistoryFromFirefox2(std::wstring file, ImporterBridge* bridge); +void ImportHistoryFromFirefox2(std::wstring file, MessageLoop* loop, + ProfileWriter* writer); #endif // CHROME_BROWSER_IMPORTER_MORK_READER_H__ diff --git a/chrome/browser/importer/safari_importer.h b/chrome/browser/importer/safari_importer.h index 827880f..e443242 100644 --- a/chrome/browser/importer/safari_importer.h +++ b/chrome/browser/importer/safari_importer.h @@ -32,7 +32,9 @@ class SafariImporter : public Importer { // Importer methods. virtual void StartImport(ProfileInfo profile_info, uint16 items, - ImporterBridge* bridge); + ProfileWriter* writer, + MessageLoop* delegate_loop, + ImporterHost* host); // Does this user account have a Safari Profile and if so, what items diff --git a/chrome/browser/importer/safari_importer.mm b/chrome/browser/importer/safari_importer.mm index bcf3432..e08e582 100644 --- a/chrome/browser/importer/safari_importer.mm +++ b/chrome/browser/importer/safari_importer.mm @@ -16,7 +16,6 @@ #include "base/string16.h" #include "base/sys_string_conversions.h" #include "base/time.h" -#include "chrome/browser/importer/importer_bridge.h" #include "chrome/common/sqlite_utils.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" @@ -77,30 +76,32 @@ bool SafariImporter::CanImport(const FilePath& library_dir, } void SafariImporter::StartImport(ProfileInfo profile_info, - uint16 services_supported, - ImporterBridge* bridge) { - bridge_ = bridge; + uint16 services_supported, ProfileWriter* writer, + MessageLoop* delegate_loop, + ImporterHost* host) { + writer_ = writer; + importer_host_ = host; // The order here is important! - bridge_->NotifyStarted(); + NotifyStarted(); if ((services_supported & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. if ((services_supported & HISTORY) && !cancelled()) { - bridge_->NotifyItemStarted(HISTORY); + NotifyItemStarted(HISTORY); ImportHistory(); - bridge_->NotifyItemEnded(HISTORY); + NotifyItemEnded(HISTORY); } if ((services_supported & FAVORITES) && !cancelled()) { - bridge_->NotifyItemStarted(FAVORITES); + NotifyItemStarted(FAVORITES); ImportBookmarks(); - bridge_->NotifyItemEnded(FAVORITES); + NotifyItemEnded(FAVORITES); } if ((services_supported & PASSWORDS) && !cancelled()) { - bridge_->NotifyItemStarted(PASSWORDS); + NotifyItemStarted(PASSWORDS); ImportPasswords(); - bridge_->NotifyItemEnded(PASSWORDS); + NotifyItemEnded(PASSWORDS); } - bridge_->NotifyEnded(); + NotifyEnded(); } void SafariImporter::ImportBookmarks() { @@ -109,12 +110,10 @@ void SafariImporter::ImportBookmarks() { // Write bookmarks into profile. if (!bookmarks.empty() && !cancelled()) { - const std::wstring& first_folder_name = - l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_SAFARI); - int options = 0; - if (import_to_bookmark_bar()) - options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR; - bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddBookmarkEntry, bookmarks, + l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_SAFARI), + import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0)); } // Import favicons. @@ -125,7 +124,8 @@ void SafariImporter::ImportBookmarks() { if (!favicon_map.empty() && !cancelled()) { std::vector<history::ImportedFavIconUsage> favicons; LoadFaviconData(db.get(), favicon_map, &favicons); - bridge_->SetFavIcons(favicons); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddFavicons, favicons)); } } @@ -317,7 +317,8 @@ void SafariImporter::ImportHistory() { ParseHistoryItems(&rows); if (!rows.empty() && !cancelled()) { - bridge_->SetHistoryItems(rows); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddHistoryPage, rows)); } } @@ -405,6 +406,7 @@ void SafariImporter::ImportHomepage() { string16 hompeage_str = base::SysNSStringToUTF16(homepage_ns.get()); GURL homepage(hompeage_str); if (homepage.is_valid()) { - bridge_->AddHomePage(homepage); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddHomepage, homepage)); } } diff --git a/chrome/browser/importer/safari_importer_unittest.mm b/chrome/browser/importer/safari_importer_unittest.mm index f9ea738..7a4d99f 100644 --- a/chrome/browser/importer/safari_importer_unittest.mm +++ b/chrome/browser/importer/safari_importer_unittest.mm @@ -11,7 +11,6 @@ #include "base/sys_string_conversions.h" #include "chrome/common/chrome_paths.h" #include "chrome/test/file_test_utils.h" -#include "chrome/browser/importer/importer_bridge.h" #include "testing/platform_test.h" // In order to test the Safari import functionality effectively, we store a diff --git a/chrome/browser/importer/toolbar_importer.cc b/chrome/browser/importer/toolbar_importer.cc index a215fd8..20e10da 100644 --- a/chrome/browser/importer/toolbar_importer.cc +++ b/chrome/browser/importer/toolbar_importer.cc @@ -10,7 +10,6 @@ #include "base/string_util.h" #include "base/rand_util.h" #include "chrome/browser/first_run.h" -#include "chrome/browser/importer/importer_bridge.h" #include "chrome/common/libxml_utils.h" #include "grit/generated_resources.h" #include "net/base/cookie_monster.h" @@ -91,14 +90,19 @@ Toolbar5Importer::~Toolbar5Importer() { void Toolbar5Importer::StartImport(ProfileInfo profile_info, uint16 items, - ImporterBridge* bridge) { - DCHECK(bridge); - - bridge_ = bridge; + ProfileWriter* writer, + MessageLoop* delagate_loop, + ImporterHost* host) { + DCHECK(writer); + DCHECK(host); + + importer_host_ = host; + delagate_loop_ = delagate_loop; + writer_ = writer; items_to_import_ = items; state_ = INITIALIZED; - bridge_->NotifyStarted(); + NotifyStarted(); ContinueImport(); } @@ -113,9 +117,9 @@ void Toolbar5Importer::Cancel() { // If we are conducting network operations, post a message to the importer // thread for synchronization. - if (NULL != bridge_->delegate_loop_) { - if (bridge_->delegate_loop_ != MessageLoop::current()) { - bridge_->delegate_loop_->PostTask( + if (NULL != delagate_loop_) { + if (delagate_loop_ != MessageLoop::current()) { + delagate_loop_->PostTask( FROM_HERE, NewRunnableMethod(this, &Toolbar5Importer::Cancel)); } else { @@ -197,17 +201,17 @@ void Toolbar5Importer::EndImport() { data_fetcher_ = NULL; } - bridge_->NotifyEnded(); + NotifyEnded(); } } void Toolbar5Importer::BeginImportBookmarks() { - bridge_->NotifyItemStarted(FAVORITES); + NotifyItemStarted(FAVORITES); GetAuthenticationFromServer(); } void Toolbar5Importer::EndImportBookmarks() { - bridge_->NotifyItemEnded(FAVORITES); + NotifyItemEnded(FAVORITES); ContinueImport(); } @@ -578,10 +582,11 @@ bool Toolbar5Importer::ExtractFoldersFromXmlReader( void Toolbar5Importer::AddBookmarksToChrome( const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { if (!bookmarks.empty() && !cancelled()) { - const std::wstring& first_folder_name = - l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR); int options = ProfileWriter::ADD_IF_UNIQUE | (import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0); - bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options); + main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, + &ProfileWriter::AddBookmarkEntry, bookmarks, + l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR), + options)); } } diff --git a/chrome/browser/importer/toolbar_importer.h b/chrome/browser/importer/toolbar_importer.h index 61cdfb0..24b5b28 100644 --- a/chrome/browser/importer/toolbar_importer.h +++ b/chrome/browser/importer/toolbar_importer.h @@ -14,7 +14,6 @@ #include "chrome/browser/importer/importer.h" #include "chrome/browser/net/url_fetcher.h" -class ImporterBridge; class XmlReader; // Currently the only configuration information we need is to check whether or @@ -41,7 +40,9 @@ class Toolbar5Importer : public URLFetcher::Delegate, public Importer { // of Importer::StartImport. virtual void StartImport(ProfileInfo profile_info, uint16 items, - ImporterBridge* bridge); + ProfileWriter* writer, + MessageLoop* delegate_loop, + ImporterHost* host); // Importer view call this method when the user clicks the cancel button // in the ImporterView UI. We need to post a message to our loop |