diff options
author | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-18 19:08:38 +0000 |
---|---|---|
committer | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-18 19:08:38 +0000 |
commit | 11af41c9e407cc24b41ffa9de99d0f9e6846360e (patch) | |
tree | d654e3a073e4f935e9f1ff3a07fc0fe1ec4b6319 /chrome/utility | |
parent | b912496173a4a1a194f95e254e179725c66ccf0b (diff) | |
download | chromium_src-11af41c9e407cc24b41ffa9de99d0f9e6846360e.zip chromium_src-11af41c9e407cc24b41ffa9de99d0f9e6846360e.tar.gz chromium_src-11af41c9e407cc24b41ffa9de99d0f9e6846360e.tar.bz2 |
Disable uses of ProfileImportProcess on Android.
This is part of the unit_tests linking effort on Android.
This moves the profile import-related code excluded on Android to its own class.
BUG=136787
Review URL: https://chromiumcodereview.appspot.com/10777012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147285 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/utility')
-rw-r--r-- | chrome/utility/chrome_content_utility_client.cc | 72 | ||||
-rw-r--r-- | chrome/utility/chrome_content_utility_client.h | 27 | ||||
-rw-r--r-- | chrome/utility/profile_import_handler.cc | 89 | ||||
-rw-r--r-- | chrome/utility/profile_import_handler.h | 67 |
4 files changed, 172 insertions, 83 deletions
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc index f1a0724..51fa4d5 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" @@ -21,6 +22,7 @@ #include "chrome/common/extensions/unpacker.h" #include "chrome/common/extensions/update_manifest.h" #include "chrome/common/web_resource/web_resource_unpacker.h" +#include "chrome/utility/profile_import_handler.h" #include "content/public/utility/utility_thread.h" #include "printing/backend/print_backend.h" #include "printing/page_range.h" @@ -31,7 +33,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 +43,10 @@ namespace chrome { -ChromeContentUtilityClient::ChromeContentUtilityClient() : items_to_import_(0) { +ChromeContentUtilityClient::ChromeContentUtilityClient() { +#if !defined(OS_ANDROID) + import_handler_.reset(new ProfileImportHandler()); +#endif } ChromeContentUtilityClient::~ChromeContentUtilityClient() { @@ -82,14 +86,14 @@ 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_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() + +#if !defined(OS_ANDROID) + if (!handled) + handled = import_handler_->OnMessageReceived(message); +#endif + return handled; } @@ -391,54 +395,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 diff --git a/chrome/utility/chrome_content_utility_client.h b/chrome/utility/chrome_content_utility_client.h index b028636..fb82afa 100644 --- a/chrome/utility/chrome_content_utility_client.h +++ b/chrome/utility/chrome_content_utility_client.h @@ -6,7 +6,6 @@ #define CHROME_UTILITY_CHROME_CONTENT_UTILITY_CLIENT_H_ #include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/platform_file.h" #include "content/public/utility/content_utility_client.h" @@ -35,6 +34,8 @@ struct PageRange; namespace chrome { +class ProfileImportHandler; + class ChromeContentUtilityClient : public content::ContentUtilityClient { public: ChromeContentUtilityClient(); @@ -77,29 +78,7 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient { void OnGetPrinterCapsAndDefaults(const std::string& printer_name); - void OnImportStart( - const importer::SourceProfile& source_profile, - uint16 items, - const base::DictionaryValue& localized_strings); - void OnImportCancel(); - void OnImportItemFinished(uint16 item); - - // The following are used with out of process profile import: - void ImporterCleanup(); - - // 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_; + scoped_ptr<ProfileImportHandler> import_handler_; }; } // namespace chrome diff --git a/chrome/utility/profile_import_handler.cc b/chrome/utility/profile_import_handler.cc new file mode 100644 index 0000000..473581c --- /dev/null +++ b/chrome/utility/profile_import_handler.cc @@ -0,0 +1,89 @@ +// Copyright (c) 2012 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/utility/profile_import_handler.h" + +#include "base/bind.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" +#include "chrome/browser/importer/importer.h" +#include "chrome/browser/importer/profile_import_process_messages.h" +#include "content/public/utility/utility_thread.h" + +namespace chrome { + +ProfileImportHandler::ProfileImportHandler() : items_to_import_(0) {} + +ProfileImportHandler::~ProfileImportHandler() {} + +bool ProfileImportHandler::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(ProfileImportHandler, message) + IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_StartImport, OnImportStart) + IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport, OnImportCancel) + IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished, + OnImportItemFinished) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void ProfileImportHandler::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 ProfileImportHandler::OnImportCancel() { + ImporterCleanup(); +} + +void ProfileImportHandler::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 ProfileImportHandler::ImporterCleanup() { + importer_->Cancel(); + importer_ = NULL; + bridge_ = NULL; + import_thread_.reset(); + content::UtilityThread::Get()->ReleaseProcessIfNeeded(); +} + +// static +bool ProfileImportHandler::Send(IPC::Message* message) { + return content::UtilityThread::Get()->Send(message); +} + +} // namespace chrome diff --git a/chrome/utility/profile_import_handler.h b/chrome/utility/profile_import_handler.h new file mode 100644 index 0000000..a82df4b --- /dev/null +++ b/chrome/utility/profile_import_handler.h @@ -0,0 +1,67 @@ +// Copyright (c) 2012 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_UTILITY_PROFILE_IMPORT_HANDLER_H_ +#define CHROME_UTILITY_PROFILE_IMPORT_HANDLER_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "ipc/ipc_listener.h" + +class ExternalProcessImporterBridge; +class Importer; + +namespace base { +class DictionaryValue; +class Thread; +} + +namespace importer { +struct SourceProfile; +} + +namespace chrome { + +// Dispatches IPCs for out of process profile import. +class ProfileImportHandler : public IPC::Listener { + public: + ProfileImportHandler(); + virtual ~ProfileImportHandler(); + + // IPC::Listener: + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + private: + void OnImportStart( + const importer::SourceProfile& source_profile, + uint16 items, + const base::DictionaryValue& localized_strings); + void OnImportCancel(); + void OnImportItemFinished(uint16 item); + + // The following are used with out of process profile import: + void ImporterCleanup(); + + static bool Send(IPC::Message* 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_; +}; + +} // namespace chrome + +#endif // CHROME_UTILITY_PROFILE_IMPORT_HANDLER_H_ |