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/. */
7 #ifndef mozilla_ipc_ProcessUtils_h
8 #define mozilla_ipc_ProcessUtils_h
13 #include "mozilla/ipc/FileDescriptor.h"
14 #include "base/shared_memory.h"
15 #include "mozilla/Maybe.h"
16 #include "mozilla/Preferences.h"
17 #include "nsXULAppAPI.h"
22 class GeckoChildProcessHost
;
24 // You probably should call ContentChild::SetProcessName instead of calling
26 void SetThisProcessName(const char* aName
);
28 class SharedPreferenceSerializer final
{
30 explicit SharedPreferenceSerializer();
31 SharedPreferenceSerializer(SharedPreferenceSerializer
&& aOther
);
32 ~SharedPreferenceSerializer();
34 bool SerializeToSharedMemory(const GeckoProcessType aDestinationProcessType
,
35 const nsACString
& aDestinationRemoteType
);
37 size_t GetPrefMapSize() const { return mPrefMapSize
; }
38 size_t GetPrefsLength() const { return mPrefsLength
; }
40 const UniqueFileHandle
& GetPrefsHandle() const { return mPrefsHandle
; }
42 const UniqueFileHandle
& GetPrefMapHandle() const { return mPrefMapHandle
; }
44 void AddSharedPrefCmdLineArgs(GeckoChildProcessHost
& procHost
,
45 std::vector
<std::string
>& aExtraOpts
) const;
48 DISALLOW_COPY_AND_ASSIGN(SharedPreferenceSerializer
);
51 UniqueFileHandle mPrefMapHandle
;
52 UniqueFileHandle mPrefsHandle
;
55 class SharedPreferenceDeserializer final
{
57 SharedPreferenceDeserializer();
58 ~SharedPreferenceDeserializer();
60 bool DeserializeFromSharedMemory(uint64_t aPrefsHandle
,
61 uint64_t aPrefMapHandle
, uint64_t aPrefsLen
,
62 uint64_t aPrefMapSize
);
64 const FileDescriptor
& GetPrefMapHandle() const;
67 DISALLOW_COPY_AND_ASSIGN(SharedPreferenceDeserializer
);
68 Maybe
<FileDescriptor
> mPrefMapHandle
;
69 Maybe
<size_t> mPrefsLen
;
70 Maybe
<size_t> mPrefMapSize
;
71 base::SharedMemory mShmem
;
75 // Android doesn't use -prefsHandle or -prefMapHandle. It gets those FDs
77 void SetPrefsFd(int aFd
);
78 void SetPrefMapFd(int aFd
);
81 // Generate command line argument to spawn a child process. If the shared memory
82 // is not properly initialized, this would be a no-op.
83 void ExportSharedJSInit(GeckoChildProcessHost
& procHost
,
84 std::vector
<std::string
>& aExtraOpts
);
86 // Initialize the content used by the JS engine during the initialization of a
88 bool ImportSharedJSInit(uint64_t aJsInitHandle
, uint64_t aJsInitLen
);
91 } // namespace mozilla
93 #endif // ifndef mozilla_ipc_ProcessUtils_h