2012-05-21 04:12:37 -07: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 11:38:29 -07: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 11:14:41 -07:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
|
2009-08-19 10:09:51 -07:00
|
|
|
#include "nsXULAppAPI.h" // for GeckoProcessType
|
2010-06-30 20:07:50 -07:00
|
|
|
#include "nsString.h"
|
2009-07-10 12:03:09 -07:00
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
class GeckoChildProcessHost : public ChildProcessHost
|
|
|
|
{
|
2009-07-20 11:14:41 -07:00
|
|
|
protected:
|
|
|
|
typedef mozilla::Monitor Monitor;
|
2012-08-07 16:29:32 -07:00
|
|
|
typedef std::vector<std::string> StringVector;
|
2009-07-20 11:14:41 -07:00
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
public:
|
2012-08-29 05:24:48 -07:00
|
|
|
typedef base::ChildPrivileges ChildPrivileges;
|
2009-10-27 14:52:37 -07:00
|
|
|
typedef base::ProcessHandle ProcessHandle;
|
|
|
|
|
2012-08-29 05:24:48 -07:00
|
|
|
GeckoChildProcessHost(GeckoProcessType aProcessType,
|
|
|
|
ChildPrivileges aPrivileges=base::PRIVILEGES_DEFAULT);
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2009-11-09 14:56:55 -08:00
|
|
|
~GeckoChildProcessHost();
|
|
|
|
|
2012-09-17 01:37:20 -07:00
|
|
|
static nsresult GetArchitecturesForBinary(const char *path, uint32_t *result);
|
2010-09-15 23:09:19 -07:00
|
|
|
|
2012-09-17 01:37:20 -07:00
|
|
|
static uint32_t GetSupportedArchitecturesForProcessType(GeckoProcessType type);
|
2010-09-15 23:09:19 -07:00
|
|
|
|
2012-08-07 16:29:32 -07: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 01:37:20 -07:00
|
|
|
int32_t timeoutMs=0,
|
2010-09-15 23:09:19 -07:00
|
|
|
base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
|
2012-08-07 16:29:32 -07:00
|
|
|
|
|
|
|
bool PerformAsyncLaunch(StringVector aExtraOpts=StringVector(),
|
2010-09-15 23:09:19 -07:00
|
|
|
base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2012-09-17 01:37:20 -07:00
|
|
|
virtual void OnChannelConnected(int32_t peer_pid);
|
2009-06-29 11:38:29 -07:00
|
|
|
virtual void OnMessageReceived(const IPC::Message& aMsg);
|
|
|
|
virtual void OnChannelError();
|
2012-07-14 14:21:32 -07:00
|
|
|
virtual void GetQueuedMessages(std::queue<IPC::Message>& queue);
|
2009-06-29 11:38:29 -07:00
|
|
|
|
2009-11-18 13:43:53 -08:00
|
|
|
void InitializeChannel();
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
virtual bool CanShutdown() { return true; }
|
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
virtual void OnWaitableEventSignaled(base::WaitableEvent *event);
|
|
|
|
|
2009-07-10 23:33:10 -07:00
|
|
|
IPC::Channel* GetChannel() {
|
|
|
|
return channelp();
|
|
|
|
}
|
|
|
|
|
2009-07-13 22:12:50 -07:00
|
|
|
base::WaitableEvent* GetShutDownEvent() {
|
|
|
|
return GetProcessEvent();
|
|
|
|
}
|
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
ProcessHandle GetChildProcessHandle() {
|
|
|
|
return mChildProcessHandle;
|
|
|
|
}
|
|
|
|
|
2010-08-27 06:32:45 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
task_t GetChildTask() {
|
|
|
|
return mChildTask;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
protected:
|
2009-08-19 10:09:51 -07:00
|
|
|
GeckoProcessType mProcessType;
|
2012-08-29 05:24:48 -07:00
|
|
|
ChildPrivileges mPrivileges;
|
2009-07-20 11:14:41 -07:00
|
|
|
Monitor mMonitor;
|
2009-06-29 11:38:29 -07:00
|
|
|
FilePath mProcessPath;
|
2012-08-07 16:29:32 -07: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 11:38:29 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t mChildCounter;
|
2011-03-25 16:40:50 -07:00
|
|
|
|
2012-08-07 16:29:32 -07:00
|
|
|
void PrepareLaunch();
|
|
|
|
|
2010-06-30 20:07:50 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
void InitWindowsGroupID();
|
|
|
|
nsString mGroupId;
|
|
|
|
#endif
|
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
#if defined(OS_POSIX)
|
|
|
|
base::file_handle_mapping_vector mFileMap;
|
|
|
|
#endif
|
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
base::WaitableEventWatcher::Delegate* mDelegate;
|
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
ProcessHandle mChildProcessHandle;
|
2010-08-27 06:32:45 -07:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
task_t mChildTask;
|
|
|
|
#endif
|
2009-10-27 14:52:37 -07:00
|
|
|
|
2009-06-29 11:38:29 -07:00
|
|
|
private:
|
|
|
|
DISALLOW_EVIL_CONSTRUCTORS(GeckoChildProcessHost);
|
2011-03-25 16:40:50 -07:00
|
|
|
|
|
|
|
// Does the actual work for AsyncLaunch, on the IO thread.
|
|
|
|
bool PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts,
|
|
|
|
base::ProcessArchitecture arch);
|
2012-07-14 14:21:32 -07:00
|
|
|
|
2012-08-07 16:29:32 -07:00
|
|
|
void OpenPrivilegedHandle(base::ProcessId aPid);
|
|
|
|
|
2012-07-14 14:21:32 -07: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 11:38:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ipc */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|
|
|
|
#endif /* __IPC_GLUE_GECKOCHILDPROCESSHOST_H__ */
|