Commit db46ceb9 authored by Richard Knoll's avatar Richard Knoll Committed by Chromium LUCI CQ

Embedder-specific helper child process support

This allows embedders to define custom helper processes. They can define
the path to those by implementing ContentClient::GetChildPath(). For now
this is macOS only as the first place we need it is for macOS system
notifications.

Also updates the used message pump for services that do not run in a
sandboxed environment to use an NSApplication loop. This is necessary
to receive activation events from system notifications.

This CL is step 1 taken from rsesek@s prototype CL: crrev.com/c/2516122

Bug: 1127306
Change-Id: Iea2760b3daaa94bd797002be494c985abe8e78e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2625882
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843712}
parent 96da14fc
......@@ -589,6 +589,15 @@ gfx::Image& ChromeContentClient::GetNativeImageNamed(int resource_id) {
resource_id);
}
#if defined(OS_MAC)
base::FilePath ChromeContentClient::GetChildProcessPath(
int child_flags,
const base::FilePath& helpers_path) {
NOTREACHED() << "Unsupported child process flags!";
return {};
}
#endif // OS_MAC
std::string ChromeContentClient::GetProcessTypeNameInEnglish(int type) {
#if BUILDFLAG(ENABLE_NACL)
switch (type) {
......
......@@ -92,6 +92,11 @@ class ChromeContentClient : public content::ContentClient {
ui::ScaleFactor scale_factor) override;
base::RefCountedMemory* GetDataResourceBytes(int resource_id) override;
gfx::Image& GetNativeImageNamed(int resource_id) override;
#if defined(OS_MAC)
base::FilePath GetChildProcessPath(
int child_flags,
const base::FilePath& helpers_path) override;
#endif // OS_MAC
std::string GetProcessTypeNameInEnglish(int type) override;
blink::OriginTrialPolicy* GetOriginTrialPolicy() override;
#if defined(OS_ANDROID)
......
......@@ -25,6 +25,7 @@
#include "build/build_config.h"
#include "content/common/content_constants_internal.h"
#include "content/public/common/child_process_host_delegate.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
#include "ipc/ipc.mojom.h"
......@@ -104,7 +105,9 @@ base::FilePath ChildProcessHost::GetChildPath(int flags) {
#if BUILDFLAG(ENABLE_PLUGINS)
} else if (flags == CHILD_PLUGIN) {
child_base_name += kMacHelperSuffix_plugin;
#endif
#endif // ENABLE_PLUGINS
} else if (flags > CHILD_EMBEDDER_FIRST) {
return GetContentClient()->GetChildProcessPath(flags, child_path);
} else {
NOTREACHED();
}
......@@ -114,7 +117,7 @@ base::FilePath ChildProcessHost::GetChildPath(int flags) {
.Append("MacOS")
.Append(child_base_name);
}
#endif
#endif // OS_MAC
return child_path;
}
......
......@@ -125,6 +125,12 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
// CHILD_NORMAL, and this cannot be combined with any other CHILD_* values.
CHILD_LAUNCH_X86_64,
#endif // ARCH_CPU_ARM64
// Marker for the start of embedder-specific helper child process types.
// Values greater than CHILD_EMBEDDER_FIRST are reserved to be used by the
// embedder to add custom process types and will be resolved via
// ContentClient::GetChildPath().
CHILD_EMBEDDER_FIRST,
#endif
};
......
......@@ -4,6 +4,7 @@
#include "content/public/common/content_client.h"
#include "base/files/file_path.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/strings/string_piece.h"
......@@ -91,6 +92,15 @@ gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) {
return *kEmptyImage;
}
#if defined(OS_MAC)
base::FilePath ContentClient::GetChildProcessPath(
int child_flags,
const base::FilePath& helpers_path) {
NOTIMPLEMENTED();
return base::FilePath();
}
#endif
std::string ContentClient::GetProcessTypeNameInEnglish(int type) {
NOTIMPLEMENTED();
return std::string();
......
......@@ -21,6 +21,7 @@
#include "url/url_util.h"
namespace base {
class FilePath;
class RefCountedMemory;
class SequencedTaskRunner;
}
......@@ -166,6 +167,16 @@ class CONTENT_EXPORT ContentClient {
// Returns a native image given its id.
virtual gfx::Image& GetNativeImageNamed(int resource_id);
#if defined(OS_MAC)
// Gets the path for an embedder-specific helper child process. The
// |child_flags| is a value greater than
// ChildProcessHost::CHILD_EMBEDDER_FIRST. The |helpers_path| is the location
// of the known //content Mac helpers in the framework bundle.
virtual base::FilePath GetChildProcessPath(
int child_flags,
const base::FilePath& helpers_path);
#endif // defined(OS_MAC)
// Called by content::GetProcessTypeNameInEnglish for process types that it
// doesn't know about because they're from the embedder.
virtual std::string GetProcessTypeNameInEnglish(int type);
......
......@@ -58,16 +58,20 @@ int UtilityMain(const MainFunctionParams& parameters) {
: base::MessagePumpType::DEFAULT;
#if defined(OS_MAC)
// On Mac, the TYPE_UI pump for the main thread is an NSApplication loop. In
// a sandboxed utility process, NSApp attempts to acquire more Mach resources
// than a restrictive sandbox policy should allow. Services that require a
// TYPE_UI pump generally just need a NS/CFRunLoop to pump system work
// sources, so choose that pump type instead. A NSRunLoop MessagePump is used
// for TYPE_UI MessageLoops on non-main threads.
base::MessagePump::OverrideMessagePumpForUIFactory(
[]() -> std::unique_ptr<base::MessagePump> {
return std::make_unique<base::MessagePumpNSRunLoop>();
});
auto sandbox_type =
sandbox::policy::SandboxTypeFromCommandLine(parameters.command_line);
if (sandbox_type != sandbox::policy::SandboxType::kNoSandbox) {
// On Mac, the TYPE_UI pump for the main thread is an NSApplication loop.
// In a sandboxed utility process, NSApp attempts to acquire more Mach
// resources than a restrictive sandbox policy should allow. Services that
// require a TYPE_UI pump generally just need a NS/CFRunLoop to pump system
// work sources, so choose that pump type instead. A NSRunLoop MessagePump
// is used for TYPE_UI MessageLoops on non-main threads.
base::MessagePump::OverrideMessagePumpForUIFactory(
[]() -> std::unique_ptr<base::MessagePump> {
return std::make_unique<base::MessagePumpNSRunLoop>();
});
}
#endif
#if defined(OS_FUCHSIA)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment