#include "content/public/app/initialize_mojo_core.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "content/public/common/content_switches.h"
#include "mojo/core/embedder/configuration.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/base/shared_memory_utils.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "sandbox/policy/sandbox_type.h"
namespace content {
void InitializeMojoCore() {
if (base::FeatureList::GetInstance()) {
mojo::core::InitFeatures();
} else {
DLOG(FATAL) << "Initializing Mojo without a FeatureList";
}
mojo::core::Configuration config;
config.max_message_num_bytes = 128 * 1024 * 1024;
const auto& command_line = *base::CommandLine::ForCurrentProcess();
const bool is_browser = !command_line.HasSwitch(switches::kProcessType);
if (is_browser) {
config.is_broker_process =
!command_line.HasSwitch(switches::kDisableMojoBroker) &&
!mojo::PlatformChannel::CommandLineHasPassedEndpoint(command_line);
if (!config.is_broker_process)
config.force_direct_shared_memory_allocation = true;
} else {
#if BUILDFLAG(IS_WIN)
config.force_direct_shared_memory_allocation = true;
#endif
}
mojo::core::Init(config);
#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_ANDROID)
if (sandbox::policy::IsUnsandboxedSandboxType(
sandbox::policy::SandboxTypeFromCommandLine(
*base::CommandLine::ForCurrentProcess()))) {
} else if (config.force_direct_shared_memory_allocation) {
} else {
DCHECK(!config.is_broker_process);
mojo::SharedMemoryUtils::InstallBaseHooks();
}
#endif
}
}