diff options
author | Kristian Monsen <kristianm@google.com> | 2011-05-11 20:53:37 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-05-16 13:54:48 +0100 |
commit | 21d179b334e59e9a3bfcaed4c4430bef1bc5759d (patch) | |
tree | 64e2bb6da27af6a5c93ca34f6051584aafbfcb9e /chrome/browser/importer | |
parent | 0c63f00edd6ed0482fd5cbcea937ca088baf7858 (diff) | |
download | external_chromium-21d179b334e59e9a3bfcaed4c4430bef1bc5759d.zip external_chromium-21d179b334e59e9a3bfcaed4c4430bef1bc5759d.tar.gz external_chromium-21d179b334e59e9a3bfcaed4c4430bef1bc5759d.tar.bz2 |
Merge Chromium at 10.0.621.0: Initial merge by git.
Change-Id: I070cc91c608dfa4a968a5a54c173260765ac8097
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r-- | chrome/browser/importer/firefox_importer_unittest_messages_internal.h | 9 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_importer_unittest_utils_mac.cc | 22 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 38 | ||||
-rw-r--r-- | chrome/browser/importer/importer.h | 82 | ||||
-rw-r--r-- | chrome/browser/importer/importer_bridge.h | 3 | ||||
-rw-r--r-- | chrome/browser/importer/importer_list.cc | 253 | ||||
-rw-r--r-- | chrome/browser/importer/importer_list.h | 70 | ||||
-rw-r--r-- | chrome/browser/importer/importer_messages.cc | 7 | ||||
-rw-r--r-- | chrome/browser/importer/importer_messages.h | 4 | ||||
-rw-r--r-- | chrome/browser/importer/importer_messages_internal.h | 95 | ||||
-rw-r--r-- | chrome/browser/importer/importer_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/importer/profile_writer.cc | 2 | ||||
-rw-r--r-- | chrome/browser/importer/toolbar_importer.cc | 2 |
13 files changed, 363 insertions, 227 deletions
diff --git a/chrome/browser/importer/firefox_importer_unittest_messages_internal.h b/chrome/browser/importer/firefox_importer_unittest_messages_internal.h index 68b2582..fd70f7f 100644 --- a/chrome/browser/importer/firefox_importer_unittest_messages_internal.h +++ b/chrome/browser/importer/firefox_importer_unittest_messages_internal.h @@ -2,15 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// This header is meant to be included in multiple passes, hence no traditional -// header guard. -// See ipc_message_macros.h for explanation of the macros and passes. - #include "ipc/ipc_message_macros.h" +#define IPC_MESSAGE_START FirefoxImporterUnittestMsgStart + // Messages definitions for messages sent between the unit test binary and // a child process by FFUnitTestDecryptorProxy. -IPC_BEGIN_MESSAGES(Test) // Server->Child: Initialize the decrytor with the following paramters. IPC_MESSAGE_CONTROL2(Msg_Decryptor_Init, @@ -29,5 +26,3 @@ IPC_MESSAGE_CONTROL1(Msg_Decryptor_Response, // Server->Child: Die. IPC_MESSAGE_CONTROL0(Msg_Decryptor_Quit) - -IPC_END_MESSAGES(Test) diff --git a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc index fbe3d3d..15ac4a2 100644 --- a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc +++ b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc @@ -14,19 +14,11 @@ #include "ipc/ipc_channel.h" #include "ipc/ipc_descriptors.h" #include "ipc/ipc_message.h" -#include "ipc/ipc_message_utils.h" #include "ipc/ipc_switches.h" #include "testing/multiprocess_func_list.h" -// Declaration of IPC Messages used for this test. -#define MESSAGES_INTERNAL_FILE \ - "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" -#include "ipc/ipc_message_macros.h" - -// Definition of IPC Messages used for this test. -#define MESSAGES_INTERNAL_IMPL_FILE \ - "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" -#include "ipc/ipc_message_impl_macros.h" +#define IPC_MESSAGE_IMPL +#include "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" namespace { @@ -102,11 +94,14 @@ class FFDecryptorServerChannelListener : public IPC::Channel::Listener { sender_->Send(new Msg_Decryptor_Quit()); } - virtual void OnMessageReceived(const IPC::Message& msg) { + virtual bool OnMessageReceived(const IPC::Message& msg) { + bool handled = true; IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResonse) + IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() + return handled; } // If an error occured, just kill the message Loop. @@ -239,12 +234,15 @@ class FFDecryptorClientChannelListener : public IPC::Channel::Listener { MessageLoop::current()->Quit(); } - virtual void OnMessageReceived(const IPC::Message& msg) { + virtual bool OnMessageReceived(const IPC::Message& msg) { + bool handled = true; IPC_BEGIN_MESSAGE_MAP(FFDecryptorClientChannelListener, msg) IPC_MESSAGE_HANDLER(Msg_Decryptor_Init, OnDecryptor_Init) IPC_MESSAGE_HANDLER(Msg_Decrypt, OnDecrypt) IPC_MESSAGE_HANDLER(Msg_Decryptor_Quit, OnQuitRequest) + IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() + return handled; } virtual void OnChannelError() { diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index a9deb82..6379e7b 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -20,7 +20,7 @@ #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/webdata/web_data_service.h" -#include "chrome/common/notification_service.h" +#include "chrome/common/notification_source.h" #include "gfx/codec/png_codec.h" #include "gfx/favicon_size.h" #include "grit/generated_resources.h" @@ -33,7 +33,7 @@ #include "chrome/browser/views/importer_lock_view.h" #include "views/window/window.h" #elif defined(OS_MACOSX) -#include "chrome/browser/cocoa/importer_lock_dialog.h" +#include "chrome/browser/ui/cocoa/importer_lock_dialog.h" #elif defined(TOOLKIT_USES_GTK) #include "chrome/browser/gtk/import_lock_dialog_gtk.h" #endif @@ -42,6 +42,8 @@ using webkit_glue::PasswordForm; // Importer. +void Importer::Cancel() { cancelled_ = true; } + Importer::Importer() : cancelled_(false), import_to_bookmark_bar_(false), @@ -85,8 +87,23 @@ ImporterHost::ImporterHost() installed_bookmark_observer_(false), is_source_readable_(true), headless_(false), - parent_window_(NULL) { - importer_list_.DetectSourceProfiles(); + parent_window_(NULL), + importer_list_(new ImporterList) { + importer_list_->DetectSourceProfilesHack(); +} + +ImporterHost::ImporterHost(ImporterList::Observer* observer) + : profile_(NULL), + observer_(NULL), + task_(NULL), + importer_(NULL), + waiting_for_bookmarkbar_model_(false), + installed_bookmark_observer_(false), + is_source_readable_(true), + headless_(false), + parent_window_(NULL), + importer_list_(new ImporterList) { + importer_list_->DetectSourceProfiles(observer); } ImporterHost::~ImporterHost() { @@ -171,7 +188,7 @@ void ImporterHost::StartImportSettings( // 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_ = ImporterList::CreateImporterByType(profile_info.browser_type); // If we fail to create Importer, exit as we cannot do anything. if (!importer_) { ImportEnded(); @@ -307,6 +324,15 @@ ExternalProcessImporterHost::ExternalProcessImporterHost() import_process_launched_(false) { } +ExternalProcessImporterHost::ExternalProcessImporterHost( + ImporterList::Observer* observer) + : ImporterHost(observer), + items_(0), + import_to_bookmark_bar_(false), + cancelled_(false), + import_process_launched_(false) { +} + void ExternalProcessImporterHost::Loaded(BookmarkModel* model) { DCHECK(model->IsLoaded()); model->RemoveObserver(this); @@ -434,7 +460,7 @@ void ExternalProcessImporterClient::NotifyItemFinishedOnIOThread( profile_import_process_host_->ReportImportItemFinished(import_item); } -void ExternalProcessImporterClient::OnProcessCrashed() { +void ExternalProcessImporterClient::OnProcessCrashed(int exit_code) { if (cancelled_) return; diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index 1cb9db7..e994036 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -55,9 +55,37 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, public BookmarkModelObserver, public NotificationObserver { public: + // An interface which an object can implement to be notified of events during + // the import process. + class Observer { + public: + // Invoked when data for the specified item is about to be collected. + virtual void ImportItemStarted(importer::ImportItem item) = 0; + + // Invoked when data for the specified item has been collected from the + // source profile and is now ready for further processing. + virtual void ImportItemEnded(importer::ImportItem item) = 0; + + // Invoked when the import begins. + virtual void ImportStarted() = 0; + + // Invoked when the source profile has been imported. + virtual void ImportEnded() = 0; + + protected: + virtual ~Observer() {} + }; + + // DEPRECATED: Calls the synchronous version of + // ImporterList::DetectSourceProfiles. + // TODO(jhawkins): Remove this constructor once all callers are fixed. + // See http://crbug.com/65633 and http://crbug.com/65638. ImporterHost(); - // BookmarkModelObserver methods. + // |observer| must not be NULL. + explicit ImporterHost(ImporterList::Observer* observer); + + // BookmarkModelObserver implementation. virtual void Loaded(BookmarkModel* model); virtual void BookmarkNodeMoved(BookmarkModel* model, const BookmarkNode* old_parent, @@ -79,10 +107,11 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, const BookmarkNode* node) {} virtual void BookmarkModelBeingDeleted(BookmarkModel* model); - // NotificationObserver method. Called when TemplateURLModel has been loaded. - void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); + // NotificationObserver implementation. Called when TemplateURLModel has been + // loaded. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); // ShowWarningDialog() asks user to close the application that is owning the // lock. They can retry or skip the importing process. @@ -122,24 +151,6 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, parent_window_ = parent_window; } - // An interface which an object can implement to be notified of events during - // the import process. - class Observer { - public: - virtual ~Observer() {} - // Invoked when data for the specified item is about to be collected. - virtual void ImportItemStarted(importer::ImportItem item) = 0; - - // Invoked when data for the specified item has been collected from the - // source profile and is now ready for further processing. - virtual void ImportItemEnded(importer::ImportItem item) = 0; - - // Invoked when the import begins. - virtual void ImportStarted() = 0; - - // Invoked when the source profile has been imported. - virtual void ImportEnded() = 0; - }; void SetObserver(Observer* observer); // A series of functions invoked at the start, during and end of the end @@ -152,25 +163,30 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, virtual void ImportEnded(); int GetAvailableProfileCount() const { - return importer_list_.GetAvailableProfileCount(); + return importer_list_->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); + return importer_list_->GetSourceProfileNameAt(index); } // Returns the ProfileInfo at the specified index. The ProfileInfo should be // passed to StartImportSettings(). const importer::ProfileInfo& GetSourceProfileInfoAt(int index) const { - return importer_list_.GetSourceProfileInfoAt(index); + return importer_list_->GetSourceProfileInfoAt(index); } // Returns the ProfileInfo with the given browser type. const importer::ProfileInfo& GetSourceProfileInfoForBrowserType( int browser_type) const { - return importer_list_.GetSourceProfileInfoForBrowserType(browser_type); + return importer_list_->GetSourceProfileInfoForBrowserType(browser_type); + } + + // Returns true if the source profiles have been loaded. + bool source_profiles_loaded() const { + return importer_list_->source_profiles_loaded(); } protected: @@ -240,7 +256,7 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, virtual void InvokeTaskIfDone(); // Used to create an importer of the appropriate type. - ImporterList importer_list_; + scoped_refptr<ImporterList> importer_list_; DISALLOW_COPY_AND_ASSIGN(ImporterHost); }; @@ -249,8 +265,14 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, // the importer bridge and the external process importer client. class ExternalProcessImporterHost : public ImporterHost { public: + // DEPRECATED: Calls the deprecated ImporterHost constructor. + // TODO(jhawkins): Remove this constructor once all callers are fixed. + // See http://crbug.com/65633 and http://crbug.com/65638. ExternalProcessImporterHost(); + // |observer| must not be NULL. + explicit ExternalProcessImporterHost(ImporterList::Observer* observer); + // Called when the BookmarkModel has finished loading. Calls InvokeTaskIfDone // to start importing. virtual void Loaded(BookmarkModel* model); @@ -327,7 +349,7 @@ class ExternalProcessImporterClient void NotifyItemFinishedOnIOThread(importer::ImportItem import_item); // Cancel import on process crash. - virtual void OnProcessCrashed(); + virtual void OnProcessCrashed(int exit_code); // Notifies the importerhost that import has finished, and calls Release(). void Cleanup(); @@ -447,7 +469,7 @@ class Importer : public base::RefCountedThreadSafe<Importer> { ImporterBridge* bridge) = 0; // Cancels the import process. - virtual void Cancel() { cancelled_ = true; } + virtual void Cancel(); void set_import_to_bookmark_bar(bool import_to_bookmark_bar) { import_to_bookmark_bar_ = import_to_bookmark_bar; diff --git a/chrome/browser/importer/importer_bridge.h b/chrome/browser/importer/importer_bridge.h index 186821e..43667b5 100644 --- a/chrome/browser/importer/importer_bridge.h +++ b/chrome/browser/importer/importer_bridge.h @@ -6,14 +6,11 @@ #define CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ #pragma once -#include "build/build_config.h" - #include <vector> #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "chrome/browser/browser_thread.h" #include "chrome/browser/importer/importer_data_types.h" // TODO: remove this, see friend declaration in ImporterBridge. #include "chrome/browser/importer/toolbar_importer.h" 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(¤t_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 diff --git a/chrome/browser/importer/importer_list.h b/chrome/browser/importer/importer_list.h index 6f98046..f3db148 100644 --- a/chrome/browser/importer/importer_list.h +++ b/chrome/browser/importer/importer_list.h @@ -9,23 +9,42 @@ #include <string> #include <vector> -#include "build/build_config.h" #include "base/basictypes.h" +#include "base/platform_thread.h" +#include "base/ref_counted.h" +#include "base/scoped_vector.h" +#include "build/build_config.h" +#include "chrome/browser/browser_thread.h" #include "chrome/browser/importer/importer_data_types.h" class Importer; -class ImporterList { +class ImporterList : public base::RefCountedThreadSafe<ImporterList> { public: + // Any class calling DetectSourceProfiles() must implement this interface in + // order to be called back when the source profiles are loaded. + class Observer { + public: + virtual void SourceProfilesLoaded() = 0; + + protected: + virtual ~Observer() {} + }; + + static Importer* CreateImporterByType(importer::ProfileType type); + 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(); + // of all profiles. Calls into DetectSourceProfilesWorker() on the FILE thread + // to do the real work of detecting source profiles. |observer| must be + // non-NULL. + void DetectSourceProfiles(Observer* observer); - Importer* CreateImporterByType(importer::ProfileType type); + // DEPRECATED: This method is synchronous and performs file operations which + // may end up blocking the current thread, which is usually the UI thread. + void DetectSourceProfilesHack(); // Returns the number of different browser profiles you can import from. int GetAvailableProfileCount() const; @@ -42,19 +61,38 @@ class ImporterList { const importer::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 + // Returns true if the source profiles have been loaded. + bool source_profiles_loaded() const; private: + friend class base::RefCountedThreadSafe<ImporterList>; + + ~ImporterList(); + + // The worker method for DetectSourceProfiles(). Must be called on the FILE + // thread. + void DetectSourceProfilesWorker(); + + // Called by DetectSourceProfilesWorker() on the source thread. This method + // notifies |observer_| that the source profiles are loaded. |profiles| is + // the vector of loaded profiles. + void SourceProfilesLoaded( + const std::vector<importer::ProfileInfo*>& profiles); + // The list of profiles with the default one first. - std::vector<importer::ProfileInfo*> source_profiles_; + ScopedVector<importer::ProfileInfo> source_profiles_; + + // The ID of the thread DetectSourceProfiles() is called on. Only valid after + // DetectSourceProfiles() is called and until SourceProfilesLoaded() has + // returned. + BrowserThread::ID source_thread_id_; + + // Weak reference. Only valid after DetectSourceProfiles() is called and until + // SourceProfilesLoaded() has returned. + Observer* observer_; + + // True if source profiles are loaded. + bool source_profiles_loaded_; DISALLOW_COPY_AND_ASSIGN(ImporterList); }; diff --git a/chrome/browser/importer/importer_messages.cc b/chrome/browser/importer/importer_messages.cc index d20452a..9120a2b 100644 --- a/chrome/browser/importer/importer_messages.cc +++ b/chrome/browser/importer/importer_messages.cc @@ -2,10 +2,7 @@ // 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_messages.h" - #include "base/values.h" -#define MESSAGES_INTERNAL_IMPL_FILE \ - "chrome/browser/importer/importer_messages_internal.h" -#include "ipc/ipc_message_impl_macros.h" +#define IPC_MESSAGE_IMPL +#include "chrome/browser/importer/importer_messages.h" diff --git a/chrome/browser/importer/importer_messages.h b/chrome/browser/importer/importer_messages.h index fd7b1dc..e05aac8 100644 --- a/chrome/browser/importer/importer_messages.h +++ b/chrome/browser/importer/importer_messages.h @@ -363,8 +363,6 @@ struct ParamTraits<TemplateURL> { } // namespace IPC -#define MESSAGES_INTERNAL_FILE \ - "chrome/browser/importer/importer_messages_internal.h" -#include "ipc/ipc_message_macros.h" +#include "chrome/browser/importer/importer_messages_internal.h" #endif // CHROME_BROWSER_IMPORTER_IMPORTER_MESSAGES_H_ diff --git a/chrome/browser/importer/importer_messages_internal.h b/chrome/browser/importer/importer_messages_internal.h index 980e397..20e7770 100644 --- a/chrome/browser/importer/importer_messages_internal.h +++ b/chrome/browser/importer/importer_messages_internal.h @@ -10,73 +10,70 @@ #include "ipc/ipc_message_macros.h" #include "webkit/glue/password_form.h" +#define IPC_MESSAGE_START ProfileImportMsgStart + //----------------------------------------------------------------------------- // ProfileImportProcess messages // These are messages sent from the browser to the profile import process. -IPC_BEGIN_MESSAGES(ProfileImportProcess) - IPC_MESSAGE_CONTROL4(ProfileImportProcessMsg_StartImport, - importer::ProfileInfo /* ProfileInfo struct */, - int /* bitmask of items to import */, - DictionaryValue /* localized strings */, - bool /* import to bookmark bar */) +IPC_MESSAGE_CONTROL4(ProfileImportProcessMsg_StartImport, + importer::ProfileInfo /* ProfileInfo struct */, + int /* bitmask of items to import */, + DictionaryValue /* localized strings */, + bool /* import to bookmark bar */) - IPC_MESSAGE_CONTROL0(ProfileImportProcessMsg_CancelImport) +IPC_MESSAGE_CONTROL0(ProfileImportProcessMsg_CancelImport) - IPC_MESSAGE_CONTROL1(ProfileImportProcessMsg_ReportImportItemFinished, - int /* ImportItem */) -IPC_END_MESSAGES(ProfileImportProcess) +IPC_MESSAGE_CONTROL1(ProfileImportProcessMsg_ReportImportItemFinished, + int /* ImportItem */) //--------------------------------------------------------------------------- // ProfileImportProcessHost messages // These are messages sent from the profile import process to the browser. -IPC_BEGIN_MESSAGES(ProfileImportProcessHost) - // These messages send information about the status of the import and - // individual import tasks. - IPC_MESSAGE_CONTROL0(ProfileImportProcessHostMsg_Import_Started) - - IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_Import_Finished, - bool /* was import successful? */, - std::string /* error message, if any */) +// These messages send information about the status of the import and +// individual import tasks. +IPC_MESSAGE_CONTROL0(ProfileImportProcessHostMsg_Import_Started) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_ImportItem_Started, - int /* ImportItem */) +IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_Import_Finished, + bool /* was import successful? */, + std::string /* error message, if any */) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_ImportItem_Finished, - int /* ImportItem */) +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_ImportItem_Started, + int /* ImportItem */) - // These messages send data from the external importer process back to - // the process host so it can be written to the profile. - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHistoryImportStart, - int /* total number of history::URLRow items */) +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_ImportItem_Finished, + int /* ImportItem */) - IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_NotifyHistoryImportGroup, - std::vector<history::URLRow>, - int /* the source of URLs as in history::VisitSource.*/ - /* To simplify IPC call, pass as an integer */) +// These messages send data from the external importer process back to +// the process host so it can be written to the profile. +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHistoryImportStart, + int /* total number of history::URLRow items */) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHomePageImportReady, - GURL /* GURL of home page */) +IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_NotifyHistoryImportGroup, + std::vector<history::URLRow>, + int /* the source of URLs as in history::VisitSource.*/ + /* To simplify IPC call, pass as an integer */) - IPC_MESSAGE_CONTROL3(ProfileImportProcessHostMsg_NotifyBookmarksImportStart, - std::wstring /* first folder name */, - int /* options */, - int /* total number of bookmarks */) +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHomePageImportReady, + GURL /* GURL of home page */) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyBookmarksImportGroup, - std::vector<ProfileWriter::BookmarkEntry>) +IPC_MESSAGE_CONTROL3(ProfileImportProcessHostMsg_NotifyBookmarksImportStart, + std::wstring /* first folder name */, + int /* options */, + int /* total number of bookmarks */) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFavIconsImportStart, - int /* total number of FavIcons */) +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyBookmarksImportGroup, + std::vector<ProfileWriter::BookmarkEntry>) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFavIconsImportGroup, - std::vector<history::ImportedFavIconUsage> ) +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFavIconsImportStart, + int /* total number of FavIcons */) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyPasswordFormReady, - webkit_glue::PasswordForm ) +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFavIconsImportGroup, + std::vector<history::ImportedFavIconUsage> ) - IPC_MESSAGE_CONTROL3(ProfileImportProcessHostMsg_NotifyKeywordsReady, - std::vector<TemplateURL>, - int, /* default keyword index */ - bool /* unique on host and path */) -IPC_END_MESSAGES(ProfileImportProcessHost) +IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyPasswordFormReady, + webkit_glue::PasswordForm ) +IPC_MESSAGE_CONTROL3(ProfileImportProcessHostMsg_NotifyKeywordsReady, + std::vector<TemplateURL>, + int, /* default keyword index */ + bool /* unique on host and path */) diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index 214f056..56ac2cc 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -29,14 +29,13 @@ #include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/chrome_paths.h" #include "webkit/glue/password_form.h" #if defined(OS_WIN) -#include "base/scoped_comptr_win.h" #include "app/win_util.h" +#include "base/scoped_comptr_win.h" #include "chrome/browser/importer/ie_importer.h" #include "chrome/browser/password_manager/ie7_password.h" #endif diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc index 57ddffc..68e5c96 100644 --- a/chrome/browser/importer/profile_writer.cc +++ b/chrome/browser/importer/profile_writer.cc @@ -11,7 +11,7 @@ #include "chrome/browser/importer/importer.h" #include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profile.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/common/notification_service.h" diff --git a/chrome/browser/importer/toolbar_importer.cc b/chrome/browser/importer/toolbar_importer.cc index da367f8..cc3411c 100644 --- a/chrome/browser/importer/toolbar_importer.cc +++ b/chrome/browser/importer/toolbar_importer.cc @@ -16,7 +16,7 @@ #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/profile.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/libxml_utils.h" #include "chrome/common/net/url_request_context_getter.h" #include "grit/generated_resources.h" |