This source file includes following definitions.
- InitializeSandbox
- GetSandboxTypeFromCommandLine
- InitializeSandbox
#include "content/public/common/sandbox_init.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "content/common/sandbox_mac.h"
#include "content/public/common/content_switches.h"
namespace content {
bool InitializeSandbox(int sandbox_type, const base::FilePath& allowed_dir) {
Sandbox::SandboxWarmup(sandbox_type);
return Sandbox::EnableSandbox(sandbox_type, allowed_dir);
}
bool GetSandboxTypeFromCommandLine(int* sandbox_type,
base::FilePath* allowed_dir) {
DCHECK(sandbox_type);
DCHECK(allowed_dir);
*sandbox_type = -1;
*allowed_dir = base::FilePath();
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kNoSandbox))
return false;
std::string process_type =
command_line.GetSwitchValueASCII(switches::kProcessType);
if (process_type.empty()) {
return false;
} else if (process_type == switches::kRendererProcess) {
*sandbox_type = SANDBOX_TYPE_RENDERER;
} else if (process_type == switches::kUtilityProcess) {
*sandbox_type = SANDBOX_TYPE_UTILITY;
*allowed_dir =
command_line.GetSwitchValuePath(switches::kUtilityProcessAllowedDir);
} else if (process_type == switches::kWorkerProcess) {
*sandbox_type = SANDBOX_TYPE_WORKER;
} else if (process_type == switches::kGpuProcess) {
if (command_line.HasSwitch(switches::kDisableGpuSandbox))
return false;
*sandbox_type = SANDBOX_TYPE_GPU;
} else if ((process_type == switches::kPluginProcess) ||
(process_type == switches::kPpapiBrokerProcess)) {
return false;
} else if (process_type == switches::kPpapiPluginProcess) {
*sandbox_type = SANDBOX_TYPE_PPAPI;
} else {
return false;
}
return true;
}
bool InitializeSandbox() {
int sandbox_type = 0;
base::FilePath allowed_dir;
if (!GetSandboxTypeFromCommandLine(&sandbox_type, &allowed_dir))
return true;
return InitializeSandbox(sandbox_type, allowed_dir);
}
}