зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1539029 - pt 3 - de-duplicate building cmdline for shared prefs class. r=kmag
Cmd-line params for the SharedPreferenceSerializer was duplicated in ContentParent and SocketProcessHost. Since we'll have a 3rd process (RDD) using this same code, let's move the repsonsiblity for knowing how to add these cmdline params into SharedPreferenceSerializer. Depends on D26567 Differential Revision: https://phabricator.services.mozilla.com/D26568 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
385731ac09
Коммит
ac99c1dda6
|
@ -2056,6 +2056,7 @@ void ContentParent::LaunchSubprocessInternal(
|
|||
earlyReject();
|
||||
return;
|
||||
}
|
||||
prefSerializer.AddSharedPrefCmdLineArgs(*mSubprocess, extraArgs);
|
||||
|
||||
// Register ContentParent as an observer for changes to any pref
|
||||
// whose prefix matches the empty string, i.e. all of them. The
|
||||
|
@ -2063,43 +2064,6 @@ void ContentParent::LaunchSubprocessInternal(
|
|||
// happen during async launch.
|
||||
Preferences::AddStrongObserver(this, "");
|
||||
|
||||
// Formats a pointer or pointer-sized-integer as a string suitable for passing
|
||||
// in an arguments list.
|
||||
auto formatPtrArg = [](auto arg) {
|
||||
return nsPrintfCString("%zu", uintptr_t(arg));
|
||||
};
|
||||
|
||||
#if defined(XP_WIN)
|
||||
// Record the handle as to-be-shared, and pass it via a command flag. This
|
||||
// works because Windows handles are system-wide.
|
||||
HANDLE prefsHandle = prefSerializer.GetSharedMemoryHandle();
|
||||
mSubprocess->AddHandleToShare(prefsHandle);
|
||||
mSubprocess->AddHandleToShare(prefSerializer.GetPrefMapHandle().get());
|
||||
extraArgs.push_back("-prefsHandle");
|
||||
extraArgs.push_back(formatPtrArg(prefsHandle).get());
|
||||
extraArgs.push_back("-prefMapHandle");
|
||||
extraArgs.push_back(
|
||||
formatPtrArg(prefSerializer.GetPrefMapHandle().get()).get());
|
||||
#else
|
||||
// In contrast, Unix fds are per-process. So remap the fd to a fixed one that
|
||||
// will be used in the child.
|
||||
// XXX: bug 1440207 is about improving how fixed fds are used.
|
||||
//
|
||||
// Note: on Android, AddFdToRemap() sets up the fd to be passed via a Parcel,
|
||||
// and the fixed fd isn't used. However, we still need to mark it for
|
||||
// remapping so it doesn't get closed in the child.
|
||||
mSubprocess->AddFdToRemap(prefSerializer.GetSharedMemoryHandle().fd,
|
||||
kPrefsFileDescriptor);
|
||||
mSubprocess->AddFdToRemap(prefSerializer.GetPrefMapHandle().get(),
|
||||
kPrefMapFileDescriptor);
|
||||
#endif
|
||||
|
||||
// Pass the lengths via command line flags.
|
||||
extraArgs.push_back("-prefsLen");
|
||||
extraArgs.push_back(formatPtrArg(prefSerializer.GetPrefLength()).get());
|
||||
extraArgs.push_back("-prefMapSize");
|
||||
extraArgs.push_back(formatPtrArg(prefSerializer.GetPrefMapSize()).get());
|
||||
|
||||
if (gSafeMode) {
|
||||
extraArgs.push_back("-safeMode");
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
||||
class GeckoChildProcessHost;
|
||||
|
||||
// You probably should call ContentChild::SetProcessName instead of calling
|
||||
// this directly.
|
||||
void SetThisProcessName(const char* aName);
|
||||
|
@ -37,6 +39,9 @@ class SharedPreferenceSerializer final {
|
|||
|
||||
size_t GetPrefMapSize() const { return mPrefMapSize; }
|
||||
|
||||
void AddSharedPrefCmdLineArgs(GeckoChildProcessHost& procHost,
|
||||
std::vector<std::string>& aExtraOpts) const;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(SharedPreferenceSerializer);
|
||||
size_t mPrefMapSize;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "ProcessUtils.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ipc/GeckoChildProcessHost.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
|
@ -51,6 +52,46 @@ bool SharedPreferenceSerializer::SerializeToSharedMemory() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void SharedPreferenceSerializer::AddSharedPrefCmdLineArgs(
|
||||
mozilla::ipc::GeckoChildProcessHost& procHost,
|
||||
std::vector<std::string>& aExtraOpts) const {
|
||||
// Formats a pointer or pointer-sized-integer as a string suitable for passing
|
||||
// in an arguments list.
|
||||
auto formatPtrArg = [](auto arg) {
|
||||
return nsPrintfCString("%zu", uintptr_t(arg));
|
||||
};
|
||||
|
||||
#if defined(XP_WIN)
|
||||
// Record the handle as to-be-shared, and pass it via a command flag. This
|
||||
// works because Windows handles are system-wide.
|
||||
HANDLE prefsHandle = GetSharedMemoryHandle();
|
||||
procHost.AddHandleToShare(prefsHandle);
|
||||
procHost.AddHandleToShare(GetPrefMapHandle().get());
|
||||
aExtraOpts.push_back("-prefsHandle");
|
||||
aExtraOpts.push_back(formatPtrArg(prefsHandle).get());
|
||||
aExtraOpts.push_back("-prefMapHandle");
|
||||
aExtraOpts.push_back(
|
||||
formatPtrArg(GetPrefMapHandle().get()).get());
|
||||
#else
|
||||
// In contrast, Unix fds are per-process. So remap the fd to a fixed one that
|
||||
// will be used in the child.
|
||||
// XXX: bug 1440207 is about improving how fixed fds are used.
|
||||
//
|
||||
// Note: on Android, AddFdToRemap() sets up the fd to be passed via a Parcel,
|
||||
// and the fixed fd isn't used. However, we still need to mark it for
|
||||
// remapping so it doesn't get closed in the child.
|
||||
procHost.AddFdToRemap(GetSharedMemoryHandle().fd, kPrefsFileDescriptor);
|
||||
procHost.AddFdToRemap(GetPrefMapHandle().get(), kPrefMapFileDescriptor);
|
||||
#endif
|
||||
|
||||
// Pass the lengths via command line flags.
|
||||
aExtraOpts.push_back("-prefsLen");
|
||||
aExtraOpts.push_back(formatPtrArg(GetPrefLength()).get());
|
||||
aExtraOpts.push_back("-prefMapSize");
|
||||
aExtraOpts.push_back(formatPtrArg(GetPrefMapSize()).get());
|
||||
}
|
||||
|
||||
|
||||
#ifdef ANDROID
|
||||
static int gPrefsFd = -1;
|
||||
static int gPrefMapFd = -1;
|
||||
|
|
|
@ -111,41 +111,7 @@ bool SocketProcessHost::Launch() {
|
|||
if (!prefSerializer.SerializeToSharedMemory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Formats a pointer or pointer-sized-integer as a string suitable for passing
|
||||
// in an arguments list.
|
||||
auto formatPtrArg = [](auto arg) {
|
||||
return nsPrintfCString("%zu", uintptr_t(arg));
|
||||
};
|
||||
|
||||
#if defined(XP_WIN)
|
||||
// Record the handle as to-be-shared, and pass it via a command flag. This
|
||||
// works because Windows handles are system-wide.
|
||||
HANDLE prefsHandle = prefSerializer.GetSharedMemoryHandle();
|
||||
AddHandleToShare(prefsHandle);
|
||||
AddHandleToShare(prefSerializer.GetPrefMapHandle().get());
|
||||
extraArgs.push_back("-prefsHandle");
|
||||
extraArgs.push_back(formatPtrArg(prefsHandle).get());
|
||||
extraArgs.push_back("-prefMapHandle");
|
||||
extraArgs.push_back(
|
||||
formatPtrArg(prefSerializer.GetPrefMapHandle().get()).get());
|
||||
#else
|
||||
// In contrast, Unix fds are per-process. So remap the fd to a fixed one that
|
||||
// will be used in the child.
|
||||
// XXX: bug 1440207 is about improving how fixed fds are used.
|
||||
//
|
||||
// Note: on Android, AddFdToRemap() sets up the fd to be passed via a Parcel,
|
||||
// and the fixed fd isn't used. However, we still need to mark it for
|
||||
// remapping so it doesn't get closed in the child.
|
||||
AddFdToRemap(prefSerializer.GetSharedMemoryHandle().fd, kPrefsFileDescriptor);
|
||||
AddFdToRemap(prefSerializer.GetPrefMapHandle().get(), kPrefMapFileDescriptor);
|
||||
#endif
|
||||
|
||||
// Pass the lengths via command line flags.
|
||||
extraArgs.push_back("-prefsLen");
|
||||
extraArgs.push_back(formatPtrArg(prefSerializer.GetPrefLength()).get());
|
||||
extraArgs.push_back("-prefMapSize");
|
||||
extraArgs.push_back(formatPtrArg(prefSerializer.GetPrefMapSize()).get());
|
||||
prefSerializer.AddSharedPrefCmdLineArgs(*this, extraArgs);
|
||||
|
||||
mLaunchPhase = LaunchPhase::Waiting;
|
||||
if (!GeckoChildProcessHost::LaunchAndWaitForProcessHandle(extraArgs)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче