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