Bug 1550422 - P8. Add shared pref serializer/deserializer to VR process. r?kmag!,daoshengmu! draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 14 May 2019 12:38:44 +1000
changeset 2008585 d8113a005c417457cd19af19cd45b1b09c21357b
parent 2008584 74aa9c272547782d14d3548a7c00021da5cf10d2
child 2008586 04c90f4ed76f625cc99d4a53f6ed6bb3fa7bb44a
push id363925
push userjyavenard@mozilla.com
push dateSat, 18 May 2019 07:53:18 +0000
treeherdertry@5082cd581229 [default view] [failures only]
reviewerskmag
bugs1550422
milestone68.0a1
Bug 1550422 - P8. Add shared pref serializer/deserializer to VR process. r?kmag!,daoshengmu! Differential Revision: https://phabricator.services.mozilla.com/D31016
gfx/vr/ipc/VRProcessChild.cpp
gfx/vr/ipc/VRProcessParent.cpp
gfx/vr/ipc/VRProcessParent.h
--- a/gfx/vr/ipc/VRProcessChild.cpp
+++ b/gfx/vr/ipc/VRProcessChild.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "VRProcessChild.h"
 
 #include "mozilla/BackgroundHangMonitor.h"
 #include "mozilla/ipc/IOThreadChild.h"
+#include "ProcessUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using mozilla::ipc::IOThreadChild;
 
 StaticRefPtr<VRParent> sVRParent;
 
 VRProcessChild::VRProcessChild(ProcessId aParentPid)
@@ -23,25 +24,58 @@ VRProcessChild::~VRProcessChild() { sVRP
 /*static*/
 VRParent* VRProcessChild::GetVRParent() {
   MOZ_ASSERT(sVRParent);
   return sVRParent;
 }
 
 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());
 
   return true;
 }
 
 void VRProcessChild::CleanUp() {
--- a/gfx/vr/ipc/VRProcessParent.cpp
+++ b/gfx/vr/ipc/VRProcessParent.cpp
@@ -8,16 +8,17 @@
 #include "VRGPUChild.h"
 #include "VRProcessManager.h"
 #include "mozilla/gfx/GPUProcessManager.h"
 #include "mozilla/gfx/GPUChild.h"
 #include "mozilla/ipc/ProtocolTypes.h"
 #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"
 #include "gfxVRPuppet.h"
 
 #include "nsAppRunner.h"  // for IToplevelProtocol
 #include "mozilla/ipc/ProtocolUtils.h"
 
@@ -56,18 +57,25 @@ bool VRProcessParent::Launch() {
 
   mLaunchPhase = LaunchPhase::Waiting;
 
   std::vector<std::string> extraArgs;
   nsCString parentBuildID(mozilla::PlatformBuildID());
   extraArgs.push_back("-parentBuildID");
   extraArgs.push_back(parentBuildID.get());
 
+  mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
+  if (!mPrefSerializer->SerializeToSharedMemory()) {
+    return false;
+  }
+  mPrefSerializer->AddSharedPrefCmdLineArgs(*this, extraArgs);
+
   if (!GeckoChildProcessHost::AsyncLaunch(extraArgs)) {
     mLaunchPhase = LaunchPhase::Complete;
+    mPrefSerializer = nullptr;
     return false;
   }
   return true;
 }
 
 bool VRProcessParent::WaitForLaunch() {
   if (mLaunchPhase == LaunchPhase::Complete) {
     return !!mVRChild;
@@ -129,16 +137,18 @@ void VRProcessParent::DestroyProcess() {
   }
 }
 
 void VRProcessParent::InitAfterConnect(bool aSucceeded) {
   MOZ_ASSERT(mLaunchPhase == LaunchPhase::Waiting);
   MOZ_ASSERT(!mVRChild);
 
   mLaunchPhase = LaunchPhase::Complete;
+  mPrefSerializer = nullptr;
+
   if (aSucceeded) {
     mVRChild = MakeUnique<VRChild>(this);
 
     DebugOnly<bool> rv =
         mVRChild->Open(GetChannel(), base::GetProcId(GetChildProcessHandle()));
     MOZ_ASSERT(rv);
 
     mVRChild->Init();
--- a/gfx/vr/ipc/VRProcessParent.h
+++ b/gfx/vr/ipc/VRProcessParent.h
@@ -8,16 +8,19 @@
 #define GFX_VR_PROCESS_PARENT_H
 
 #include "mozilla/UniquePtr.h"
 
 #include "mozilla/ipc/GeckoChildProcessHost.h"
 #include "mozilla/ipc/TaskFactory.h"
 
 namespace mozilla {
+namespace ipc {
+class SharedPreferenceSerializer;
+}
 namespace gfx {
 
 class VRChild;
 
 class VRProcessParent final : public mozilla::ipc::GeckoChildProcessHost {
  public:
   class Listener {
    public:
@@ -26,16 +29,20 @@ class VRProcessParent final : public moz
     // Follow GPU and RDD process manager, adding this to avoid
     // unexpectedly shutdown or had its connection severed.
     // This is not called if an error occurs after calling Shutdown().
     virtual void OnProcessUnexpectedShutdown(VRProcessParent* aParent) {}
   };
 
   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.
   //
   // Returns true if the process is successfully connected; false otherwise.
   bool WaitForLaunch();
   void Shutdown();
   void DestroyProcess();
@@ -66,14 +73,15 @@ class VRProcessParent final : public moz
   mozilla::ipc::TaskFactory<VRProcessParent> mTaskFactory;
   nsCOMPtr<nsIThread> mLaunchThread;
   Listener* mListener;
 
   enum class LaunchPhase { Unlaunched, Waiting, Complete };
   LaunchPhase mLaunchPhase;
   bool mChannelClosed;
   bool mShutdownRequested;
+  UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
 };
 
 }  // namespace gfx
 }  // namespace mozilla
 
 #endif  // ifndef GFX_VR_PROCESS_PARENT_H