Index: chrome/browser/importer/external_process_importer_client.cc |
diff --git a/chrome/browser/importer/external_process_importer_client.cc b/chrome/browser/importer/external_process_importer_client.cc |
index 325691bf5f862668efe04109905bbbc81a0a07cc..2ad13d4b0281346f6edfb7c58986837571d87532 100644 |
--- a/chrome/browser/importer/external_process_importer_client.cc |
+++ b/chrome/browser/importer/external_process_importer_client.cc |
@@ -4,6 +4,8 @@ |
#include "chrome/browser/importer/external_process_importer_client.h" |
+#include <utility> |
+ |
#include "base/bind.h" |
#include "base/strings/string_number_conversions.h" |
#include "build/build_config.h" |
@@ -12,11 +14,11 @@ |
#include "chrome/browser/importer/in_process_importer_bridge.h" |
#include "chrome/common/importer/firefox_importer_utils.h" |
#include "chrome/common/importer/imported_bookmark_entry.h" |
-#include "chrome/common/importer/profile_import_process_messages.h" |
#include "chrome/grit/generated_resources.h" |
#include "components/strings/grit/components_strings.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/utility_process_host.h" |
+#include "services/service_manager/public/cpp/interface_provider.h" |
#include "ui/base/l10n/l10n_util.h" |
using content::BrowserThread; |
@@ -34,19 +36,52 @@ ExternalProcessImporterClient::ExternalProcessImporterClient( |
source_profile_(source_profile), |
items_(items), |
bridge_(bridge), |
- cancelled_(false) { |
+ cancelled_(false), |
+ binding_(this) { |
process_importer_host_->NotifyImportStarted(); |
} |
void ExternalProcessImporterClient::Start() { |
AddRef(); // balanced in Cleanup. |
+ |
+ chrome::mojom::ProfileImportRequest request = |
+ mojo::GetProxy(&profile_import_); |
+ |
BrowserThread::ID thread_id; |
CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_id)); |
BrowserThread::PostTask( |
BrowserThread::IO, FROM_HERE, |
- base::Bind(&ExternalProcessImporterClient::StartProcessOnIOThread, |
- this, |
- thread_id)); |
+ base::Bind(&ExternalProcessImporterClient::StartProcessOnIOThread, this, |
+ thread_id, base::Passed(std::move(request)))); |
+ |
+ // Dictionary of all localized strings that could be needed by the importer |
+ // in the external process. |
+ base::DictionaryValue localized_strings; |
+ localized_strings.SetString(base::IntToString(IDS_BOOKMARK_GROUP), |
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP)); |
+ localized_strings.SetString( |
+ base::IntToString(IDS_BOOKMARK_GROUP_FROM_FIREFOX), |
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_FIREFOX)); |
+ localized_strings.SetString( |
+ base::IntToString(IDS_BOOKMARK_GROUP_FROM_SAFARI), |
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_SAFARI)); |
+ localized_strings.SetString( |
+ base::IntToString(IDS_IMPORT_FROM_FIREFOX), |
+ l10n_util::GetStringUTF8(IDS_IMPORT_FROM_FIREFOX)); |
+ localized_strings.SetString( |
+ base::IntToString(IDS_IMPORT_FROM_ICEWEASEL), |
+ l10n_util::GetStringUTF8(IDS_IMPORT_FROM_ICEWEASEL)); |
+ localized_strings.SetString(base::IntToString(IDS_IMPORT_FROM_SAFARI), |
+ l10n_util::GetStringUTF8(IDS_IMPORT_FROM_SAFARI)); |
+ localized_strings.SetString( |
+ base::IntToString(IDS_BOOKMARK_BAR_FOLDER_NAME), |
+ l10n_util::GetStringUTF8(IDS_BOOKMARK_BAR_FOLDER_NAME)); |
+ |
+ // If the utility process hasn't started yet the message will queue until it |
+ // does. |
+ auto observer_ptr = binding_.CreateInterfacePtrAndBind(); |
+ profile_import_->StartImport(source_profile_, items_, localized_strings, |
+ std::move(observer_ptr)); |
} |
void ExternalProcessImporterClient::Cancel() { |
@@ -54,11 +89,9 @@ void ExternalProcessImporterClient::Cancel() { |
return; |
cancelled_ = true; |
- BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
- base::Bind( |
- &ExternalProcessImporterClient::CancelImportProcessOnIOThread, |
- this)); |
+ if (utility_process_host_) |
+ profile_import_->CancelImport(); |
+ CloseMojoHandles(); |
Release(); |
} |
@@ -75,49 +108,7 @@ void ExternalProcessImporterClient::OnProcessCrashed(int exit_code) { |
bool ExternalProcessImporterClient::OnMessageReceived( |
const IPC::Message& message) { |
- bool handled = true; |
- IPC_BEGIN_MESSAGE_MAP(ExternalProcessImporterClient, message) |
- // Notification messages about the state of the import process. |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_Import_Started, |
- OnImportStart) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_Import_Finished, |
- OnImportFinished) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_ImportItem_Started, |
- OnImportItemStart) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_ImportItem_Finished, |
- OnImportItemFinished) |
- // Data messages containing items to be written to the user profile. |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyHistoryImportStart, |
- OnHistoryImportStart) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyHistoryImportGroup, |
- OnHistoryImportGroup) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyHomePageImportReady, |
- OnHomePageImportReady) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyBookmarksImportStart, |
- OnBookmarksImportStart) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyBookmarksImportGroup, |
- OnBookmarksImportGroup) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyFaviconsImportStart, |
- OnFaviconsImportStart) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyFaviconsImportGroup, |
- OnFaviconsImportGroup) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyPasswordFormReady, |
- OnPasswordFormImportReady) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyKeywordsReady, |
- OnKeywordsImportReady) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyFirefoxSearchEngData, |
- OnFirefoxSearchEngineDataReceived) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_AutofillFormDataImportStart, |
- OnAutofillFormDataImportStart) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_AutofillFormDataImportGroup, |
- OnAutofillFormDataImportGroup) |
-#if defined(OS_WIN) |
- IPC_MESSAGE_HANDLER(ProfileImportProcessHostMsg_NotifyIE7PasswordInfo, |
- OnIE7PasswordReceived) |
-#endif |
- IPC_MESSAGE_UNHANDLED(handled = false) |
- IPC_END_MESSAGE_MAP() |
- return handled; |
+ return false; |
} |
void ExternalProcessImporterClient::OnImportStart() { |
@@ -137,29 +128,25 @@ void ExternalProcessImporterClient::OnImportFinished( |
Cleanup(); |
} |
-void ExternalProcessImporterClient::OnImportItemStart(int item_data) { |
+void ExternalProcessImporterClient::OnImportItemStart( |
+ importer::ImportItem import_item) { |
if (cancelled_) |
return; |
- bridge_->NotifyItemStarted(static_cast<importer::ImportItem>(item_data)); |
+ bridge_->NotifyItemStarted(import_item); |
} |
-void ExternalProcessImporterClient::OnImportItemFinished(int item_data) { |
+void ExternalProcessImporterClient::OnImportItemFinished( |
+ importer::ImportItem import_item) { |
if (cancelled_) |
return; |
- importer::ImportItem import_item = |
- static_cast<importer::ImportItem>(item_data); |
bridge_->NotifyItemEnded(import_item); |
- BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
- base::Bind(&ExternalProcessImporterClient::NotifyItemFinishedOnIOThread, |
- this, |
- import_item)); |
+ profile_import_->ReportImportItemFinished(import_item); |
} |
void ExternalProcessImporterClient::OnHistoryImportStart( |
- size_t total_history_rows_count) { |
+ uint32_t total_history_rows_count) { |
if (cancelled_) |
return; |
@@ -190,7 +177,7 @@ void ExternalProcessImporterClient::OnHomePageImportReady( |
void ExternalProcessImporterClient::OnBookmarksImportStart( |
const base::string16& first_folder_name, |
- size_t total_bookmarks_count) { |
+ uint32_t total_bookmarks_count) { |
if (cancelled_) |
return; |
@@ -213,7 +200,7 @@ void ExternalProcessImporterClient::OnBookmarksImportGroup( |
} |
void ExternalProcessImporterClient::OnFaviconsImportStart( |
- size_t total_favicons_count) { |
+ uint32_t total_favicons_count) { |
if (cancelled_) |
return; |
@@ -249,14 +236,14 @@ void ExternalProcessImporterClient::OnKeywordsImportReady( |
} |
void ExternalProcessImporterClient::OnFirefoxSearchEngineDataReceived( |
- const std::vector<std::string> search_engine_data) { |
+ const std::vector<std::string>& search_engine_data) { |
if (cancelled_) |
return; |
bridge_->SetFirefoxSearchEnginesXMLData(search_engine_data); |
} |
void ExternalProcessImporterClient::OnAutofillFormDataImportStart( |
- size_t total_autofill_form_data_entry_count) { |
+ uint32_t total_autofill_form_data_entry_count) { |
if (cancelled_) |
return; |
@@ -277,14 +264,16 @@ void ExternalProcessImporterClient::OnAutofillFormDataImportGroup( |
bridge_->SetAutofillFormData(autofill_form_data_); |
} |
-#if defined(OS_WIN) |
void ExternalProcessImporterClient::OnIE7PasswordReceived( |
const importer::ImporterIE7PasswordInfo& importer_password_info) { |
+#if defined(OS_WIN) |
if (cancelled_) |
return; |
bridge_->AddIE7PasswordInfo(importer_password_info); |
-} |
+#else |
+ NOTREACHED(); |
#endif |
+} |
ExternalProcessImporterClient::~ExternalProcessImporterClient() {} |
@@ -294,22 +283,13 @@ void ExternalProcessImporterClient::Cleanup() { |
if (process_importer_host_.get()) |
process_importer_host_->NotifyImportEnded(); |
+ CloseMojoHandles(); |
Release(); |
} |
-void ExternalProcessImporterClient::CancelImportProcessOnIOThread() { |
- if (utility_process_host_.get()) |
- utility_process_host_->Send(new ProfileImportProcessMsg_CancelImport()); |
-} |
- |
-void ExternalProcessImporterClient::NotifyItemFinishedOnIOThread( |
- importer::ImportItem import_item) { |
- utility_process_host_->Send( |
- new ProfileImportProcessMsg_ReportImportItemFinished(import_item)); |
-} |
- |
void ExternalProcessImporterClient::StartProcessOnIOThread( |
- BrowserThread::ID thread_id) { |
+ BrowserThread::ID thread_id, |
+ chrome::mojom::ProfileImportRequest request) { |
utility_process_host_ = |
UtilityProcessHost::Create( |
this, BrowserThread::GetTaskRunnerForThread(thread_id).get()) |
@@ -326,31 +306,13 @@ void ExternalProcessImporterClient::StartProcessOnIOThread( |
utility_process_host_->SetEnv(env); |
#endif |
- // Dictionary of all localized strings that could be needed by the importer |
- // in the external process. |
- base::DictionaryValue localized_strings; |
- localized_strings.SetString( |
- base::IntToString(IDS_BOOKMARK_GROUP), |
- l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP)); |
- localized_strings.SetString( |
- base::IntToString(IDS_BOOKMARK_GROUP_FROM_FIREFOX), |
- l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_FIREFOX)); |
- localized_strings.SetString( |
- base::IntToString(IDS_BOOKMARK_GROUP_FROM_SAFARI), |
- l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_SAFARI)); |
- localized_strings.SetString( |
- base::IntToString(IDS_IMPORT_FROM_FIREFOX), |
- l10n_util::GetStringUTF8(IDS_IMPORT_FROM_FIREFOX)); |
- localized_strings.SetString( |
- base::IntToString(IDS_IMPORT_FROM_ICEWEASEL), |
- l10n_util::GetStringUTF8(IDS_IMPORT_FROM_ICEWEASEL)); |
- localized_strings.SetString( |
- base::IntToString(IDS_IMPORT_FROM_SAFARI), |
- l10n_util::GetStringUTF8(IDS_IMPORT_FROM_SAFARI)); |
- localized_strings.SetString( |
- base::IntToString(IDS_BOOKMARK_BAR_FOLDER_NAME), |
- l10n_util::GetStringUTF8(IDS_BOOKMARK_BAR_FOLDER_NAME)); |
+ utility_process_host_->Start(); |
+ chrome::mojom::ProfileImportPtr profile_import; |
+ utility_process_host_->GetRemoteInterfaces()->GetInterface( |
+ std::move(request)); |
+} |
- utility_process_host_->Send(new ProfileImportProcessMsg_StartImport( |
- source_profile_, items_, localized_strings)); |
+void ExternalProcessImporterClient::CloseMojoHandles() { |
+ profile_import_.reset(); |
+ binding_.Close(); |
} |