From fec74fbc4b061cd9bf1aebd4274d9015bafabfbd Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Sat, 25 May 2019 10:12:45 +0000 Subject: [PATCH] Bug 1550422 - P8. Add shared pref serializer/deserializer to VR process. r=kmag,daoshengmu Differential Revision: https://phabricator.services.mozilla.com/D31016 --HG-- extra : moz-landing-system : lando --- gfx/vr/ipc/VRProcessChild.cpp | 34 ++++++++++++++++++++++++++++++++++ gfx/vr/ipc/VRProcessParent.cpp | 10 ++++++++++ gfx/vr/ipc/VRProcessParent.h | 8 ++++++++ 3 files changed, 52 insertions(+) diff --git a/gfx/vr/ipc/VRProcessChild.cpp b/gfx/vr/ipc/VRProcessChild.cpp index 4c39bd744ccc..4a1e5d34b2f2 100644 --- a/gfx/vr/ipc/VRProcessChild.cpp +++ b/gfx/vr/ipc/VRProcessChild.cpp @@ -8,6 +8,7 @@ #include "mozilla/BackgroundHangMonitor.h" #include "mozilla/ipc/IOThreadChild.h" +#include "ProcessUtils.h" using namespace mozilla; using namespace mozilla::gfx; @@ -28,15 +29,48 @@ VRParent* VRProcessChild::GetVRParent() { bool VRProcessChild::Init(int aArgc, char* aArgv[]) { char* parentBuildID = nullptr; + char* prefsHandle = nullptr; + char* prefMapHandle = nullptr; + char* prefsLen = nullptr; + char* prefMapSize = nullptr; for (int i = 1; i < aArgc; i++) { if (!aArgv[i]) { continue; } if (strcmp(aArgv[i], "-parentBuildID") == 0) { parentBuildID = aArgv[i + 1]; + +#ifdef XP_WIN + } else if (strcmp(aArgv[i], "-prefsHandle") == 0) { + if (++i == aArgc) { + return false; + } + prefsHandle = aArgv[i]; + } else if (strcmp(aArgv[i], "-prefMapHandle") == 0) { + if (++i == aArgc) { + return false; + } + prefMapHandle = aArgv[i]; +#endif + } else if (strcmp(aArgv[i], "-prefsLen") == 0) { + if (++i == aArgc) { + return false; + } + prefsLen = aArgv[i]; + } else if (strcmp(aArgv[i], "-prefMapSize") == 0) { + if (++i == aArgc) { + return false; + } + prefMapSize = aArgv[i]; } } + SharedPreferenceDeserializer deserializer; + if (!deserializer.DeserializeFromSharedMemory(prefsHandle, prefMapHandle, + prefsLen, prefMapSize)) { + return false; + } + sVRParent = new VRParent(); sVRParent->Init(ParentPid(), parentBuildID, IOThreadChild::message_loop(), IOThreadChild::channel()); diff --git a/gfx/vr/ipc/VRProcessParent.cpp b/gfx/vr/ipc/VRProcessParent.cpp index af09cc911b15..988985a6c030 100644 --- a/gfx/vr/ipc/VRProcessParent.cpp +++ b/gfx/vr/ipc/VRProcessParent.cpp @@ -13,6 +13,7 @@ #include "mozilla/ipc/ProtocolUtils.h" // for IToplevelProtocol #include "mozilla/TimeStamp.h" // for TimeStamp #include "mozilla/Unused.h" +#include "ProcessUtils.h" #include "VRChild.h" #include "VRManager.h" #include "VRThread.h" @@ -61,8 +62,15 @@ bool VRProcessParent::Launch() { extraArgs.push_back("-parentBuildID"); extraArgs.push_back(parentBuildID.get()); + mPrefSerializer = MakeUnique(); + if (!mPrefSerializer->SerializeToSharedMemory()) { + return false; + } + mPrefSerializer->AddSharedPrefCmdLineArgs(*this, extraArgs); + if (!GeckoChildProcessHost::AsyncLaunch(extraArgs)) { mLaunchPhase = LaunchPhase::Complete; + mPrefSerializer = nullptr; return false; } return true; @@ -134,6 +142,8 @@ void VRProcessParent::InitAfterConnect(bool aSucceeded) { MOZ_ASSERT(!mVRChild); mLaunchPhase = LaunchPhase::Complete; + mPrefSerializer = nullptr; + if (aSucceeded) { mVRChild = MakeUnique(this); diff --git a/gfx/vr/ipc/VRProcessParent.h b/gfx/vr/ipc/VRProcessParent.h index 22d3c7339766..0be7f45d777c 100644 --- a/gfx/vr/ipc/VRProcessParent.h +++ b/gfx/vr/ipc/VRProcessParent.h @@ -13,6 +13,9 @@ #include "mozilla/ipc/TaskFactory.h" namespace mozilla { +namespace ipc { +class SharedPreferenceSerializer; +} namespace gfx { class VRChild; @@ -31,6 +34,10 @@ class VRProcessParent final : public mozilla::ipc::GeckoChildProcessHost { explicit VRProcessParent(Listener* aListener); + // Launch the subprocess asynchronously. On failure, false is returned. + // Otherwise, true is returned, and the OnProcessLaunchComplete listener + // callback will be invoked either when a connection has been established, or + // if a connection could not be established due to an asynchronous error. bool Launch(); // If the process is being launched, block until it has launched and // connected. If a launch task is pending, it will fire immediately. @@ -71,6 +78,7 @@ class VRProcessParent final : public mozilla::ipc::GeckoChildProcessHost { LaunchPhase mLaunchPhase; bool mChannelClosed; bool mShutdownRequested; + UniquePtr mPrefSerializer; }; } // namespace gfx