ProcessChild.h (2385B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_ipc_ProcessChild_h 8 #define mozilla_ipc_ProcessChild_h 9 10 #include "Endpoint.h" 11 #include "base/message_loop.h" 12 #include "base/process.h" 13 14 #include "mozilla/GeckoArgs.h" 15 #include "mozilla/ipc/IOThread.h" 16 17 // ProcessChild is the base class for all subprocesses of the main 18 // browser process. Its code runs on the thread that started in 19 // main(). 20 21 namespace mozilla { 22 namespace ipc { 23 24 class ProcessChild { 25 protected: 26 typedef base::ProcessId ProcessId; 27 28 public: 29 explicit ProcessChild(IPC::Channel::ChannelHandle aClientChannel, 30 ProcessId aParentPid, const nsID& aMessageChannelId); 31 32 ProcessChild(const ProcessChild&) = delete; 33 ProcessChild& operator=(const ProcessChild&) = delete; 34 35 virtual ~ProcessChild(); 36 37 virtual bool Init(int aArgc, char* aArgv[]) = 0; 38 39 static void AddPlatformBuildID(geckoargs::ChildProcessArgs& aExtraArgs); 40 41 static bool InitPrefs(int aArgc, char* aArgv[]); 42 43 virtual void CleanUp() {} 44 45 static MessageLoop* message_loop() { return gProcessChild->mUILoop; } 46 47 static void NotifiedImpendingShutdown(); 48 49 static bool ExpectingShutdown(); 50 51 static void AppendToIPCShutdownStateAnnotation(const nsCString& aStr) { 52 StaticMutexAutoLock lock(gIPCShutdownStateLock); 53 gIPCShutdownStateAnnotation.Append(" - "_ns); 54 gIPCShutdownStateAnnotation.Append(aStr); 55 } 56 57 /** 58 * Exit *now*. Do not shut down XPCOM, do not pass Go, do not run 59 * static destructors, do not collect $200. 60 */ 61 static void QuickExit(); 62 63 protected: 64 static ProcessChild* current() { return gProcessChild; } 65 66 ProcessId ParentPid() { return mParentPid; } 67 68 UntypedEndpoint TakeInitialEndpoint(); 69 70 private: 71 static ProcessChild* gProcessChild; 72 static StaticMutex gIPCShutdownStateLock; 73 static nsCString gIPCShutdownStateAnnotation 74 MOZ_GUARDED_BY(gIPCShutdownStateLock); 75 76 MessageLoop* mUILoop; 77 ProcessId mParentPid; 78 nsID mMessageChannelId; 79 UniquePtr<IOThreadChild> mChildThread; 80 }; 81 82 } // namespace ipc 83 } // namespace mozilla 84 85 #endif // ifndef mozilla_ipc_ProcessChild_h