summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/DEPS1
-rw-r--r--chrome/browser/component_updater/component_updater_service.cc16
-rw-r--r--chrome/browser/extensions/extension_management_api.cc19
-rw-r--r--chrome/browser/extensions/extension_updater.cc12
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker.cc7
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker.h7
-rw-r--r--chrome/browser/extensions/webstore_inline_installer.cc25
-rw-r--r--chrome/browser/extensions/webstore_install_helper.cc6
-rw-r--r--chrome/browser/extensions/webstore_install_helper.h17
-rw-r--r--chrome/browser/first_run/first_run_win.cc1
-rw-r--r--chrome/browser/image_decoder.cc9
-rw-r--r--chrome/browser/image_decoder.h7
-rw-r--r--chrome/browser/importer/external_process_importer_client.cc8
-rw-r--r--chrome/browser/importer/external_process_importer_client.h12
-rw-r--r--chrome/browser/web_resource/web_resource_service.cc17
-rw-r--r--content/browser/in_process_webkit/indexed_db_key_utility_client.cc14
-rw-r--r--content/browser/indexed_db/idbbindingutilities_browsertest.cc13
-rw-r--r--content/browser/plugin_loader_posix.cc10
-rw-r--r--content/browser/plugin_loader_posix.h19
-rw-r--r--content/browser/plugin_service_impl.cc1
-rw-r--r--content/browser/utility_process_host.h128
-rw-r--r--content/browser/utility_process_host_impl.cc (renamed from content/browser/utility_process_host.cc)67
-rw-r--r--content/browser/utility_process_host_impl.h78
-rw-r--r--content/content_browser.gypi5
-rw-r--r--content/public/browser/utility_process_host.h66
-rw-r--r--content/public/browser/utility_process_host_client.h38
26 files changed, 355 insertions, 248 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS
index 6264c74..31fad92 100644
--- a/chrome/browser/DEPS
+++ b/chrome/browser/DEPS
@@ -121,7 +121,6 @@ include_rules = [
"+content/browser/tab_contents/web_drag_source_gtk.h",
"+content/browser/tab_contents/web_drag_source_mac.h",
"+content/browser/trace_controller.h",
- "+content/browser/utility_process_host.h",
"+content/browser/zygote_host_linux.h",
"-content/common",
diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc
index 8849a9b..cb0d94f 100644
--- a/chrome/browser/component_updater/component_updater_service.cc
+++ b/chrome/browser/component_updater/component_updater_service.cc
@@ -25,8 +25,9 @@
#include "chrome/common/chrome_utility_messages.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/extension.h"
-#include "content/browser/utility_process_host.h"
#include "content/public/browser/notification_service.h"
+#include "content/public/browser/utility_process_host.h"
+#include "content/public/browser/utility_process_host_client.h"
#include "content/public/common/url_fetcher_delegate.h"
#include "content/public/common/url_fetcher.h"
#include "googleurl/src/gurl.h"
@@ -34,6 +35,8 @@
#include "net/base/load_flags.h"
using content::BrowserThread;
+using content::UtilityProcessHost;
+using content::UtilityProcessHostClient;
// The component updater is designed to live until process shutdown, so
// base::Bind() calls are not refcounted.
@@ -237,9 +240,9 @@ class CrxUpdateService : public ComponentUpdateService {
virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE;
// The only purpose of this class is to forward the
- // UtilityProcessHost::Client callbacks so CrxUpdateService does
+ // UtilityProcessHostClient callbacks so CrxUpdateService does
// not have to derive from it because that is refcounted.
- class ManifestParserBridge : public UtilityProcessHost::Client {
+ class ManifestParserBridge : public UtilityProcessHostClient {
public:
explicit ManifestParserBridge(CrxUpdateService* service)
: service_(service) {}
@@ -597,10 +600,9 @@ void CrxUpdateService::ParseManifest(const std::string& xml) {
CrxUpdateService::OnParseUpdateManifestSucceeded(manifest.results());
}
} else {
- UtilityProcessHost* host =
- new UtilityProcessHost(new ManifestParserBridge(this),
- BrowserThread::UI);
- host->set_use_linux_zygote(true);
+ UtilityProcessHost* host = UtilityProcessHost::Create(
+ new ManifestParserBridge(this), BrowserThread::UI);
+ host->EnableZygote();
host->Send(new ChromeUtilityMsg_ParseUpdateManifest(xml));
}
}
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_;
diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc
index bdd755f..8fba251 100644
--- a/chrome/browser/first_run/first_run_win.cc
+++ b/chrome/browser/first_run/first_run_win.cc
@@ -13,6 +13,7 @@
#include "base/environment.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/process_util.h"
#include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/stringprintf.h"
diff --git a/chrome/browser/image_decoder.cc b/chrome/browser/image_decoder.cc
index 390c93a..8e3eb71 100644
--- a/chrome/browser/image_decoder.cc
+++ b/chrome/browser/image_decoder.cc
@@ -8,8 +8,10 @@
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_utility_messages.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/utility_process_host.h"
using content::BrowserThread;
+using content::UtilityProcessHost;
ImageDecoder::ImageDecoder(Delegate* delegate,
const std::string& image_data)
@@ -57,9 +59,8 @@ void ImageDecoder::OnDecodeImageFailed() {
void ImageDecoder::DecodeImageInSandbox(
const std::vector<unsigned char>& image_data) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- UtilityProcessHost* utility_process_host =
- new UtilityProcessHost(this,
- target_thread_id_);
- utility_process_host->set_use_linux_zygote(true);
+ UtilityProcessHost* utility_process_host = UtilityProcessHost::Create(
+ this, target_thread_id_);
+ utility_process_host->EnableZygote();
utility_process_host->Send(new ChromeUtilityMsg_DecodeImage(image_data));
}
diff --git a/chrome/browser/image_decoder.h b/chrome/browser/image_decoder.h
index 736961f..8c9c028 100644
--- a/chrome/browser/image_decoder.h
+++ b/chrome/browser/image_decoder.h
@@ -10,12 +10,13 @@
#include <vector>
#include "base/compiler_specific.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 SkBitmap;
// Decodes an image in a sandboxed process.
-class ImageDecoder : public UtilityProcessHost::Client {
+class ImageDecoder : public content::UtilityProcessHostClient {
public:
class Delegate {
public:
@@ -43,7 +44,7 @@ class ImageDecoder : public UtilityProcessHost::Client {
// It's a reference counted object, so destructor is private.
virtual ~ImageDecoder();
- // Overidden from UtilityProcessHost::Client:
+ // Overidden from UtilityProcessHostClient:
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// IPC message handlers.
diff --git a/chrome/browser/importer/external_process_importer_client.cc b/chrome/browser/importer/external_process_importer_client.cc
index 757a2d7..def875d 100644
--- a/chrome/browser/importer/external_process_importer_client.cc
+++ b/chrome/browser/importer/external_process_importer_client.cc
@@ -16,10 +16,12 @@
#include "chrome/browser/search_engines/template_url_service.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 "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
+using content::UtilityProcessHost;
ExternalProcessImporterClient::ExternalProcessImporterClient(
ExternalProcessImporterHost* importer_host,
@@ -75,15 +77,15 @@ void ExternalProcessImporterClient::Start() {
void ExternalProcessImporterClient::StartProcessOnIOThread(
BrowserThread::ID thread_id) {
utility_process_host_ =
- (new UtilityProcessHost(this, thread_id))->AsWeakPtr();
- utility_process_host_->set_no_sandbox(true);
+ UtilityProcessHost::Create(this, thread_id)->AsWeakPtr();
+ utility_process_host_->DisableSandbox();
#if defined(OS_MACOSX)
base::environment_vector env;
std::string dylib_path = GetFirefoxDylibPath().value();
if (!dylib_path.empty())
env.push_back(std::make_pair("DYLD_FALLBACK_LIBRARY_PATH", dylib_path));
- utility_process_host_->set_env(env);
+ utility_process_host_->SetEnv(env);
#endif
// Dictionary of all localized strings that could be needed by the importer
diff --git a/chrome/browser/importer/external_process_importer_client.h b/chrome/browser/importer/external_process_importer_client.h
index e8a834f..30c35de 100644
--- a/chrome/browser/importer/external_process_importer_client.h
+++ b/chrome/browser/importer/external_process_importer_client.h
@@ -11,15 +11,19 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
#include "base/string16.h"
#include "chrome/browser/importer/importer_data_types.h"
#include "chrome/browser/importer/profile_writer.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 ExternalProcessImporterHost;
class InProcessImporterBridge;
+
+namespace content {
class UtilityProcessHost;
+}
namespace history {
class URLRow;
@@ -29,7 +33,7 @@ struct ImportedFaviconUsage;
// This class is the client for the out of process profile importing. It
// collects notifications from this process host and feeds data back to the
// importer host, who actually does the writing.
-class ExternalProcessImporterClient : public UtilityProcessHost::Client {
+class ExternalProcessImporterClient : public content::UtilityProcessHostClient {
public:
ExternalProcessImporterClient(ExternalProcessImporterHost* importer_host,
const importer::SourceProfile& source_profile,
@@ -55,7 +59,7 @@ class ExternalProcessImporterClient : public UtilityProcessHost::Client {
// Called by the ExternalProcessImporterHost on import cancel.
virtual void Cancel();
- // UtilityProcessHost::Client implementation:
+ // UtilityProcessHostClient implementation:
virtual void OnProcessCrashed(int exit_code) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
@@ -111,7 +115,7 @@ class ExternalProcessImporterClient : public UtilityProcessHost::Client {
// Handles sending messages to the external process. Deletes itself when
// the external process dies (see
// BrowserChildProcessHost::OnChildDisconnected).
- base::WeakPtr<UtilityProcessHost> utility_process_host_;
+ base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
// Data to be passed from the importer host to the external importer.
const importer::SourceProfile& source_profile_;
diff --git a/chrome/browser/web_resource/web_resource_service.cc b/chrome/browser/web_resource/web_resource_service.cc
index 72724e6..aa5a45b 100644
--- a/chrome/browser/web_resource/web_resource_service.cc
+++ b/chrome/browser/web_resource/web_resource_service.cc
@@ -18,19 +18,22 @@
#include "chrome/common/chrome_utility_messages.h"
#include "chrome/common/web_resource/web_resource_unpacker.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
-#include "content/browser/utility_process_host.h"
#include "content/public/browser/browser_thread.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 "googleurl/src/gurl.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_request_status.h"
using content::BrowserThread;
+using content::UtilityProcessHost;
+using content::UtilityProcessHostClient;
// This class coordinates a web resource unpack and parse task which is run in
// a separate process. Results are sent back to this class and routed to
// the WebResourceService.
-class WebResourceService::UnpackerClient : public UtilityProcessHost::Client {
+class WebResourceService::UnpackerClient : public UtilityProcessHostClient {
public:
explicit UnpackerClient(WebResourceService* web_resource_service)
: web_resource_service_(web_resource_service),
@@ -68,8 +71,8 @@ class WebResourceService::UnpackerClient : public UtilityProcessHost::Client {
private:
virtual ~UnpackerClient() {}
- // UtilityProcessHost::Client
- virtual bool OnMessageReceived(const IPC::Message& message) {
+ // UtilityProcessHostClient
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(WebResourceService::UnpackerClient, message)
IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnpackWebResource_Succeeded,
@@ -81,7 +84,7 @@ class WebResourceService::UnpackerClient : public UtilityProcessHost::Client {
return handled;
}
- virtual void OnProcessCrashed(int exit_code) {
+ virtual void OnProcessCrashed(int exit_code) OVERRIDE {
if (got_response_)
return;
@@ -111,8 +114,8 @@ class WebResourceService::UnpackerClient : public UtilityProcessHost::Client {
void StartProcessOnIOThread(BrowserThread::ID thread_id,
const std::string& json_data) {
- UtilityProcessHost* host = new UtilityProcessHost(this, thread_id);
- host->set_use_linux_zygote(true);
+ UtilityProcessHost* host = UtilityProcessHost::Create(this, thread_id);
+ host->EnableZygote();
// TODO(mrc): get proper file path when we start using web resources
// that need to be unpacked.
host->Send(new ChromeUtilityMsg_UnpackWebResource(json_data));
diff --git a/content/browser/in_process_webkit/indexed_db_key_utility_client.cc b/content/browser/in_process_webkit/indexed_db_key_utility_client.cc
index e0ba5f9..331febf 100644
--- a/content/browser/in_process_webkit/indexed_db_key_utility_client.cc
+++ b/content/browser/in_process_webkit/indexed_db_key_utility_client.cc
@@ -7,13 +7,15 @@
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/synchronization/waitable_event.h"
-#include "content/browser/utility_process_host.h"
+#include "content/browser/utility_process_host_impl.h"
#include "content/common/indexed_db/indexed_db_key.h"
#include "content/common/indexed_db/indexed_db_messages.h"
#include "content/common/utility_messages.h"
+#include "content/public/browser/utility_process_host_client.h"
#include "content/public/common/serialized_script_value.h"
using content::BrowserThread;
+using content::UtilityProcessHostClient;
// This class is used to obtain IndexedDBKeys from SerializedScriptValues
// given an IDBKeyPath. It uses UtilityProcess to do this inside a sandbox
@@ -45,11 +47,11 @@ class KeyUtilityClientImpl
const string16& key_path);
private:
- class Client : public UtilityProcessHost::Client {
+ class Client : public UtilityProcessHostClient {
public:
explicit Client(KeyUtilityClientImpl* parent);
- // UtilityProcessHost::Client
+ // UtilityProcessHostClient
virtual void OnProcessCrashed(int exit_code);
virtual bool OnMessageReceived(const IPC::Message& message);
@@ -100,7 +102,7 @@ class KeyUtilityClientImpl
content::SerializedScriptValue value_after_injection_;
// Used in the IO thread.
- base::WeakPtr<UtilityProcessHost> utility_process_host_;
+ base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
scoped_refptr<Client> client_;
DISALLOW_COPY_AND_ASSIGN(KeyUtilityClientImpl);
@@ -275,9 +277,9 @@ void KeyUtilityClientImpl::StartUtilityProcessInternal() {
DCHECK(state_ == STATE_UNINITIALIZED);
client_ = new KeyUtilityClientImpl::Client(this);
- utility_process_host_ = (new UtilityProcessHost(
+ utility_process_host_ = (new UtilityProcessHostImpl(
client_.get(), BrowserThread::IO))->AsWeakPtr();
- utility_process_host_->set_use_linux_zygote(true);
+ utility_process_host_->EnableZygote();
utility_process_host_->StartBatchMode();
state_ = STATE_INITIALIZED;
waitable_event_.Signal();
diff --git a/content/browser/indexed_db/idbbindingutilities_browsertest.cc b/content/browser/indexed_db/idbbindingutilities_browsertest.cc
index 62aed97a..6583fd7 100644
--- a/content/browser/indexed_db/idbbindingutilities_browsertest.cc
+++ b/content/browser/indexed_db/idbbindingutilities_browsertest.cc
@@ -7,7 +7,8 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/renderer_host/resource_dispatcher_host.h"
-#include "content/browser/utility_process_host.h"
+#include "content/browser/utility_process_host_impl.h"
+#include "content/public/browser/utility_process_host_client.h"
#include "content/common/indexed_db/indexed_db_key.h"
#include "content/common/utility_messages.h"
#include "content/common/webkitplatformsupport_impl.h"
@@ -20,6 +21,8 @@
#include "webkit/glue/web_io_operators.h"
using content::BrowserThread;
+using content::UtilityProcessHost;
+using content::UtilityProcessHostClient;
using WebKit::WebSerializedScriptValue;
// Enables calling WebKit::shutdown no matter where a "return" happens.
@@ -104,7 +107,7 @@ TEST(IDBKeyPathWithoutSandbox, Value) {
ASSERT_EQ(WebKit::WebIDBKey::NullType, values[3].type());
}
-class IDBKeyPathHelper : public UtilityProcessHost::Client {
+class IDBKeyPathHelper : public UtilityProcessHostClient {
public:
IDBKeyPathHelper()
: expected_id_(0),
@@ -120,8 +123,8 @@ class IDBKeyPathHelper : public UtilityProcessHost::Client {
}
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
utility_process_host_ =
- (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr();
- utility_process_host_->set_use_linux_zygote(true);
+ (new UtilityProcessHostImpl(this, BrowserThread::IO))->AsWeakPtr();
+ utility_process_host_->EnableZygote();
utility_process_host_->StartBatchMode();
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
MessageLoop::QuitClosure());
@@ -187,7 +190,7 @@ class IDBKeyPathHelper : public UtilityProcessHost::Client {
ASSERT_TRUE(ret);
}
- // UtilityProcessHost::Client
+ // UtilityProcessHostClient
bool OnMessageReceived(const IPC::Message& message) {
bool msg_is_ok = true;
bool handled = true;
diff --git a/content/browser/plugin_loader_posix.cc b/content/browser/plugin_loader_posix.cc
index 5d506e6..58525d8 100644
--- a/content/browser/plugin_loader_posix.cc
+++ b/content/browser/plugin_loader_posix.cc
@@ -10,6 +10,7 @@
#include "base/metrics/histogram.h"
#include "content/common/child_process_host_impl.h"
#include "content/common/utility_messages.h"
+#include "content/browser/utility_process_host_impl.h"
#include "content/public/browser/browser_thread.h"
#include "webkit/plugins/npapi/plugin_list.h"
@@ -102,11 +103,12 @@ void PluginLoaderPosix::LoadPluginsInternal() {
if (load_start_time_.is_null())
load_start_time_ = base::TimeTicks::Now();
- process_host_ =
- (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr();
- process_host_->set_no_sandbox(true);
+ UtilityProcessHostImpl* host =
+ new UtilityProcessHostImpl(this, BrowserThread::IO);
+ process_host_ = host->AsWeakPtr();
+ process_host_->DisableSandbox();
#if defined(OS_MACOSX)
- process_host_->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION);
+ host->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION);
#endif
process_host_->Send(new UtilityMsg_LoadPlugins(canonical_list_));
diff --git a/content/browser/plugin_loader_posix.h b/content/browser/plugin_loader_posix.h
index cc5408e..7db8b8b0 100644
--- a/content/browser/plugin_loader_posix.h
+++ b/content/browser/plugin_loader_posix.h
@@ -8,20 +8,22 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "content/browser/plugin_service_impl.h"
-#include "content/browser/utility_process_host.h"
+#include "content/public/browser/utility_process_host_client.h"
#include "ipc/ipc_message.h"
#include "webkit/plugins/webplugininfo.h"
-class FilePath;
-class UtilityProcessHost;
-
namespace base {
class MessageLoopProxy;
}
+namespace content {
+class UtilityProcessHost;
+}
+
// This class is responsible for managing the out-of-process plugin loading on
// POSIX systems. It primarily lives on the IO thread, but has a brief stay on
// the FILE thread to iterate over plugin directories when it is first
@@ -43,8 +45,9 @@ class MessageLoopProxy;
// 5. This algorithm continues until the canonical list has been walked to the
// end, after which the list of loaded plugins is set on the PluginList and
// the completion callback is run.
-class CONTENT_EXPORT PluginLoaderPosix : public UtilityProcessHost::Client,
- IPC::Message::Sender {
+class CONTENT_EXPORT PluginLoaderPosix
+ : public NON_EXPORTED_BASE(content::UtilityProcessHostClient),
+ public IPC::Message::Sender {
public:
PluginLoaderPosix();
@@ -53,7 +56,7 @@ class CONTENT_EXPORT PluginLoaderPosix : public UtilityProcessHost::Client,
scoped_refptr<base::MessageLoopProxy> target_loop,
const content::PluginService::GetPluginsCallback& callback);
- // UtilityProcessHost::Client:
+ // UtilityProcessHostClient:
virtual void OnProcessCrashed(int exit_code) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
@@ -92,7 +95,7 @@ class CONTENT_EXPORT PluginLoaderPosix : public UtilityProcessHost::Client,
bool MaybeRunPendingCallbacks();
// The process host for which this is a client.
- base::WeakPtr<UtilityProcessHost> process_host_;
+ base::WeakPtr<content::UtilityProcessHost> process_host_;
// A list of paths to plugins which will be loaded by the utility process, in
// the order specified by this vector.
diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc
index 397ac1e..4477b2f 100644
--- a/content/browser/plugin_service_impl.cc
+++ b/content/browser/plugin_service_impl.cc
@@ -22,7 +22,6 @@
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/resource_context.h"
-#include "content/browser/utility_process_host.h"
#include "content/common/pepper_plugin_registry.h"
#include "content/common/plugin_messages.h"
#include "content/common/utility_messages.h"
diff --git a/content/browser/utility_process_host.h b/content/browser/utility_process_host.h
deleted file mode 100644
index ebb9ff9..0000000
--- a/content/browser/utility_process_host.h
+++ /dev/null
@@ -1,128 +0,0 @@
-// 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 CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_
-#define CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_
-#pragma once
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
-#include "base/process_util.h"
-#include "base/memory/weak_ptr.h"
-#include "content/common/content_export.h"
-#include "content/public/browser/browser_child_process_host_delegate.h"
-#include "content/public/browser/browser_thread.h"
-#include "ipc/ipc_message.h"
-
-class BrowserChildProcessHostImpl;
-
-// This class acts as the browser-side host to a utility child process. A
-// utility process is a short-lived sandboxed process that is created to run
-// a specific task. This class lives solely on the IO thread.
-// If you need a single method call in the sandbox, use StartFooBar(p).
-// If you need multiple batches of work to be done in the sandboxed process,
-// use StartBatchMode(), then multiple calls to StartFooBar(p),
-// then finish with EndBatchMode().
-//
-// Note: If your class keeps a ptr to an object of this type, grab a weak ptr to
-// avoid a use after free. See http://crbug.com/108871.
-class CONTENT_EXPORT UtilityProcessHost
- : public content::BrowserChildProcessHostDelegate,
- public IPC::Message::Sender,
- public base::SupportsWeakPtr<UtilityProcessHost> {
- public:
- // An interface to be implemented by consumers of the utility process to
- // get results back. All functions are called on the thread passed along
- // to UtilityProcessHost.
- class CONTENT_EXPORT Client : public base::RefCountedThreadSafe<Client> {
- public:
- Client();
-
- // Called when the process has crashed.
- virtual void OnProcessCrashed(int exit_code);
-
- // Allow the client to filter IPC messages.
- virtual bool OnMessageReceived(const IPC::Message& message);
-
- protected:
- friend class base::RefCountedThreadSafe<Client>;
-
- virtual ~Client();
-
- private:
- friend class UtilityProcessHost;
-
- DISALLOW_COPY_AND_ASSIGN(Client);
- };
-
- UtilityProcessHost(Client* client,
- content::BrowserThread::ID client_thread_id);
- virtual ~UtilityProcessHost();
-
- // IPC::Message::Sender implementation:
- virtual bool Send(IPC::Message* message) OVERRIDE;
-
- // Starts utility process in batch mode. Caller must call EndBatchMode()
- // to finish the utility process.
- bool StartBatchMode();
-
- // Ends the utility process. Must be called after StartBatchMode().
- void EndBatchMode();
-
- void set_exposed_dir(const FilePath& dir) { exposed_dir_ = dir; }
- void set_no_sandbox(bool flag) { no_sandbox_ = flag; }
- void set_child_flags(int flags) { child_flags_ = flags; }
- void set_use_linux_zygote(bool flag) { use_linux_zygote_ = flag; }
-#if defined(OS_POSIX)
- void set_env(const base::environment_vector& env) { env_ = env; }
-#endif
-
- protected:
- // Allow these methods to be overridden for tests.
- virtual FilePath GetUtilityProcessCmd();
-
- private:
- // Starts a process if necessary. Returns true if it succeeded or a process
- // has already been started via StartBatchMode().
- bool StartProcess();
-
- // BrowserChildProcessHost:
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
- virtual void OnProcessCrashed(int exit_code) OVERRIDE;
-
- // A pointer to our client interface, who will be informed of progress.
- scoped_refptr<Client> client_;
- content::BrowserThread::ID client_thread_id_;
- // True when running in batch mode, i.e., StartBatchMode() has been called
- // and the utility process will run until EndBatchMode().
- bool is_batch_mode_;
-
- // Allows a directory to be opened through the sandbox, in case it's needed by
- // the operation.
- FilePath exposed_dir_;
-
- // Whether to pass switches::kNoSandbox to the child.
- bool no_sandbox_;
-
- // Flags defined in ChildProcessHost with which to start the process.
- int child_flags_;
-
- // If the |no_sandbox_| flag is off, and we are on Linux, launch the
- // utility process from the zygote. Defaults to false.
- // Can only be used for tasks that do not require FS access.
- bool use_linux_zygote_;
-
- base::environment_vector env_;
-
- bool started_;
-
- scoped_ptr<BrowserChildProcessHostImpl> process_;
-
- DISALLOW_COPY_AND_ASSIGN(UtilityProcessHost);
-};
-
-#endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_
diff --git a/content/browser/utility_process_host.cc b/content/browser/utility_process_host_impl.cc
index d5ba05e..792dba1 100644
--- a/content/browser/utility_process_host.cc
+++ b/content/browser/utility_process_host_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/utility_process_host.h"
+#include "content/browser/utility_process_host_impl.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -13,6 +13,7 @@
#include "content/common/child_process_host_impl.h"
#include "content/common/utility_messages.h"
#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/utility_process_host_client.h"
#include "content/public/common/content_switches.h"
#include "ipc/ipc_switches.h"
#include "ui/base/ui_base_switches.h"
@@ -20,23 +21,21 @@
using content::BrowserThread;
using content::ChildProcessHost;
+using content::UtilityProcessHostClient;
-UtilityProcessHost::Client::Client() {
-}
-
-UtilityProcessHost::Client::~Client() {
-}
+namespace content {
-void UtilityProcessHost::Client::OnProcessCrashed(int exit_code) {
+UtilityProcessHost* UtilityProcessHost::Create(
+ UtilityProcessHostClient* client,
+ BrowserThread::ID client_thread_id) {
+ return new UtilityProcessHostImpl(client, client_thread_id);
}
-bool UtilityProcessHost::Client::OnMessageReceived(
- const IPC::Message& message) {
- return false;
}
-UtilityProcessHost::UtilityProcessHost(Client* client,
- BrowserThread::ID client_thread_id)
+UtilityProcessHostImpl::UtilityProcessHostImpl(
+ UtilityProcessHostClient* client,
+ BrowserThread::ID client_thread_id)
: client_(client),
client_thread_id_(client_thread_id),
is_batch_mode_(false),
@@ -52,36 +51,52 @@ UtilityProcessHost::UtilityProcessHost(Client* client,
new BrowserChildProcessHostImpl(content::PROCESS_TYPE_UTILITY, this));
}
-UtilityProcessHost::~UtilityProcessHost() {
+UtilityProcessHostImpl::~UtilityProcessHostImpl() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!is_batch_mode_);
}
-bool UtilityProcessHost::Send(IPC::Message* message) {
+bool UtilityProcessHostImpl::Send(IPC::Message* message) {
if (!StartProcess())
return false;
return process_->Send(message);
}
-bool UtilityProcessHost::StartBatchMode() {
+bool UtilityProcessHostImpl::StartBatchMode() {
CHECK(!is_batch_mode_);
is_batch_mode_ = StartProcess();
Send(new UtilityMsg_BatchMode_Started());
return is_batch_mode_;
}
-void UtilityProcessHost::EndBatchMode() {
+void UtilityProcessHostImpl::EndBatchMode() {
CHECK(is_batch_mode_);
is_batch_mode_ = false;
Send(new UtilityMsg_BatchMode_Finished());
}
-FilePath UtilityProcessHost::GetUtilityProcessCmd() {
- return ChildProcessHost::GetChildPath(child_flags_);
+void UtilityProcessHostImpl::SetExposedDir(const FilePath& dir) {
+ exposed_dir_ = dir;
+}
+
+void UtilityProcessHostImpl::DisableSandbox() {
+ no_sandbox_ = true;
+}
+
+void UtilityProcessHostImpl::EnableZygote() {
+ use_linux_zygote_ = true;
+}
+
+#if defined(OS_POSIX)
+
+void UtilityProcessHostImpl::SetEnv(const base::environment_vector& env) {
+ env_ = env;
}
-bool UtilityProcessHost::StartProcess() {
+#endif // OS_POSIX
+
+bool UtilityProcessHostImpl::StartProcess() {
if (started_)
return true;
started_ = true;
@@ -96,7 +111,7 @@ bool UtilityProcessHost::StartProcess() {
if (channel_id.empty())
return false;
- FilePath exe_path = GetUtilityProcessCmd();
+ FilePath exe_path = ChildProcessHost::GetChildPath(child_flags_);
if (exe_path.empty()) {
NOTREACHED() << "Unable to get utility process binary name.";
return false;
@@ -151,16 +166,18 @@ bool UtilityProcessHost::StartProcess() {
return true;
}
-bool UtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
+bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) {
BrowserThread::PostTask(
client_thread_id_, FROM_HERE,
- base::Bind(base::IgnoreResult(&Client::OnMessageReceived),
- client_.get(), message));
+ base::Bind(base::IgnoreResult(
+ &UtilityProcessHostClient::OnMessageReceived), client_.get(),
+ message));
return true;
}
-void UtilityProcessHost::OnProcessCrashed(int exit_code) {
+void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) {
BrowserThread::PostTask(
client_thread_id_, FROM_HERE,
- base::Bind(&Client::OnProcessCrashed, client_.get(), exit_code));
+ base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(),
+ exit_code));
}
diff --git a/content/browser/utility_process_host_impl.h b/content/browser/utility_process_host_impl.h
new file mode 100644
index 0000000..46a4ecd
--- /dev/null
+++ b/content/browser/utility_process_host_impl.h
@@ -0,0 +1,78 @@
+// 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 CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_
+#define CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/browser_child_process_host_delegate.h"
+#include "content/public/browser/utility_process_host.h"
+
+class BrowserChildProcessHostImpl;
+
+class CONTENT_EXPORT UtilityProcessHostImpl
+ : public NON_EXPORTED_BASE(content::UtilityProcessHost),
+ public content::BrowserChildProcessHostDelegate {
+ public:
+ UtilityProcessHostImpl(content::UtilityProcessHostClient* client,
+ content::BrowserThread::ID client_thread_id);
+ virtual ~UtilityProcessHostImpl();
+
+ // UtilityProcessHost implementation:
+ virtual bool Send(IPC::Message* message) OVERRIDE;
+ virtual bool StartBatchMode() OVERRIDE;
+ virtual void EndBatchMode() OVERRIDE;
+ virtual void SetExposedDir(const FilePath& dir) OVERRIDE;
+ virtual void DisableSandbox() OVERRIDE;
+ virtual void EnableZygote() OVERRIDE;
+#if defined(OS_POSIX)
+ virtual void SetEnv(const base::environment_vector& env) OVERRIDE;
+#endif
+
+ void set_child_flags(int flags) { child_flags_ = flags; }
+
+ private:
+ // Starts a process if necessary. Returns true if it succeeded or a process
+ // has already been started via StartBatchMode().
+ bool StartProcess();
+
+ // BrowserChildProcessHost:
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+ virtual void OnProcessCrashed(int exit_code) OVERRIDE;
+
+ // A pointer to our client interface, who will be informed of progress.
+ scoped_refptr<content::UtilityProcessHostClient> client_;
+ content::BrowserThread::ID client_thread_id_;
+ // True when running in batch mode, i.e., StartBatchMode() has been called
+ // and the utility process will run until EndBatchMode().
+ bool is_batch_mode_;
+
+ FilePath exposed_dir_;
+
+ // Whether to pass switches::kNoSandbox to the child.
+ bool no_sandbox_;
+
+ // Flags defined in ChildProcessHost with which to start the process.
+ int child_flags_;
+
+ // Launch the utility process from the zygote. Defaults to false.
+ bool use_linux_zygote_;
+
+ base::environment_vector env_;
+
+ bool started_;
+
+ scoped_ptr<BrowserChildProcessHostImpl> process_;
+
+ DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl);
+};
+
+#endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_H_
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index a21e4e0..380a09e 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -96,6 +96,7 @@
'public/browser/ssl_status.cc',
'public/browser/ssl_status.h',
'public/browser/user_metrics.h',
+ 'public/browser/utility_process_host.h',
'public/browser/web_contents.h',
'public/browser/web_contents_delegate.cc',
'public/browser/web_contents_delegate.h',
@@ -651,8 +652,8 @@
'browser/trace_subscriber_stdio.cc',
'browser/trace_subscriber_stdio.h',
'browser/user_metrics.cc',
- 'browser/utility_process_host.cc',
- 'browser/utility_process_host.h',
+ 'browser/utility_process_host_impl.cc',
+ 'browser/utility_process_host_impl.h',
'browser/webui/generic_handler.cc',
'browser/webui/generic_handler.h',
'browser/webui/web_ui_impl.cc',
diff --git a/content/public/browser/utility_process_host.h b/content/public/browser/utility_process_host.h
new file mode 100644
index 0000000..a965b96
--- /dev/null
+++ b/content/public/browser/utility_process_host.h
@@ -0,0 +1,66 @@
+// 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 CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
+#define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
+#pragma once
+
+#include "base/process_util.h"
+#include "content/common/content_export.h"
+#include "content/public/browser/browser_thread.h"
+#include "ipc/ipc_message.h"
+
+class FilePath;
+
+namespace content {
+
+class UtilityProcessHostClient;
+
+// This class acts as the browser-side host to a utility child process. A
+// utility process is a short-lived process that is created to run a specific
+// task. This class lives solely on the IO thread.
+// If you need a single method call in the process, use StartFooBar(p).
+// If you need multiple batches of work to be done in the process, use
+// StartBatchMode(), then multiple calls to StartFooBar(p), then finish with
+// EndBatchMode().
+//
+// Note: If your class keeps a ptr to an object of this type, grab a weak ptr to
+// avoid a use after free since this object is deleted synchronously but the
+// client notification is asynchronous. See http://crbug.com/108871.
+class UtilityProcessHost : public IPC::Message::Sender,
+ public base::SupportsWeakPtr<UtilityProcessHost> {
+ public:
+ // Used to create a utility process.
+ static CONTENT_EXPORT UtilityProcessHost* Create(
+ UtilityProcessHostClient* client,
+ BrowserThread::ID client_thread_id);
+
+ virtual ~UtilityProcessHost() {}
+
+ // Starts utility process in batch mode. Caller must call EndBatchMode()
+ // to finish the utility process.
+ virtual bool StartBatchMode() = 0;
+
+ // Ends the utility process. Must be called after StartBatchMode().
+ virtual void EndBatchMode() = 0;
+
+ // Allows a directory to be opened through the sandbox, in case it's needed by
+ // the operation.
+ virtual void SetExposedDir(const FilePath& dir) = 0;
+
+ // Make the process run without a sandbox.
+ virtual void DisableSandbox() = 0;
+
+ // If the sandbox is being used and we are on Linux, launch the process from
+ // the zygote. Can only be used for tasks that do not require FS access.
+ virtual void EnableZygote() = 0;
+
+#if defined(OS_POSIX)
+ virtual void SetEnv(const base::environment_vector& env) = 0;
+#endif
+};
+
+}; // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
diff --git a/content/public/browser/utility_process_host_client.h b/content/public/browser/utility_process_host_client.h
new file mode 100644
index 0000000..c449fd9
--- /dev/null
+++ b/content/public/browser/utility_process_host_client.h
@@ -0,0 +1,38 @@
+// 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 CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_CLIENT_H_
+#define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_CLIENT_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "content/common/content_export.h"
+
+namespace IPC {
+class Message;
+}
+
+namespace content {
+
+// An interface to be implemented by consumers of the utility process to
+// get results back. All functions are called on the thread passed along
+// to UtilityProcessHost.
+class UtilityProcessHostClient
+ : public base::RefCountedThreadSafe<UtilityProcessHostClient> {
+ public:
+ // Called when the process has crashed.
+ virtual void OnProcessCrashed(int exit_code) {}
+
+ // Allow the client to filter IPC messages.
+ virtual bool OnMessageReceived(const IPC::Message& message) = 0;
+
+ protected:
+ friend class base::RefCountedThreadSafe<UtilityProcessHostClient>;
+
+ virtual ~UtilityProcessHostClient() {}
+};
+
+}; // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_CLIENT_H_