Bug 1891340 - Part 1: Add parameters to customize the before and after icon tints...
[gecko.git] / ipc / glue / ProcessUtils.h
blob27c336a92cf7295b7e9c7dd4a1d5e5464bb38747
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
10 #include <functional>
11 #include <vector>
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"
19 namespace mozilla {
20 namespace ipc {
22 class GeckoChildProcessHost;
24 // You probably should call ContentChild::SetProcessName instead of calling
25 // this directly.
26 void SetThisProcessName(const char* aName);
28 class SharedPreferenceSerializer final {
29 public:
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;
47 private:
48 DISALLOW_COPY_AND_ASSIGN(SharedPreferenceSerializer);
49 size_t mPrefMapSize;
50 size_t mPrefsLength;
51 UniqueFileHandle mPrefMapHandle;
52 UniqueFileHandle mPrefsHandle;
55 class SharedPreferenceDeserializer final {
56 public:
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;
66 private:
67 DISALLOW_COPY_AND_ASSIGN(SharedPreferenceDeserializer);
68 Maybe<FileDescriptor> mPrefMapHandle;
69 Maybe<size_t> mPrefsLen;
70 Maybe<size_t> mPrefMapSize;
71 base::SharedMemory mShmem;
74 #if defined(ANDROID) || defined(XP_IOS)
75 // Android/iOS doesn't use -prefsHandle or -prefMapHandle. It gets those FDs
76 // another way.
77 void SetPrefsFd(int aFd);
78 void SetPrefMapFd(int aFd);
79 #endif
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
87 // JS::Runtime.
88 bool ImportSharedJSInit(uint64_t aJsInitHandle, uint64_t aJsInitLen);
90 } // namespace ipc
91 } // namespace mozilla
93 #endif // ifndef mozilla_ipc_ProcessUtils_h