diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-03 17:02:07 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-03 17:02:07 +0000 |
commit | c4f883a6d4a7e2d31ea641f36f7f5150a2cbc349 (patch) | |
tree | 946d49876311e62e24e56605f803ac9cc5b6e54d /chrome/browser/extensions | |
parent | 803f91036d5674629f9e64205cacd31fb0f7d5c2 (diff) | |
download | chromium_src-c4f883a6d4a7e2d31ea641f36f7f5150a2cbc349.zip chromium_src-c4f883a6d4a7e2d31ea641f36f7f5150a2cbc349.tar.gz chromium_src-c4f883a6d4a7e2d31ea641f36f7f5150a2cbc349.tar.bz2 |
Create an API around UtilityProcessHost and use that from chrome.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9317074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120342 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
7 files changed, 53 insertions, 40 deletions
diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc index 5958415..7233585 100644 --- a/chrome/browser/extensions/extension_management_api.cc +++ b/chrome/browser/extensions/extension_management_api.cc @@ -30,9 +30,13 @@ #include "chrome/common/extensions/url_pattern.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/utility_process_host.h" +#include "content/public/browser/utility_process_host_client.h" using base::IntToString; using content::BrowserThread; +using content::UtilityProcessHost; +using content::UtilityProcessHostClient; namespace events = extension_event_names; namespace keys = extension_management_api_constants; @@ -193,13 +197,12 @@ namespace { // This class helps GetPermissionWarningsByManifestFunction manage // sending manifest JSON strings to the utility process for parsing. -class SafeManifestJSONParser : public UtilityProcessHost::Client { +class SafeManifestJSONParser : public UtilityProcessHostClient { public: SafeManifestJSONParser(GetPermissionWarningsByManifestFunction* client, const std::string& manifest) : client_(client), - manifest_(manifest), - utility_host_(NULL) {} + manifest_(manifest) {} void Start() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -211,9 +214,10 @@ class SafeManifestJSONParser : public UtilityProcessHost::Client { void StartWorkOnIOThread() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - utility_host_ = new UtilityProcessHost(this, BrowserThread::IO); - utility_host_->set_use_linux_zygote(true); - utility_host_->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); + UtilityProcessHost* host = + UtilityProcessHost::Create(this, BrowserThread::IO); + host->EnableZygote(); + host->Send(new ChromeUtilityMsg_ParseJSON(manifest_)); } virtual bool OnMessageReceived(const IPC::Message& message) { @@ -237,7 +241,6 @@ class SafeManifestJSONParser : public UtilityProcessHost::Client { else error_ = keys::kManifestParseError; - utility_host_ = NULL; // has already deleted itself BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, @@ -247,7 +250,6 @@ class SafeManifestJSONParser : public UtilityProcessHost::Client { void OnJSONParseFailed(const std::string& error) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); error_ = error; - utility_host_ = NULL; // has already deleted itself BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, @@ -275,7 +277,6 @@ class SafeManifestJSONParser : public UtilityProcessHost::Client { scoped_ptr<DictionaryValue> parsed_manifest_; std::string error_; - UtilityProcessHost* utility_host_; }; } // namespace diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc index 7b17abc..04f5c29 100644 --- a/chrome/browser/extensions/extension_updater.cc +++ b/chrome/browser/extensions/extension_updater.cc @@ -37,9 +37,9 @@ #include "chrome/common/extensions/extension_file_util.h" #include "chrome/common/pref_names.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" -#include "content/browser/utility_process_host.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" +#include "content/public/browser/utility_process_host.h" #include "content/public/common/url_fetcher.h" #include "crypto/sha2.h" #include "googleurl/src/gurl.h" @@ -58,6 +58,8 @@ using base::RandInt; using base::Time; using base::TimeDelta; using content::BrowserThread; +using content::UtilityProcessHost; +using content::UtilityProcessHostClient; using prefs::kExtensionBlacklistUpdateVersion; using prefs::kLastExtensionsUpdateCheck; using prefs::kNextExtensionsUpdateCheck; @@ -620,7 +622,7 @@ void ExtensionUpdater::OnURLFetchComplete(const content::URLFetcher* source) { } // Utility class to handle doing xml parsing in a sandboxed utility process. -class SafeManifestParser : public UtilityProcessHost::Client { +class SafeManifestParser : public UtilityProcessHostClient { public: // Takes ownership of |fetch_data|. SafeManifestParser(const std::string& xml, ManifestFetchData* fetch_data, @@ -652,9 +654,9 @@ class SafeManifestParser : public UtilityProcessHost::Client { bool use_utility_process = rdh && !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); if (use_utility_process) { - UtilityProcessHost* host = new UtilityProcessHost( + UtilityProcessHost* host = UtilityProcessHost::Create( this, BrowserThread::UI); - host->set_use_linux_zygote(true); + host->EnableZygote(); host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml_)); } else { UpdateManifest manifest; @@ -678,7 +680,7 @@ class SafeManifestParser : public UtilityProcessHost::Client { } } - // UtilityProcessHost::Client + // UtilityProcessHostClient virtual bool OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(SafeManifestParser, message) diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc index 35414b4..7875374 100644 --- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc +++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc @@ -26,6 +26,7 @@ #include "chrome/common/extensions/extension_unpacker.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/utility_process_host.h" #include "crypto/signature_verifier.h" #include "grit/generated_resources.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -33,6 +34,7 @@ #include "ui/gfx/codec/png_codec.h" using content::BrowserThread; +using content::UtilityProcessHost; // The following macro makes histograms that record the length of paths // in this file much easier to read. @@ -311,10 +313,11 @@ void SandboxedExtensionUnpacker::OnProcessCrashed(int exit_code) { void SandboxedExtensionUnpacker::StartProcessOnIOThread( const FilePath& temp_crx_path) { - UtilityProcessHost* host = new UtilityProcessHost(this, thread_identifier_); + UtilityProcessHost* host = UtilityProcessHost::Create( + this, thread_identifier_); // Grant the subprocess access to the entire subdir the extension file is // in, so that it can unpack to that dir. - host->set_exposed_dir(temp_crx_path.DirName()); + host->SetExposedDir(temp_crx_path.DirName()); host->Send( new ChromeUtilityMsg_UnpackExtension( temp_crx_path, location_, creation_flags_)); diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.h b/chrome/browser/extensions/sandboxed_extension_unpacker.h index 2fdc59f..da64d5c 100644 --- a/chrome/browser/extensions/sandboxed_extension_unpacker.h +++ b/chrome/browser/extensions/sandboxed_extension_unpacker.h @@ -12,7 +12,8 @@ #include "base/memory/ref_counted.h" #include "base/scoped_temp_dir.h" #include "chrome/common/extensions/extension.h" -#include "content/browser/utility_process_host.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/utility_process_host_client.h" class Extension; class ResourceDispatcherHost; @@ -67,7 +68,7 @@ class SandboxedExtensionUnpackerClient // // // NOTE: This class should only be used on the file thread. -class SandboxedExtensionUnpacker : public UtilityProcessHost::Client { +class SandboxedExtensionUnpacker : public content::UtilityProcessHostClient { public: // The size of the magic character sequence at the beginning of each crx // file, in bytes. This should be a multiple of 4. @@ -193,7 +194,7 @@ class SandboxedExtensionUnpacker : public UtilityProcessHost::Client { // Starts the utility process that unpacks our extension. void StartProcessOnIOThread(const FilePath& temp_crx_path); - // UtilityProcessHost::Client + // UtilityProcessHostClient virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual void OnProcessCrashed(int exit_code) OVERRIDE; diff --git a/chrome/browser/extensions/webstore_inline_installer.cc b/chrome/browser/extensions/webstore_inline_installer.cc index c539022..ce1aab6 100644 --- a/chrome/browser/extensions/webstore_inline_installer.cc +++ b/chrome/browser/extensions/webstore_inline_installer.cc @@ -19,8 +19,9 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/url_pattern.h" #include "chrome/common/url_constants.h" -#include "content/browser/utility_process_host.h" #include "content/public/browser/web_contents.h" +#include "content/public/browser/utility_process_host.h" +#include "content/public/browser/utility_process_host_client.h" #include "content/public/common/url_fetcher.h" #include "net/base/escape.h" #include "net/base/load_flags.h" @@ -28,6 +29,8 @@ using content::BrowserThread; using content::OpenURLParams; +using content::UtilityProcessHost; +using content::UtilityProcessHostClient; using content::WebContents; const char kManifestKey[] = "manifest"; @@ -57,13 +60,12 @@ const char kInlineInstallSupportedError[] = "Inline installation is not supported for this item. The user will be " "redirected to the Chrome Web Store."; -class SafeWebstoreResponseParser : public UtilityProcessHost::Client { +class SafeWebstoreResponseParser : public UtilityProcessHostClient { public: SafeWebstoreResponseParser(WebstoreInlineInstaller *client, const std::string& webstore_data) : client_(client), - webstore_data_(webstore_data), - utility_host_(NULL) {} + webstore_data_(webstore_data) {} void Start() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -75,12 +77,13 @@ class SafeWebstoreResponseParser : public UtilityProcessHost::Client { void StartWorkOnIOThread() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - utility_host_ = new UtilityProcessHost(this, BrowserThread::IO); - utility_host_->set_use_linux_zygote(true); - utility_host_->Send(new ChromeUtilityMsg_ParseJSON(webstore_data_)); + UtilityProcessHost* host = + UtilityProcessHost::Create(this, BrowserThread::IO); + host->EnableZygote(); + host->Send(new ChromeUtilityMsg_ParseJSON(webstore_data_)); } - // Implementing pieces of the UtilityProcessHost::Client interface. + // Implementing pieces of the UtilityProcessHostClient interface. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { bool handled = true; IPC_BEGIN_MESSAGE_MAP(SafeWebstoreResponseParser, message) @@ -116,9 +119,6 @@ class SafeWebstoreResponseParser : public UtilityProcessHost::Client { void ReportResults() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - // The utility_host_ will take care of deleting itself after this call. - utility_host_ = NULL; - BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, @@ -140,9 +140,6 @@ class SafeWebstoreResponseParser : public UtilityProcessHost::Client { WebstoreInlineInstaller* client_; std::string webstore_data_; - - UtilityProcessHost* utility_host_; - std::string error_; scoped_ptr<DictionaryValue> parsed_webstore_data_; }; diff --git a/chrome/browser/extensions/webstore_install_helper.cc b/chrome/browser/extensions/webstore_install_helper.cc index fbc67d3..979173c 100644 --- a/chrome/browser/extensions/webstore_install_helper.cc +++ b/chrome/browser/extensions/webstore_install_helper.cc @@ -10,11 +10,13 @@ #include "base/values.h" #include "chrome/common/chrome_utility_messages.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/utility_process_host.h" #include "content/public/common/url_fetcher.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_status.h" using content::BrowserThread; +using content::UtilityProcessHost; namespace { @@ -67,8 +69,8 @@ void WebstoreInstallHelper::Start() { void WebstoreInstallHelper::StartWorkOnIOThread() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); utility_host_ = - (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr(); - utility_host_->set_use_linux_zygote(true); + UtilityProcessHost::Create(this, BrowserThread::IO)->AsWeakPtr(); + utility_host_->EnableZygote(); utility_host_->StartBatchMode(); if (!icon_base64_data_.empty()) diff --git a/chrome/browser/extensions/webstore_install_helper.h b/chrome/browser/extensions/webstore_install_helper.h index a93e8df..4441f51 100644 --- a/chrome/browser/extensions/webstore_install_helper.h +++ b/chrome/browser/extensions/webstore_install_helper.h @@ -6,12 +6,15 @@ #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_INSTALL_HELPER_H_ #pragma once -#include "content/browser/utility_process_host.h" +#include <vector> + +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "content/public/browser/utility_process_host_client.h" #include "content/public/common/url_fetcher_delegate.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" -class UtilityProcessHost; class SkBitmap; namespace base { @@ -19,6 +22,10 @@ class DictionaryValue; class ListValue; } +namespace content { +class UtilityProcessHost; +} + namespace net { class URLRequestContextGetter; } @@ -27,7 +34,7 @@ class URLRequestContextGetter; // sending work to the utility process for parsing manifests and // fetching/decoding icon data. Clients must implement the // WebstoreInstallHelper::Delegate interface to receive the parsed data. -class WebstoreInstallHelper : public UtilityProcessHost::Client, +class WebstoreInstallHelper : public content::UtilityProcessHostClient, public content::URLFetcherDelegate { public: class Delegate { @@ -74,7 +81,7 @@ class WebstoreInstallHelper : public UtilityProcessHost::Client, // Implementing the content::URLFetcherDelegate interface. virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; - // Implementing pieces of the UtilityProcessHost::Client interface. + // Implementing pieces of the UtilityProcessHostClient interface. virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; // Message handlers. @@ -104,7 +111,7 @@ class WebstoreInstallHelper : public UtilityProcessHost::Client, scoped_ptr<content::URLFetcher> url_fetcher_; net::URLRequestContextGetter* context_getter_; // Only usable on UI thread. - base::WeakPtr<UtilityProcessHost> utility_host_; + base::WeakPtr<content::UtilityProcessHost> utility_host_; // Flags for whether we're done doing icon decoding and manifest parsing. bool icon_decode_complete_; |