1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Mozilla IPC.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * Ben Turner <bent.mozilla@gmail.com>.
18 : * Portions created by the Initial Developer are Copyright (C) 2009
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPL"), or
25 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #ifndef __IPC_GLUE_GECKOCHILDPROCESSHOST_H__
38 : #define __IPC_GLUE_GECKOCHILDPROCESSHOST_H__
39 :
40 : #include "base/file_path.h"
41 : #include "base/process_util.h"
42 : #include "base/scoped_ptr.h"
43 : #include "base/waitable_event.h"
44 : #include "chrome/common/child_process_host.h"
45 :
46 : #include "mozilla/Monitor.h"
47 :
48 : #include "nsXULAppAPI.h" // for GeckoProcessType
49 : #include "nsString.h"
50 :
51 : namespace mozilla {
52 : namespace ipc {
53 :
54 : class GeckoChildProcessHost : public ChildProcessHost
55 : {
56 : protected:
57 : typedef mozilla::Monitor Monitor;
58 :
59 : public:
60 : typedef base::ProcessHandle ProcessHandle;
61 :
62 : GeckoChildProcessHost(GeckoProcessType aProcessType=GeckoProcessType_Default,
63 : base::WaitableEventWatcher::Delegate* aDelegate=nsnull);
64 :
65 : ~GeckoChildProcessHost();
66 :
67 : static nsresult GetArchitecturesForBinary(const char *path, uint32 *result);
68 :
69 : static uint32 GetSupportedArchitecturesForProcessType(GeckoProcessType type);
70 :
71 : bool SyncLaunch(std::vector<std::string> aExtraOpts=std::vector<std::string>(),
72 : int32 timeoutMs=0,
73 : base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
74 : bool AsyncLaunch(std::vector<std::string> aExtraOpts=std::vector<std::string>());
75 : bool PerformAsyncLaunch(std::vector<std::string> aExtraOpts=std::vector<std::string>(),
76 : base::ProcessArchitecture arch=base::GetCurrentProcessArchitecture());
77 :
78 : virtual void OnChannelConnected(int32 peer_pid);
79 : virtual void OnMessageReceived(const IPC::Message& aMsg);
80 : virtual void OnChannelError();
81 :
82 : void InitializeChannel();
83 :
84 : virtual bool CanShutdown() { return true; }
85 :
86 : virtual void OnWaitableEventSignaled(base::WaitableEvent *event);
87 :
88 0 : IPC::Channel* GetChannel() {
89 0 : return channelp();
90 : }
91 :
92 : base::WaitableEvent* GetShutDownEvent() {
93 : return GetProcessEvent();
94 : }
95 :
96 0 : ProcessHandle GetChildProcessHandle() {
97 0 : return mChildProcessHandle;
98 : }
99 :
100 : #ifdef XP_MACOSX
101 : task_t GetChildTask() {
102 : return mChildTask;
103 : }
104 : #endif
105 :
106 :
107 : protected:
108 : GeckoProcessType mProcessType;
109 : Monitor mMonitor;
110 : bool mLaunched;
111 : bool mChannelInitialized;
112 : FilePath mProcessPath;
113 :
114 : static PRInt32 mChildCounter;
115 :
116 : #ifdef XP_WIN
117 : void InitWindowsGroupID();
118 : nsString mGroupId;
119 : #endif
120 :
121 : #if defined(OS_POSIX)
122 : base::file_handle_mapping_vector mFileMap;
123 : #endif
124 :
125 : base::WaitableEventWatcher::Delegate* mDelegate;
126 :
127 : ProcessHandle mChildProcessHandle;
128 : #if defined(OS_MACOSX)
129 : task_t mChildTask;
130 : #endif
131 :
132 : private:
133 : DISALLOW_EVIL_CONSTRUCTORS(GeckoChildProcessHost);
134 :
135 : // Does the actual work for AsyncLaunch, on the IO thread.
136 : bool PerformAsyncLaunchInternal(std::vector<std::string>& aExtraOpts,
137 : base::ProcessArchitecture arch);
138 : };
139 :
140 : } /* namespace ipc */
141 : } /* namespace mozilla */
142 :
143 : #endif /* __IPC_GLUE_GECKOCHILDPROCESSHOST_H__ */
|