ProcessLauncher.cpp [plain text]
#include "config.h"
#include "ProcessLauncher.h"
#include "WorkQueue.h"
#include <wtf/StdLibExtras.h>
namespace WebKit {
static WorkQueue* processLauncherWorkQueue()
{
static WorkQueue* processLauncherWorkQueue = WorkQueue::create("com.apple.WebKit.ProcessLauncher").leakRef();
return processLauncherWorkQueue;
}
ProcessLauncher::ProcessLauncher(Client* client, const LaunchOptions& launchOptions)
: m_client(client)
, m_launchOptions(launchOptions)
, m_processIdentifier(0)
{
m_isLaunching = true;
processLauncherWorkQueue()->dispatch(bind(&ProcessLauncher::launchProcess, this));
}
void ProcessLauncher::didFinishLaunchingProcess(PlatformProcessIdentifier processIdentifier, CoreIPC::Connection::Identifier identifier)
{
m_processIdentifier = processIdentifier;
m_isLaunching = false;
if (!m_client) {
#if PLATFORM(MAC)
if (identifier.port)
mach_port_mod_refs(mach_task_self(), identifier.port, MACH_PORT_RIGHT_RECEIVE, -1);
#if HAVE(XPC)
if (identifier.xpcConnection) {
xpc_release(identifier.xpcConnection);
identifier.xpcConnection = 0;
}
#endif
#endif
return;
}
m_client->didFinishLaunching(this, identifier);
}
void ProcessLauncher::invalidate()
{
m_client = 0;
platformInvalidate();
}
const char* ProcessLauncher::processTypeAsString(ProcessType processType)
{
switch (processType) {
case WebProcess:
return "webprocess";
#if ENABLE(PLUGIN_PROCESS)
case PluginProcess:
return "pluginprocess";
#endif
#if ENABLE(NETWORK_PROCESS)
case NetworkProcess:
return "networkprocess";
#endif
#if ENABLE(SHARED_WORKER_PROCESS)
case SharedWorkerProcess:
return "sharedworkerprocess";
#endif
}
ASSERT_NOT_REACHED();
return 0;
}
bool ProcessLauncher::getProcessTypeFromString(const char* string, ProcessType& processType)
{
if (!strcmp(string, "webprocess")) {
processType = WebProcess;
return true;
}
#if ENABLE(PLUGIN_PROCESS)
if (!strcmp(string, "pluginprocess")) {
processType = PluginProcess;
return true;
}
#endif
#if ENABLE(NETWORK_PROCESS)
if (!strcmp(string, "networkprocess")) {
processType = NetworkProcess;
return true;
}
#endif
#if ENABLE(SHARED_WORKER_PROCESS)
if (!strcmp(string, "sharedworkerprocess")) {
processType = SharedWorkerProcess;
return true;
}
#endif
return false;
}
}