diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 21:57:50 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 21:57:50 +0000 |
commit | 9e497dd1a3174372eda0d4322a959f576415a8c9 (patch) | |
tree | 903a4120fdfb0b84d8d5142eb3add850da778200 /chrome | |
parent | 415c2cdea5dfa8bc87bd36a91bdb8473026f943f (diff) | |
download | chromium_src-9e497dd1a3174372eda0d4322a959f576415a8c9.zip chromium_src-9e497dd1a3174372eda0d4322a959f576415a8c9.tar.gz chromium_src-9e497dd1a3174372eda0d4322a959f576415a8c9.tar.bz2 |
importer: Pull ExternalProcessImporterClient out of ImporterHost.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/6679004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/importer/external_process_importer_client.cc | 237 | ||||
-rw-r--r-- | chrome/browser/importer/external_process_importer_client.h | 164 | ||||
-rw-r--r-- | chrome/browser/importer/importer_host.cc | 228 | ||||
-rw-r--r-- | chrome/browser/importer/importer_host.h | 138 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
5 files changed, 404 insertions, 365 deletions
diff --git a/chrome/browser/importer/external_process_importer_client.cc b/chrome/browser/importer/external_process_importer_client.cc new file mode 100644 index 0000000..e5dc7c0 --- /dev/null +++ b/chrome/browser/importer/external_process_importer_client.cc @@ -0,0 +1,237 @@ +// Copyright (c) 2011 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/external_process_importer_client.h" + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/importer/importer_bridge.h" +#include "chrome/browser/importer/importer_host.h" +#include "chrome/browser/search_engines/template_url.h" +#include "chrome/browser/search_engines/template_url_model.h" +#include "content/browser/browser_thread.h" + +ExternalProcessImporterClient::ExternalProcessImporterClient( + ExternalProcessImporterHost* importer_host, + const importer::ProfileInfo& profile_info, + uint16 items, + InProcessImporterBridge* bridge, + bool import_to_bookmark_bar) + : bookmarks_options_(0), + total_bookmarks_count_(0), + total_history_rows_count_(0), + total_fav_icons_count_(0), + process_importer_host_(importer_host), + profile_import_process_host_(NULL), + profile_info_(profile_info), + items_(items), + import_to_bookmark_bar_(import_to_bookmark_bar), + bridge_(bridge), + cancelled_(false) { + bridge_->AddRef(); + process_importer_host_->NotifyImportStarted(); +} + +ExternalProcessImporterClient::~ExternalProcessImporterClient() { + bridge_->Release(); +} + +void ExternalProcessImporterClient::CancelImportProcessOnIOThread() { + profile_import_process_host_->CancelProfileImportProcess(); +} + +void ExternalProcessImporterClient::NotifyItemFinishedOnIOThread( + importer::ImportItem import_item) { + profile_import_process_host_->ReportImportItemFinished(import_item); +} + +void ExternalProcessImporterClient::Cleanup() { + if (cancelled_) + return; + + if (process_importer_host_) + process_importer_host_->NotifyImportEnded(); + Release(); +} + +void ExternalProcessImporterClient::Start() { + AddRef(); // balanced in Cleanup. + BrowserThread::ID thread_id; + CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_id)); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + NewRunnableMethod(this, + &ExternalProcessImporterClient::StartProcessOnIOThread, + g_browser_process->resource_dispatcher_host(), thread_id)); +} + +void ExternalProcessImporterClient::StartProcessOnIOThread( + ResourceDispatcherHost* rdh, + BrowserThread::ID thread_id) { + profile_import_process_host_ = + new ProfileImportProcessHost(rdh, this, thread_id); + profile_import_process_host_->StartProfileImportProcess(profile_info_, + items_, import_to_bookmark_bar_); +} + +void ExternalProcessImporterClient::Cancel() { + if (cancelled_) + return; + + cancelled_ = true; + if (profile_import_process_host_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + NewRunnableMethod(this, + &ExternalProcessImporterClient::CancelImportProcessOnIOThread)); + } + Release(); +} + +void ExternalProcessImporterClient::OnProcessCrashed(int exit_code) { + if (cancelled_) + return; + + process_importer_host_->Cancel(); +} + +void ExternalProcessImporterClient::OnImportStart() { + if (cancelled_) + return; + + bridge_->NotifyStarted(); +} + +void ExternalProcessImporterClient::OnImportFinished(bool succeeded, + std::string error_msg) { + if (cancelled_) + return; + + if (!succeeded) + LOG(WARNING) << "Import failed. Error: " << error_msg; + Cleanup(); +} + +void ExternalProcessImporterClient::OnImportItemStart(int item_data) { + if (cancelled_) + return; + + bridge_->NotifyItemStarted(static_cast<importer::ImportItem>(item_data)); +} + +void ExternalProcessImporterClient::OnImportItemFinished(int item_data) { + if (cancelled_) + return; + + importer::ImportItem import_item = + static_cast<importer::ImportItem>(item_data); + bridge_->NotifyItemEnded(import_item); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + NewRunnableMethod(this, + &ExternalProcessImporterClient::NotifyItemFinishedOnIOThread, + import_item)); +} + +void ExternalProcessImporterClient::OnHistoryImportStart( + size_t total_history_rows_count) { + if (cancelled_) + return; + + total_history_rows_count_ = total_history_rows_count; + history_rows_.reserve(total_history_rows_count); +} + +void ExternalProcessImporterClient::OnHistoryImportGroup( + const std::vector<history::URLRow>& history_rows_group, + int visit_source) { + if (cancelled_) + return; + + history_rows_.insert(history_rows_.end(), history_rows_group.begin(), + history_rows_group.end()); + if (history_rows_.size() == total_history_rows_count_) + bridge_->SetHistoryItems(history_rows_, + static_cast<history::VisitSource>(visit_source)); +} + +void ExternalProcessImporterClient::OnHomePageImportReady( + const GURL& home_page) { + if (cancelled_) + return; + + bridge_->AddHomePage(home_page); +} + +void ExternalProcessImporterClient::OnBookmarksImportStart( + const std::wstring first_folder_name, + int options, size_t total_bookmarks_count) { + if (cancelled_) + return; + + bookmarks_first_folder_name_ = first_folder_name; + bookmarks_options_ = options; + total_bookmarks_count_ = total_bookmarks_count; + bookmarks_.reserve(total_bookmarks_count); +} + +void ExternalProcessImporterClient::OnBookmarksImportGroup( + const std::vector<ProfileWriter::BookmarkEntry>& bookmarks_group) { + if (cancelled_) + return; + + // Collect sets of bookmarks from importer process until we have reached + // total_bookmarks_count_: + bookmarks_.insert(bookmarks_.end(), bookmarks_group.begin(), + bookmarks_group.end()); + if (bookmarks_.size() == total_bookmarks_count_) { + bridge_->AddBookmarkEntries(bookmarks_, bookmarks_first_folder_name_, + bookmarks_options_); + } +} + +void ExternalProcessImporterClient::OnFavIconsImportStart( + size_t total_fav_icons_count) { + if (cancelled_) + return; + + total_fav_icons_count_ = total_fav_icons_count; + fav_icons_.reserve(total_fav_icons_count); +} + +void ExternalProcessImporterClient::OnFavIconsImportGroup( + const std::vector<history::ImportedFavIconUsage>& fav_icons_group) { + if (cancelled_) + return; + + fav_icons_.insert(fav_icons_.end(), fav_icons_group.begin(), + fav_icons_group.end()); + if (fav_icons_.size() == total_fav_icons_count_) + bridge_->SetFavIcons(fav_icons_); +} + +void ExternalProcessImporterClient::OnPasswordFormImportReady( + const webkit_glue::PasswordForm& form) { + if (cancelled_) + return; + + bridge_->SetPasswordForm(form); +} + +void ExternalProcessImporterClient::OnKeywordsImportReady( + const std::vector<TemplateURL>& template_urls, + int default_keyword_index, bool unique_on_host_and_path) { + if (cancelled_) + return; + + std::vector<TemplateURL*> template_url_vec; + template_url_vec.reserve(template_urls.size()); + std::vector<TemplateURL>::const_iterator iter; + for (iter = template_urls.begin(); + iter != template_urls.end(); + ++iter) { + template_url_vec.push_back(new TemplateURL(*iter)); + } + bridge_->SetKeywords(template_url_vec, default_keyword_index, + unique_on_host_and_path); +} diff --git a/chrome/browser/importer/external_process_importer_client.h b/chrome/browser/importer/external_process_importer_client.h new file mode 100644 index 0000000..0cb5484 --- /dev/null +++ b/chrome/browser/importer/external_process_importer_client.h @@ -0,0 +1,164 @@ +// Copyright (c) 2011 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_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ +#define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ +#pragma once + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/importer/profile_writer.h" +#include "chrome/browser/profile_import_process_host.h" + +class ExternalProcessImporterHost; +class InProcessImporterBridge; + +namespace history { +class URLRow; +struct ImportedFavIconUsage; +} + +namespace importer { +struct ProfileInfo; +} + +// This class is the client for the ProfileImportProcessHost. It collects +// notifications from this process host and feeds data back to the importer +// host, who actually does the writing. +class ExternalProcessImporterClient + : public ProfileImportProcessHost::ImportProcessClient { + public: + ExternalProcessImporterClient(ExternalProcessImporterHost* importer_host, + const importer::ProfileInfo& profile_info, + uint16 items, + InProcessImporterBridge* bridge, + bool import_to_bookmark_bar); + virtual ~ExternalProcessImporterClient(); + + // Cancel import process on IO thread. + void CancelImportProcessOnIOThread(); + + // Report item completely downloaded on IO thread. + void NotifyItemFinishedOnIOThread(importer::ImportItem import_item); + + // Notifies the importerhost that import has finished, and calls Release(). + void Cleanup(); + + // Launches the task to start the external process. + virtual void Start(); + + // Creates a new ProfileImportProcessHost, which launches the import process. + virtual void StartProcessOnIOThread(ResourceDispatcherHost* rdh, + BrowserThread::ID thread_id); + + // Called by the ExternalProcessImporterHost on import cancel. + virtual void Cancel(); + + // Begin ProfileImportProcessHost::ImportProcessClient implementation. + virtual void OnProcessCrashed(int exit_status) OVERRIDE; + virtual void OnImportStart() OVERRIDE; + virtual void OnImportFinished(bool succeeded, std::string error_msg) OVERRIDE; + virtual void OnImportItemStart(int item) OVERRIDE; + virtual void OnImportItemFinished(int item) OVERRIDE; + + // Called on first message received when importing history; gives total + // number of rows to be imported. + virtual void OnHistoryImportStart(size_t total_history_rows_count) OVERRIDE; + + // Called when a group of URLRows has been received. + // The source is passed with history::VisitSource type. + virtual void OnHistoryImportGroup( + const std::vector<history::URLRow> &history_rows_group, + int visit_source) OVERRIDE; + + // Called when the home page has been received. + virtual void OnHomePageImportReady(const GURL& home_page) OVERRIDE; + + // First message received when importing bookmarks. + // |first_folder_name| can be NULL. + // |options| is described in ProfileWriter::BookmarkOptions. + // |total_bookmarks_count| is the total number of bookmarks to be imported. + virtual void OnBookmarksImportStart(const std::wstring first_folder_name, + int options, + size_t total_bookmarks_count) OVERRIDE; + + // Called when a group of bookmarks has been received. + virtual void OnBookmarksImportGroup( + const std::vector<ProfileWriter::BookmarkEntry>& bookmarks_group) + OVERRIDE; + + // First message received when importing favicons. |total_fav_icons_size| + // gives the total number of fav icons to be imported. + virtual void OnFavIconsImportStart(size_t total_fav_icons_count) OVERRIDE; + + // Called when a group of favicons has been received. + virtual void OnFavIconsImportGroup( + const std::vector<history::ImportedFavIconUsage>& fav_icons_group) + OVERRIDE; + + // Called when the passwordform has been received. + virtual void OnPasswordFormImportReady( + const webkit_glue::PasswordForm& form) OVERRIDE; + + // Called when search engines have been received. + virtual void OnKeywordsImportReady( + const std::vector<TemplateURL>& template_urls, + int default_keyword_index, + bool unique_on_host_and_path) OVERRIDE; + + // End ProfileImportProcessHost::ImportProcessClient implementation. + + private: + // These variables store data being collected from the importer until the + // entire group has been collected and is ready to be written to the profile. + std::vector<history::URLRow> history_rows_; + std::vector<ProfileWriter::BookmarkEntry> bookmarks_; + std::vector<history::ImportedFavIconUsage> fav_icons_; + + // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder + // under which imported bookmarks will be placed. + std::wstring bookmarks_first_folder_name_; + + // Determines how bookmarks should be added (ProfileWriter::BookmarkOptions). + int bookmarks_options_; + + // Total number of bookmarks to import. + size_t total_bookmarks_count_; + + // Total number of history items to import. + size_t total_history_rows_count_; + + // Total number of fav icons to import. + size_t total_fav_icons_count_; + + // Notifications received from the ProfileImportProcessHost are passed back + // to process_importer_host_, which calls the ProfileWriter to record the + // import data. When the import process is done, process_importer_host_ + // deletes itself. + ExternalProcessImporterHost* process_importer_host_; + + // Handles sending messages to the external process. Deletes itself when + // the external process dies (see ChildProcessHost::OnChildDied). + ProfileImportProcessHost* profile_import_process_host_; + + // Data to be passed from the importer host to the external importer. + const importer::ProfileInfo& profile_info_; + uint16 items_; + bool import_to_bookmark_bar_; + + // Takes import data coming over IPC and delivers it to be written by the + // ProfileWriter. Released by ExternalProcessImporterClient in its + // destructor. + InProcessImporterBridge* bridge_; + + // True if import process has been cancelled. + bool cancelled_; + + DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient); +}; + +#endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_CLIENT_H_ diff --git a/chrome/browser/importer/importer_host.cc b/chrome/browser/importer/importer_host.cc index 07445eb..7152124 100644 --- a/chrome/browser/importer/importer_host.cc +++ b/chrome/browser/importer/importer_host.cc @@ -8,6 +8,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/importer/external_process_importer_client.h" #include "chrome/browser/importer/firefox_profile_lock.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_lock_dialog.h" @@ -315,230 +316,3 @@ void ExternalProcessImporterHost::Loaded(BookmarkModel* model) { import_to_bookmark_bar_ = (!model->HasBookmarks()); InvokeTaskIfDone(); } - -// ExternalProcessImporterClient ----------------------------------------------- - -ExternalProcessImporterClient::ExternalProcessImporterClient( - ExternalProcessImporterHost* importer_host, - const importer::ProfileInfo& profile_info, - int items, - InProcessImporterBridge* bridge, - bool import_to_bookmark_bar) - : bookmarks_options_(0), - total_bookmarks_count_(0), - total_history_rows_count_(0), - total_fav_icons_count_(0), - process_importer_host_(importer_host), - profile_import_process_host_(NULL), - profile_info_(profile_info), - items_(items), - import_to_bookmark_bar_(import_to_bookmark_bar), - bridge_(bridge), - cancelled_(false) { - bridge_->AddRef(); - process_importer_host_->NotifyImportStarted(); -} - -ExternalProcessImporterClient::~ExternalProcessImporterClient() { - bridge_->Release(); -} - -void ExternalProcessImporterClient::Start() { - AddRef(); // balanced in Cleanup. - BrowserThread::ID thread_id; - CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_id)); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, - &ExternalProcessImporterClient::StartProcessOnIOThread, - g_browser_process->resource_dispatcher_host(), thread_id)); -} - -void ExternalProcessImporterClient::StartProcessOnIOThread( - ResourceDispatcherHost* rdh, - BrowserThread::ID thread_id) { - profile_import_process_host_ = - new ProfileImportProcessHost(rdh, this, thread_id); - profile_import_process_host_->StartProfileImportProcess(profile_info_, - items_, import_to_bookmark_bar_); -} - -void ExternalProcessImporterClient::Cancel() { - if (cancelled_) - return; - - cancelled_ = true; - if (profile_import_process_host_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, - &ExternalProcessImporterClient::CancelImportProcessOnIOThread)); - } - Release(); -} - -void ExternalProcessImporterClient::CancelImportProcessOnIOThread() { - profile_import_process_host_->CancelProfileImportProcess(); -} - -void ExternalProcessImporterClient::NotifyItemFinishedOnIOThread( - importer::ImportItem import_item) { - profile_import_process_host_->ReportImportItemFinished(import_item); -} - -void ExternalProcessImporterClient::OnProcessCrashed(int exit_code) { - if (cancelled_) - return; - - process_importer_host_->Cancel(); -} - -void ExternalProcessImporterClient::Cleanup() { - if (cancelled_) - return; - - if (process_importer_host_) - process_importer_host_->NotifyImportEnded(); - Release(); -} - -void ExternalProcessImporterClient::OnImportStart() { - if (cancelled_) - return; - - bridge_->NotifyStarted(); -} - -void ExternalProcessImporterClient::OnImportFinished(bool succeeded, - std::string error_msg) { - if (cancelled_) - return; - - if (!succeeded) - LOG(WARNING) << "Import failed. Error: " << error_msg; - Cleanup(); -} - -void ExternalProcessImporterClient::OnImportItemStart(int item_data) { - if (cancelled_) - return; - - bridge_->NotifyItemStarted(static_cast<importer::ImportItem>(item_data)); -} - -void ExternalProcessImporterClient::OnImportItemFinished(int item_data) { - if (cancelled_) - return; - - importer::ImportItem import_item = - static_cast<importer::ImportItem>(item_data); - bridge_->NotifyItemEnded(import_item); - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - NewRunnableMethod(this, - &ExternalProcessImporterClient::NotifyItemFinishedOnIOThread, - import_item)); -} - -void ExternalProcessImporterClient::OnHistoryImportStart( - size_t total_history_rows_count) { - if (cancelled_) - return; - - total_history_rows_count_ = total_history_rows_count; - history_rows_.reserve(total_history_rows_count); -} - -void ExternalProcessImporterClient::OnHistoryImportGroup( - const std::vector<history::URLRow>& history_rows_group, - int visit_source) { - if (cancelled_) - return; - - history_rows_.insert(history_rows_.end(), history_rows_group.begin(), - history_rows_group.end()); - if (history_rows_.size() == total_history_rows_count_) - bridge_->SetHistoryItems(history_rows_, - static_cast<history::VisitSource>(visit_source)); -} - -void ExternalProcessImporterClient::OnHomePageImportReady( - const GURL& home_page) { - if (cancelled_) - return; - - bridge_->AddHomePage(home_page); -} - -void ExternalProcessImporterClient::OnBookmarksImportStart( - const std::wstring first_folder_name, - int options, size_t total_bookmarks_count) { - if (cancelled_) - return; - - bookmarks_first_folder_name_ = first_folder_name; - bookmarks_options_ = options; - total_bookmarks_count_ = total_bookmarks_count; - bookmarks_.reserve(total_bookmarks_count); -} - -void ExternalProcessImporterClient::OnBookmarksImportGroup( - const std::vector<ProfileWriter::BookmarkEntry>& bookmarks_group) { - if (cancelled_) - return; - - // Collect sets of bookmarks from importer process until we have reached - // total_bookmarks_count_: - bookmarks_.insert(bookmarks_.end(), bookmarks_group.begin(), - bookmarks_group.end()); - if (bookmarks_.size() == total_bookmarks_count_) { - bridge_->AddBookmarkEntries(bookmarks_, bookmarks_first_folder_name_, - bookmarks_options_); - } -} - -void ExternalProcessImporterClient::OnFavIconsImportStart( - size_t total_fav_icons_count) { - if (cancelled_) - return; - - total_fav_icons_count_ = total_fav_icons_count; - fav_icons_.reserve(total_fav_icons_count); -} - -void ExternalProcessImporterClient::OnFavIconsImportGroup( - const std::vector<history::ImportedFavIconUsage>& fav_icons_group) { - if (cancelled_) - return; - - fav_icons_.insert(fav_icons_.end(), fav_icons_group.begin(), - fav_icons_group.end()); - if (fav_icons_.size() == total_fav_icons_count_) - bridge_->SetFavIcons(fav_icons_); -} - -void ExternalProcessImporterClient::OnPasswordFormImportReady( - const webkit_glue::PasswordForm& form) { - if (cancelled_) - return; - - bridge_->SetPasswordForm(form); -} - -void ExternalProcessImporterClient::OnKeywordsImportReady( - const std::vector<TemplateURL>& template_urls, - int default_keyword_index, bool unique_on_host_and_path) { - if (cancelled_) - return; - - std::vector<TemplateURL*> template_url_vec; - template_url_vec.reserve(template_urls.size()); - std::vector<TemplateURL>::const_iterator iter; - for (iter = template_urls.begin(); - iter != template_urls.end(); - ++iter) { - template_url_vec.push_back(new TemplateURL(*iter)); - } - bridge_->SetKeywords(template_url_vec, default_keyword_index, - unique_on_host_and_path); -} diff --git a/chrome/browser/importer/importer_host.h b/chrome/browser/importer/importer_host.h index 4b20633..1b94a4a 100644 --- a/chrome/browser/importer/importer_host.h +++ b/chrome/browser/importer/importer_host.h @@ -17,7 +17,6 @@ #include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/importer/importer_list.h" #include "chrome/browser/importer/profile_writer.h" -#include "chrome/browser/profile_import_process_host.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" #include "ui/gfx/native_widget_types.h" @@ -222,141 +221,4 @@ class ExternalProcessImporterHost : public ImporterHost { DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterHost); }; -// This class is the client for the ProfileImportProcessHost. It collects -// notifications from this process host and feeds data back to the importer -// host, who actually does the writing. -class ExternalProcessImporterClient - : public ProfileImportProcessHost::ImportProcessClient { - public: - ExternalProcessImporterClient(ExternalProcessImporterHost* importer_host, - const importer::ProfileInfo& profile_info, - int items, - InProcessImporterBridge* bridge, - bool import_to_bookmark_bar); - - ~ExternalProcessImporterClient(); - - // Launches the task to start the external process. - virtual void Start(); - - // Creates a new ProfileImportProcessHost, which launches the import process. - virtual void StartProcessOnIOThread(ResourceDispatcherHost* rdh, - BrowserThread::ID thread_id); - - // Called by the ExternalProcessImporterHost on import cancel. - virtual void Cancel(); - - // Cancel import process on IO thread. - void CancelImportProcessOnIOThread(); - - // Report item completely downloaded on IO thread. - void NotifyItemFinishedOnIOThread(importer::ImportItem import_item); - - // Cancel import on process crash. - virtual void OnProcessCrashed(int exit_code); - - // Notifies the importerhost that import has finished, and calls Release(). - void Cleanup(); - - // ProfileImportProcessHost messages ---------------------------------------- - // The following methods are called by ProfileImportProcessHost when the - // corresponding message has been received from the import process. - virtual void OnImportStart(); - virtual void OnImportFinished(bool succeeded, std::string error_msg); - virtual void OnImportItemStart(int item_data); - virtual void OnImportItemFinished(int item_data); - - // Called on first message received when importing history; gives total - // number of rows to be imported. - virtual void OnHistoryImportStart(size_t total_history_rows_count); - - // Called when a group of URLRows has been received. - // The source is passed with history::VisitSource type. - virtual void OnHistoryImportGroup( - const std::vector<history::URLRow> &history_rows_group, - int visit_source); - - // Called when the home page has been received. - virtual void OnHomePageImportReady(const GURL& home_page); - - // First message received when importing bookmarks. - // |first_folder_name| can be NULL. - // |options| is described in ProfileWriter::BookmarkOptions. - // |total_bookmarks_count| is the total number of bookmarks to be imported. - virtual void OnBookmarksImportStart( - const std::wstring first_folder_name, - int options, size_t total_bookmarks_count); - - // Called when a group of bookmarks has been received. - virtual void OnBookmarksImportGroup( - const std::vector<ProfileWriter::BookmarkEntry>& bookmarks_group); - - // First message received when importing favicons. |total_fav_icons_size| - // gives the total number of fav icons to be imported. - virtual void OnFavIconsImportStart(size_t total_fav_icons_count); - - // Called when a group of favicons has been received. - virtual void OnFavIconsImportGroup( - const std::vector<history::ImportedFavIconUsage>& fav_icons_group); - - // Called when the passwordform has been received. - virtual void OnPasswordFormImportReady( - const webkit_glue::PasswordForm& form); - - // Called when search engines have been received. - virtual void OnKeywordsImportReady( - const std::vector<TemplateURL>& template_urls, - int default_keyword_index, bool unique_on_host_and_path); - - // End ProfileImportProcessHost messages ------------------------------------ - - private: - // These variables store data being collected from the importer until the - // entire group has been collected and is ready to be written to the profile. - std::vector<history::URLRow> history_rows_; - std::vector<ProfileWriter::BookmarkEntry> bookmarks_; - std::vector<history::ImportedFavIconUsage> fav_icons_; - - // Usually some variation on IDS_BOOKMARK_GROUP_...; the name of the folder - // under which imported bookmarks will be placed. - std::wstring bookmarks_first_folder_name_; - - // Determines how bookmarks should be added (ProfileWriter::BookmarkOptions). - int bookmarks_options_; - - // Total number of bookmarks to import. - size_t total_bookmarks_count_; - - // Total number of history items to import. - size_t total_history_rows_count_; - - // Total number of fav icons to import. - size_t total_fav_icons_count_; - - // Notifications received from the ProfileImportProcessHost are passed back - // to process_importer_host_, which calls the ProfileWriter to record the - // import data. When the import process is done, process_importer_host_ - // deletes itself. - ExternalProcessImporterHost* process_importer_host_; - - // Handles sending messages to the external process. Deletes itself when - // the external process dies (see ChildProcessHost::OnChildDied). - ProfileImportProcessHost* profile_import_process_host_; - - // Data to be passed from the importer host to the external importer. - const importer::ProfileInfo& profile_info_; - int items_; - bool import_to_bookmark_bar_; - - // Takes import data coming over IPC and delivers it to be written by the - // ProfileWriter. Released by ExternalProcessImporterClient in its - // destructor. - InProcessImporterBridge* bridge_; - - // True if import process has been cancelled. - bool cancelled_; - - DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterClient); -}; - #endif // CHROME_BROWSER_IMPORTER_IMPORTER_HOST_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index d21d2cc..93bf4d77 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1194,6 +1194,8 @@ 'browser/idle_win.cc', 'browser/ime_input.cc', 'browser/ime_input.h', + 'browser/importer/external_process_importer_client.cc', + 'browser/importer/external_process_importer_client.h', 'browser/importer/firefox2_importer.cc', 'browser/importer/firefox2_importer.h', 'browser/importer/firefox3_importer.cc', |