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
This commit is contained in:
Jean-Yves Avenard 2019-05-25 10:12:45 +00:00
parent b27811b945
commit fec74fbc4b
3 changed files with 52 additions and 0 deletions

View File

@ -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());

View File

@ -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<ipc::SharedPreferenceSerializer>();
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<VRChild>(this);

View File

@ -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<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
};
} // namespace gfx