2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-06-29 18:38:29 +00:00
|
|
|
|
|
|
|
#ifndef __IPC_GLUE_GECKOCHILDPROCESSHOST_H__
|
|
|
|
#define __IPC_GLUE_GECKOCHILDPROCESSHOST_H__
|
|
|
|
|
|
|
|
#include "base/file_path.h"
|
|
|
|
#include "base/process_util.h"
|
|
|
|
#include "base/scoped_ptr.h"
|
|
|
|
#include "base/waitable_event.h"
|
|
|
|
#include "chrome/common/child_process_host.h"
|
|
|
|
|
2009-07-20 18:14:41 +00:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
|
2009-08-19 17:09:51 +00:00
|
|
|
#include "nsXULAppAPI.h" // for GeckoProcessType
|
2010-07-01 03:07:50 +00:00
|
|
|
#include "nsString.h"
|
2009-07-10 19:03:09 +00:00
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
class GeckoChildProcessHost : public ChildProcessHost
|
|
|
|
{
|
2009-07-20 18:14:41 +00:00
|
|
|
protected:
|
|
|
|
typedef mozilla::Monitor Monitor;
|
2012-08-07 23:29:32 +00:00
|
|
|
typedef std::vector<std::string> StringVector;
|
2009-07-20 18:14:41 +00:00
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
public:
|
2012-08-29 12:24:48 +00:00
|
|
|
typedef base::ChildPrivileges ChildPrivileges;
|
2009-10-27 21:52:37 +00:00
|
|
|
typedef base::ProcessHandle ProcessHandle;
|
|
|
|
|
2012-08-29 12:24:48 +00:00
|
|
|
GeckoChildProcessHost(GeckoProcessType aProcessType,
|
|
|
|
ChildPrivileges aPrivileges=base::PRIVILEGES_DEFAULT);
|
2009-06-29 18:38:29 +00:00
|
|
|
|
2009-11-09 22:56:55 +00:00
|
|
|
~GeckoChildProcessHost();
|
|
|
|
|
2012-09-17 08:37:20 +00:00
|
|
|
static nsresult GetArchitecturesForBinary(const char *path, uint32_t *result);
|
2010-09-16 06:09:19 +00:00
|
|
|
|
2012-09-17 08:37:20 +00:00
|
|
|
static uint32_t GetSupportedArchitecturesForProcessType(GeckoProcessType type);
|
2010-09-16 06:09:19 +00:00
|
|
|
|
2012-08-07 23:29:32 +00:00
|
|
|
// Block until the IPC channel for our subprocess is initialized,
|
|
|
|
// but no longer. The child process may or may not have been
|
|
|
|
// created when this method returns.
|
|
|
|
bool AsyncLaunch(StringVector aExtraOpts=StringVector());
|
|
|
|
|
|
|
|
// Block until the IPC channel for our subprocess is initialized and
|
|
|
|
// the OS process is created. The subprocess may or may not have
|
|
|
|
// connected back to us when this method returns.
|
|
|
|
//
|
|
|
|
// NB: on POSIX, this method is relatively cheap, and doesn't
|
|
|
|
// require disk IO. On win32 however, it requires at least the
|
|
|
|
// analogue of stat(). This difference induces a semantic
|
|
|
|
// difference in this method: on POSIX, when we return, we know the
|
|
|
|
// subprocess has been created, but we don't know whether its
|
|
|
|
// executable image can be loaded. On win32, we do know that when
|
|
|
|
// we return. But we don't know if dynamic linking succeeded on
|
|
|
|
// either platform.
|
|
|
|
bool LaunchAndWaitForProcessHandle(StringVector aExtraOpts=StringVector());
|
|
|
|
|
|
|
|
// Block until the child process has been created and it connects to
|
|
|
|
// the IPC channel, meaning it's fully initialized. (Or until an
|
|
|
|
// error occurs.)
|
|
|
|
bool SyncLaunch(StringVector aExtraOpts=StringVector(),
|
2012-09-17 08:37:20 +00:00
|
|
|
int32_t timeoutMs=0,
|
2010-09-16 06:09:19 +00:00
|
|
|
base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
|
2012-08-07 23:29:32 +00:00
|
|
|
|
|
|
|
bool PerformAsyncLaunch(StringVector aExtraOpts=StringVector(),
|
2010-09-16 06:09:19 +00:00
|
|
|
base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
|
2009-06-29 18:38:29 +00:00
|
|
|
|
2012-09-17 08:37:20 +00:00
|
|
|
virtual void OnChannelConnected(int32_t peer_pid);
|
2009-06-29 18:38:29 +00:00
|
|
|
virtual void OnMessageReceived(const IPC::Message& aMsg);
|
|
|
|
virtual void OnChannelError();
|
2012-07-14 21:21:32 +00:00
|
|
|
virtual void GetQueuedMessages(std::queue<IPC::Message>& queue);
|
2009-06-29 18:38:29 +00:00
|
|
|
|
2009-11-18 21:43:53 +00:00
|
|
|
void InitializeChannel();
|
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
virtual bool CanShutdown() { return true; }
|
|
|
|
|
2009-09-03 00:18:27 +00:00
|
|
|
virtual void OnWaitableEventSignaled(base::WaitableEvent *event);
|
|
|
|
|
2009-07-11 06:33:10 +00:00
|
|
|
IPC::Channel* GetChannel() {
|
|
|
|
return channelp();
|
|
|
|
}
|
|
|
|
|
2009-07-14 05:12:50 +00:00
|
|
|
base::WaitableEvent* GetShutDownEvent() {
|
|
|
|
return GetProcessEvent();
|
|
|
|
}
|
|
|
|
|
2009-10-27 21:52:37 +00:00
|
|
|
ProcessHandle GetChildProcessHandle() {
|
|
|
|
return mChildProcessHandle;
|
|
|
|
}
|
|
|
|
|
2010-08-27 13:32:45 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
task_t GetChildTask() {
|
|
|
|
return mChildTask;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
protected:
|
2009-08-19 17:09:51 +00:00
|
|
|
GeckoProcessType mProcessType;
|
2012-08-29 12:24:48 +00:00
|
|
|
ChildPrivileges mPrivileges;
|
2009-07-20 18:14:41 +00:00
|
|
|
Monitor mMonitor;
|
2009-06-29 18:38:29 +00:00
|
|
|
FilePath mProcessPath;
|
2012-08-07 23:29:32 +00:00
|
|
|
// This value must be accessed while holding mMonitor.
|
|
|
|
enum {
|
|
|
|
// This object has been constructed, but the OS process has not
|
|
|
|
// yet.
|
|
|
|
CREATING_CHANNEL = 0,
|
|
|
|
// The IPC channel for our subprocess has been created, but the OS
|
|
|
|
// process has still not been created.
|
|
|
|
CHANNEL_INITIALIZED,
|
|
|
|
// The OS process has been created, but it hasn't yet connected to
|
|
|
|
// our IPC channel.
|
|
|
|
PROCESS_CREATED,
|
|
|
|
// The process is launched and connected to our IPC channel. All
|
|
|
|
// is well.
|
|
|
|
PROCESS_CONNECTED,
|
|
|
|
PROCESS_ERROR
|
|
|
|
} mProcessState;
|
2009-06-29 18:38:29 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static int32_t mChildCounter;
|
2011-03-25 23:40:50 +00:00
|
|
|
|
2012-08-07 23:29:32 +00:00
|
|
|
void PrepareLaunch();
|
|
|
|
|
2010-07-01 03:07:50 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
void InitWindowsGroupID();
|
|
|
|
nsString mGroupId;
|
|
|
|
#endif
|
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
#if defined(OS_POSIX)
|
|
|
|
base::file_handle_mapping_vector mFileMap;
|
|
|
|
#endif
|
|
|
|
|
2009-09-03 00:18:27 +00:00
|
|
|
base::WaitableEventWatcher::Delegate* mDelegate;
|
|
|
|
|
2009-10-27 21:52:37 +00:00
|
|
|
ProcessHandle mChildProcessHandle;
|
2010-08-27 13:32:45 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
task_t mChildTask;
|
|
|
|
#endif
|
2009-10-27 21:52:37 +00:00
|
|
|
|
2009-06-29 18:38:29 +00:00
|
|
|
private:
|
|
|
|
DISALLOW_EVIL_CONSTRUCTORS(GeckoChildProcessHost);
|
2011-03-25 23:40:50 +00:00
|
|
|
|
|
|
|
// Does the actual work for AsyncLaunch, on the IO thread.
|
|
|
|
bool PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts,
|
|
|
|
base::ProcessArchitecture arch);
|
2012-07-14 21:21:32 +00:00
|
|
|
|
2012-08-07 23:29:32 +00:00
|
|
|
void OpenPrivilegedHandle(base::ProcessId aPid);
|
|
|
|
|
2012-07-14 21:21:32 +00:00
|
|
|
// In between launching the subprocess and handing off its IPC
|
|
|
|
// channel, there's a small window of time in which *we* might still
|
|
|
|
// be the channel listener, and receive messages. That's bad
|
|
|
|
// because we have no idea what to do with those messages. So queue
|
|
|
|
// them here until we hand off the eventual listener.
|
|
|
|
//
|
|
|
|
// FIXME/cjones: this strongly indicates bad design. Shame on us.
|
|
|
|
std::queue<IPC::Message> mQueue;
|
2009-06-29 18:38:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ipc */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|
|
|
|
#endif /* __IPC_GLUE_GECKOCHILDPROCESSHOST_H__ */
|