summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer/importer_list.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/importer/importer_list.cc')
-rw-r--r--chrome/browser/importer/importer_list.cc253
1 files changed, 161 insertions, 92 deletions
diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc
index 6ac6517..10e1101 100644
--- a/chrome/browser/importer/importer_list.cc
+++ b/chrome/browser/importer/importer_list.cc
@@ -27,39 +27,95 @@
#include "chrome/browser/importer/safari_importer.h"
#endif
-ImporterList::ImporterList() {
+namespace {
+
+#if defined(OS_WIN)
+void DetectIEProfiles(std::vector<importer::ProfileInfo*>* profiles) {
+ // IE always exists and doesn't have multiple profiles.
+ ProfileInfo* ie = new ProfileInfo();
+ ie->description = l10n_util::GetString(IDS_IMPORT_FROM_IE);
+ ie->browser_type = importer::MS_IE;
+ ie->source_path.clear();
+ ie->app_path.clear();
+ ie->services_supported = importer::HISTORY | importer::FAVORITES |
+ importer::COOKIES | importer::PASSWORDS | importer::SEARCH_ENGINES;
+ profiles->push_back(ie);
}
+#endif // defined(OS_WIN)
-ImporterList::~ImporterList() {
- STLDeleteContainerPointers(source_profiles_.begin(), source_profiles_.end());
+#if defined(OS_MACOSX)
+void DetectSafariProfiles(std::vector<importer::ProfileInfo*>* profiles) {
+ uint16 items = importer::NONE;
+ if (!SafariImporter::CanImport(mac_util::GetUserLibraryPath(), &items))
+ return;
+
+ importer::ProfileInfo* safari = new importer::ProfileInfo();
+ safari->browser_type = importer::SAFARI;
+ safari->description = l10n_util::GetString(IDS_IMPORT_FROM_SAFARI);
+ safari->source_path.clear();
+ safari->app_path.clear();
+ safari->services_supported = items;
+ profiles->push_back(safari);
}
+#endif // defined(OS_MACOSX)
-void ImporterList::DetectSourceProfiles() {
-// The first run import will automatically take settings from the first
-// profile detected, which should be the user's current default.
+void DetectFirefoxProfiles(std::vector<importer::ProfileInfo*>* profiles) {
+ FilePath profile_path = GetFirefoxProfilePath();
+ if (profile_path.empty())
+ return;
+
+ // Detects which version of Firefox is installed.
+ importer::ProfileType firefox_type;
+ FilePath app_path;
+ int version = 0;
#if defined(OS_WIN)
- if (ShellIntegration::IsFirefoxDefaultBrowser()) {
- DetectFirefoxProfiles();
- DetectIEProfiles();
- } else {
- DetectIEProfiles();
- DetectFirefoxProfiles();
- }
- // TODO(brg) : Current UI requires win_util.
- DetectGoogleToolbarProfiles();
-#elif defined(OS_MACOSX)
- if (ShellIntegration::IsFirefoxDefaultBrowser()) {
- DetectFirefoxProfiles();
- DetectSafariProfiles();
+ version = GetCurrentFirefoxMajorVersionFromRegistry();
+#endif
+ if (version < 2)
+ GetFirefoxVersionAndPathFromProfile(profile_path, &version, &app_path);
+
+ if (version == 2) {
+ firefox_type = importer::FIREFOX2;
+ } else if (version >= 3) {
+ firefox_type = importer::FIREFOX3;
} else {
- DetectSafariProfiles();
- DetectFirefoxProfiles();
+ // Ignores other versions of firefox.
+ return;
}
-#else
- DetectFirefoxProfiles();
+
+ importer::ProfileInfo* firefox = new importer::ProfileInfo();
+ firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX);
+ firefox->browser_type = firefox_type;
+ firefox->source_path = profile_path;
+#if defined(OS_WIN)
+ firefox->app_path = FilePath::FromWStringHack(
+ GetFirefoxInstallPathFromRegistry());
#endif
+ if (firefox->app_path.empty())
+ firefox->app_path = app_path;
+ firefox->services_supported = importer::HISTORY | importer::FAVORITES |
+ importer::PASSWORDS | importer::SEARCH_ENGINES;
+ profiles->push_back(firefox);
+}
+
+void DetectGoogleToolbarProfiles(
+ std::vector<importer::ProfileInfo*>* profiles) {
+ if (FirstRun::IsChromeFirstRun())
+ return;
+
+ importer::ProfileInfo* google_toolbar = new importer::ProfileInfo();
+ google_toolbar->browser_type = importer::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 = importer::FAVORITES;
+ profiles->push_back(google_toolbar);
}
+} // namespace
+
+// static
Importer* ImporterList::CreateImporterByType(importer::ProfileType type) {
switch (type) {
#if defined(OS_WIN)
@@ -85,23 +141,53 @@ Importer* ImporterList::CreateImporterByType(importer::ProfileType type) {
return NULL;
}
+ImporterList::ImporterList()
+ : source_thread_id_(BrowserThread::UI),
+ observer_(NULL),
+ source_profiles_loaded_(false) {
+}
+
+ImporterList::~ImporterList() {
+}
+
+void ImporterList::DetectSourceProfiles(Observer* observer) {
+ DCHECK(observer);
+ observer_ = observer;
+
+ BrowserThread::GetCurrentThreadIdentifier(&source_thread_id_);
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ NewRunnableMethod(this, &ImporterList::DetectSourceProfilesWorker));
+}
+
+void ImporterList::DetectSourceProfilesHack() {
+ DetectSourceProfilesWorker();
+}
+
int ImporterList::GetAvailableProfileCount() const {
+ DCHECK(source_profiles_loaded_);
return static_cast<int>(source_profiles_.size());
}
std::wstring ImporterList::GetSourceProfileNameAt(int index) const {
+ DCHECK(source_profiles_loaded_);
DCHECK(index >=0 && index < GetAvailableProfileCount());
return source_profiles_[index]->description;
}
const importer::ProfileInfo& ImporterList::GetSourceProfileInfoAt(
int index) const {
+ DCHECK(source_profiles_loaded_);
DCHECK(index >=0 && index < GetAvailableProfileCount());
return *source_profiles_[index];
}
const importer::ProfileInfo& ImporterList::GetSourceProfileInfoForBrowserType(
int browser_type) const {
+ DCHECK(source_profiles_loaded_);
+
int count = GetAvailableProfileCount();
for (int i = 0; i < count; ++i) {
if (source_profiles_[i]->browser_type == browser_type)
@@ -111,83 +197,66 @@ const importer::ProfileInfo& ImporterList::GetSourceProfileInfoForBrowserType(
return *(new importer::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 = importer::MS_IE;
- ie->source_path.clear();
- ie->app_path.clear();
- ie->services_supported = importer::HISTORY | importer::FAVORITES |
- importer::COOKIES | importer::PASSWORDS | importer::SEARCH_ENGINES;
- source_profiles_.push_back(ie);
+bool ImporterList::source_profiles_loaded() const {
+ return source_profiles_loaded_;
}
-#endif
-void ImporterList::DetectFirefoxProfiles() {
- FilePath profile_path = GetFirefoxProfilePath();
- if (profile_path.empty())
- return;
+void ImporterList::DetectSourceProfilesWorker() {
+ // TODO(jhawkins): Remove this condition once DetectSourceProfileHack is
+ // removed. |observer_| is NULL when said method is called.
+ if (observer_)
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- // Detects which version of Firefox is installed.
- importer::ProfileType firefox_type;
- FilePath app_path;
- int version = 0;
-#if defined(OS_WIN)
- version = GetCurrentFirefoxMajorVersionFromRegistry();
-#endif
- if (version < 2)
- GetFirefoxVersionAndPathFromProfile(profile_path, &version, &app_path);
+ std::vector<importer::ProfileInfo*> profiles;
- if (version == 2) {
- firefox_type = importer::FIREFOX2;
- } else if (version >= 3) {
- firefox_type = importer::FIREFOX3;
+// The first run import will automatically take settings from the first
+// profile detected, which should be the user's current default.
+#if defined(OS_WIN)
+ if (ShellIntegration::IsFirefoxDefaultBrowser()) {
+ DetectFirefoxProfiles(&profiles);
+ DetectIEProfiles(&profiles);
} else {
- // Ignores other versions of firefox.
- return;
+ DetectIEProfiles(&profiles);
+ DetectFirefoxProfiles(&profiles);
}
-
- importer::ProfileInfo* firefox = new importer::ProfileInfo();
- firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX);
- firefox->browser_type = firefox_type;
- firefox->source_path = profile_path;
-#if defined(OS_WIN)
- firefox->app_path = FilePath::FromWStringHack(
- GetFirefoxInstallPathFromRegistry());
+ // TODO(brg) : Current UI requires win_util.
+ DetectGoogleToolbarProfiles(&profiles);
+#elif defined(OS_MACOSX)
+ if (ShellIntegration::IsFirefoxDefaultBrowser()) {
+ DetectFirefoxProfiles(&profiles);
+ DetectSafariProfiles(&profiles);
+ } else {
+ DetectSafariProfiles(&profiles);
+ DetectFirefoxProfiles(&profiles);
+ }
+#else
+ DetectFirefoxProfiles(&profiles);
#endif
- if (firefox->app_path.empty())
- firefox->app_path = app_path;
- firefox->services_supported = importer::HISTORY | importer::FAVORITES |
- importer::PASSWORDS | importer::SEARCH_ENGINES;
- source_profiles_.push_back(firefox);
-}
-
-void ImporterList::DetectGoogleToolbarProfiles() {
- if (!FirstRun::IsChromeFirstRun()) {
- importer::ProfileInfo* google_toolbar = new importer::ProfileInfo();
- google_toolbar->browser_type = importer::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 = importer::FAVORITES;
- source_profiles_.push_back(google_toolbar);
+
+ // TODO(jhawkins): Remove this condition once DetectSourceProfileHack is
+ // removed. |observer_| is NULL when said method is called.
+ if (observer_) {
+ BrowserThread::PostTask(
+ source_thread_id_,
+ FROM_HERE,
+ NewRunnableMethod(this, &ImporterList::SourceProfilesLoaded, profiles));
+ } else {
+ source_profiles_->assign(profiles.begin(), profiles.end());
+ source_profiles_loaded_ = true;
}
}
-#if defined(OS_MACOSX)
-void ImporterList::DetectSafariProfiles() {
- uint16 items = importer::NONE;
- if (SafariImporter::CanImport(mac_util::GetUserLibraryPath(), &items)) {
- importer::ProfileInfo* safari = new importer::ProfileInfo();
- safari->browser_type = importer::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);
- }
+void ImporterList::SourceProfilesLoaded(
+ const std::vector<importer::ProfileInfo*>& profiles) {
+ DCHECK_NE(static_cast<Observer*>(NULL), observer_);
+
+ BrowserThread::ID current_thread_id;
+ BrowserThread::GetCurrentThreadIdentifier(&current_thread_id);
+ DCHECK_EQ(current_thread_id, source_thread_id_);
+
+ source_profiles_->assign(profiles.begin(), profiles.end());
+ source_profiles_loaded_ = true;
+ observer_->SourceProfilesLoaded();
+ observer_ = NULL;
+ source_thread_id_ = BrowserThread::UI;
}
-#endif // OS_MACOSX