ProcessUtils.h (2634B)
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_ProcessUtils_h 8 #define mozilla_ipc_ProcessUtils_h 9 10 #include <functional> 11 12 #include "mozilla/GeckoArgs.h" 13 #include "mozilla/ipc/FileDescriptor.h" 14 #include "mozilla/ipc/SharedMemoryHandle.h" 15 #include "mozilla/ipc/SharedMemoryMapping.h" 16 #include "mozilla/Preferences.h" 17 #include "nsXULAppAPI.h" 18 19 namespace mozilla { 20 namespace ipc { 21 22 class GeckoChildProcessHost; 23 24 // You probably should call ContentChild::SetProcessName instead of calling 25 // this directly. 26 void SetThisProcessName(const char* aName); 27 28 class SharedPreferenceSerializer final { 29 public: 30 explicit SharedPreferenceSerializer(); 31 SharedPreferenceSerializer(SharedPreferenceSerializer&& aOther); 32 ~SharedPreferenceSerializer(); 33 34 bool SerializeToSharedMemory(const GeckoProcessType aDestinationProcessType, 35 const nsACString& aDestinationRemoteType); 36 37 const ReadOnlySharedMemoryHandle& GetPrefsHandle() const { 38 return mPrefsHandle; 39 } 40 41 const ReadOnlySharedMemoryHandle& GetPrefMapHandle() const { 42 return mPrefMapHandle; 43 } 44 45 void AddSharedPrefCmdLineArgs(GeckoChildProcessHost& procHost, 46 geckoargs::ChildProcessArgs& aExtraOpts) const; 47 48 private: 49 DISALLOW_COPY_AND_ASSIGN(SharedPreferenceSerializer); 50 ReadOnlySharedMemoryHandle mPrefMapHandle; 51 ReadOnlySharedMemoryHandle mPrefsHandle; 52 }; 53 54 class SharedPreferenceDeserializer final { 55 public: 56 SharedPreferenceDeserializer(); 57 ~SharedPreferenceDeserializer(); 58 59 bool DeserializeFromSharedMemory(ReadOnlySharedMemoryHandle&& aPrefsHandle, 60 ReadOnlySharedMemoryHandle&& aPrefMapHandle); 61 62 private: 63 DISALLOW_COPY_AND_ASSIGN(SharedPreferenceDeserializer); 64 ReadOnlySharedMemoryHandle mPrefMapHandle; 65 ReadOnlySharedMemoryMapping mShmem; 66 }; 67 68 // Generate command line argument to spawn a child process. If the shared memory 69 // is not properly initialized, this would be a no-op. 70 void ExportSharedJSInit(GeckoChildProcessHost& procHost, 71 geckoargs::ChildProcessArgs& aExtraOpts); 72 73 // Initialize the content used by the JS engine during the initialization of a 74 // JS::Runtime. 75 bool ImportSharedJSInit(ReadOnlySharedMemoryHandle&& aJsInitHandle); 76 77 } // namespace ipc 78 } // namespace mozilla 79 80 #endif // ifndef mozilla_ipc_ProcessUtils_h