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/. */
6
7 #include "VRProcessChild.h"
8
9 #include "mozilla/BackgroundHangMonitor.h"
10 #include "mozilla/ipc/IOThreadChild.h"
11 #include "mozilla/ipc/ProcessUtils.h"
12 #include "mozilla/StaticPrefs_dom.h"
13
14 using namespace mozilla;
15 using namespace mozilla::gfx;
16 using mozilla::ipc::IOThreadChild;
17
18 StaticRefPtr<VRParent> sVRParent;
19
VRProcessChild(ProcessId aParentPid)20 VRProcessChild::VRProcessChild(ProcessId aParentPid)
21 : ProcessChild(aParentPid) {}
22
~VRProcessChild()23 VRProcessChild::~VRProcessChild() { sVRParent = nullptr; }
24
25 /*static*/
GetVRParent()26 VRParent* VRProcessChild::GetVRParent() {
27 MOZ_ASSERT(sVRParent);
28 return sVRParent;
29 }
30
Init(int aArgc,char * aArgv[])31 bool VRProcessChild::Init(int aArgc, char* aArgv[]) {
32 char* parentBuildID = nullptr;
33 char* prefsHandle = nullptr;
34 char* prefMapHandle = nullptr;
35 char* prefsLen = nullptr;
36 char* prefMapSize = nullptr;
37 for (int i = 1; i < aArgc; i++) {
38 if (!aArgv[i]) {
39 continue;
40 }
41 if (strcmp(aArgv[i], "-parentBuildID") == 0) {
42 parentBuildID = aArgv[i + 1];
43
44 #ifdef XP_WIN
45 } else if (strcmp(aArgv[i], "-prefsHandle") == 0) {
46 if (++i == aArgc) {
47 return false;
48 }
49 prefsHandle = aArgv[i];
50 } else if (strcmp(aArgv[i], "-prefMapHandle") == 0) {
51 if (++i == aArgc) {
52 return false;
53 }
54 prefMapHandle = aArgv[i];
55 #endif
56 } else if (strcmp(aArgv[i], "-prefsLen") == 0) {
57 if (++i == aArgc) {
58 return false;
59 }
60 prefsLen = aArgv[i];
61 } else if (strcmp(aArgv[i], "-prefMapSize") == 0) {
62 if (++i == aArgc) {
63 return false;
64 }
65 prefMapSize = aArgv[i];
66 }
67 }
68
69 ipc::SharedPreferenceDeserializer deserializer;
70 if (!deserializer.DeserializeFromSharedMemory(prefsHandle, prefMapHandle,
71 prefsLen, prefMapSize)) {
72 return false;
73 }
74
75 sVRParent = new VRParent();
76 sVRParent->Init(ParentPid(), parentBuildID, IOThreadChild::TakeInitialPort());
77
78 return true;
79 }
80
CleanUp()81 void VRProcessChild::CleanUp() {
82 sVRParent = nullptr;
83 NS_ShutdownXPCOM(nullptr);
84 }
85