Chromium Code Reviews| Index: chrome/utility/chrome_content_utility_client.cc |
| diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc |
| index 9a129e9a37326f2002d2f87e8ea1fbc728563b9d..26a117fd19dc943d3703661e2d376fdb5ec75c44 100644 |
| --- a/chrome/utility/chrome_content_utility_client.cc |
| +++ b/chrome/utility/chrome_content_utility_client.cc |
| @@ -4,10 +4,11 @@ |
| #include "chrome/utility/chrome_content_utility_client.h" |
| -#include "base/bind.h" |
| #include "base/base64.h" |
| +#include "base/bind.h" |
| #include "base/command_line.h" |
| #include "base/json/json_reader.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/message_loop_proxy.h" |
| #include "base/threading/thread.h" |
| #include "chrome/browser/importer/external_process_importer_bridge.h" |
| @@ -31,7 +32,6 @@ |
| #if defined(OS_WIN) |
| #include "base/file_util.h" |
| -#include "base/memory/scoped_ptr.h" |
| #include "base/path_service.h" |
| #include "base/win/iat_patch_function.h" |
| #include "base/win/scoped_handle.h" |
| @@ -42,7 +42,101 @@ |
| namespace chrome { |
| -ChromeContentUtilityClient::ChromeContentUtilityClient() : items_to_import_(0) { |
| +#if defined(OS_ANDROID) |
| + |
| +// Dummy implementation on Android. |
| +class ChromeContentUtilityClient::ImportHandler { |
| + public: |
| + void OnImportStart( |
| + const importer::SourceProfile& source_profile, |
| + uint16 items, |
| + const base::DictionaryValue& localized_strings) { |
| + } |
| + void OnImportCancel() {} |
| + void OnImportItemFinished(uint16 item) {} |
| +}; |
| + |
| +#else |
| + |
| +class ChromeContentUtilityClient::ImportHandler { |
|
Yaron
2012/07/17 19:13:53
Why not split this out to a separate file and then
Philippe
2012/07/18 09:34:27
Good point. I kept the dummy implementation for An
|
| + public: |
| + ImportHandler() : items_to_import_(0) {} |
| + |
| + void OnImportStart( |
| + const importer::SourceProfile& source_profile, |
| + uint16 items, |
| + const base::DictionaryValue& localized_strings) { |
| + bridge_ = new ExternalProcessImporterBridge( |
| + localized_strings, content::UtilityThread::Get(), |
| + base::MessageLoopProxy::current()); |
| + importer_ = importer::CreateImporterByType(source_profile.importer_type); |
| + if (!importer_) { |
| + Send(new ProfileImportProcessHostMsg_Import_Finished(false, |
| + "Importer could not be created.")); |
| + return; |
| + } |
| + |
| + items_to_import_ = items; |
| + |
| + // Create worker thread in which importer runs. |
| + import_thread_.reset(new base::Thread("import_thread")); |
| + base::Thread::Options options; |
| + options.message_loop_type = MessageLoop::TYPE_IO; |
| + if (!import_thread_->StartWithOptions(options)) { |
| + NOTREACHED(); |
| + ImporterCleanup(); |
| + } |
| + import_thread_->message_loop()->PostTask( |
| + FROM_HERE, base::Bind(&Importer::StartImport, importer_.get(), |
| + source_profile, items, bridge_)); |
| + } |
| + |
| + void OnImportCancel() { |
| + ImporterCleanup(); |
| + } |
| + |
| + void OnImportItemFinished(uint16 item) { |
| + items_to_import_ ^= item; // Remove finished item from mask. |
| + // If we've finished with all items, notify the browser process. |
| + if (items_to_import_ == 0) { |
| + Send(new ProfileImportProcessHostMsg_Import_Finished(true, "")); |
| + ImporterCleanup(); |
| + } |
| + } |
| + |
| + private: |
| + // The following are used with out of process profile import: |
| + void ImporterCleanup() { |
| + importer_->Cancel(); |
| + importer_ = NULL; |
| + bridge_ = NULL; |
| + import_thread_.reset(); |
| + content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| + } |
| + |
| + static bool Send(IPC::Message* message) { |
| + return content::UtilityThread::Get()->Send(message); |
| + } |
| + |
| + // Thread that importer runs on, while ProfileImportThread handles messages |
| + // from the browser process. |
| + scoped_ptr<base::Thread> import_thread_; |
| + |
| + // Bridge object is passed to importer, so that it can send IPC calls |
| + // directly back to the ProfileImportProcessHost. |
| + scoped_refptr<ExternalProcessImporterBridge> bridge_; |
| + |
| + // A bitmask of importer::ImportItem. |
| + uint16 items_to_import_; |
| + |
| + // Importer of the appropriate type (Firefox, Safari, IE, etc.) |
| + scoped_refptr<Importer> importer_; |
| +}; |
| + |
| +#endif |
| + |
| +ChromeContentUtilityClient::ChromeContentUtilityClient() |
| + : import_handler_(new ImportHandler()) { |
| } |
| ChromeContentUtilityClient::~ChromeContentUtilityClient() { |
| @@ -82,12 +176,18 @@ bool ChromeContentUtilityClient::OnMessageReceived( |
| IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseJSON, OnParseJSON) |
| IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults, |
| OnGetPrinterCapsAndDefaults) |
| - IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_StartImport, |
| - OnImportStart) |
| - IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport, |
| - OnImportCancel) |
| - IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished, |
| - OnImportItemFinished) |
| + IPC_MESSAGE_FORWARD( |
|
Yaron
2012/07/17 19:13:53
couldn't you also ask your ImportHandler to regist
Philippe
2012/07/18 09:34:27
Good point.
|
| + ProfileImportProcessMsg_StartImport, |
| + import_handler_.get(), |
| + ChromeContentUtilityClient::ImportHandler::OnImportStart) |
| + IPC_MESSAGE_FORWARD( |
| + ProfileImportProcessMsg_CancelImport, |
| + import_handler_.get(), |
| + ChromeContentUtilityClient::ImportHandler::OnImportCancel) |
| + IPC_MESSAGE_FORWARD( |
| + ProfileImportProcessMsg_ReportImportItemFinished, |
| + import_handler_.get(), |
| + ChromeContentUtilityClient::ImportHandler::OnImportItemFinished) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -391,54 +491,4 @@ void ChromeContentUtilityClient::OnGetPrinterCapsAndDefaults( |
| content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| } |
| -void ChromeContentUtilityClient::OnImportStart( |
| - const importer::SourceProfile& source_profile, |
| - uint16 items, |
| - const DictionaryValue& localized_strings) { |
| - bridge_ = new ExternalProcessImporterBridge( |
| - localized_strings, content::UtilityThread::Get(), |
| - base::MessageLoopProxy::current()); |
| - importer_ = importer::CreateImporterByType(source_profile.importer_type); |
| - if (!importer_) { |
| - Send(new ProfileImportProcessHostMsg_Import_Finished(false, |
| - "Importer could not be created.")); |
| - return; |
| - } |
| - |
| - items_to_import_ = items; |
| - |
| - // Create worker thread in which importer runs. |
| - import_thread_.reset(new base::Thread("import_thread")); |
| - base::Thread::Options options; |
| - options.message_loop_type = MessageLoop::TYPE_IO; |
| - if (!import_thread_->StartWithOptions(options)) { |
| - NOTREACHED(); |
| - ImporterCleanup(); |
| - } |
| - import_thread_->message_loop()->PostTask( |
| - FROM_HERE, base::Bind(&Importer::StartImport, importer_.get(), |
| - source_profile, items, bridge_)); |
| -} |
| - |
| -void ChromeContentUtilityClient::OnImportCancel() { |
| - ImporterCleanup(); |
| -} |
| - |
| -void ChromeContentUtilityClient::OnImportItemFinished(uint16 item) { |
| - items_to_import_ ^= item; // Remove finished item from mask. |
| - // If we've finished with all items, notify the browser process. |
| - if (items_to_import_ == 0) { |
| - Send(new ProfileImportProcessHostMsg_Import_Finished(true, "")); |
| - ImporterCleanup(); |
| - } |
| -} |
| - |
| -void ChromeContentUtilityClient::ImporterCleanup() { |
| - importer_->Cancel(); |
| - importer_ = NULL; |
| - bridge_ = NULL; |
| - import_thread_.reset(); |
| - content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| -} |
| - |
| } // namespace chrome |