Bug 1647759 - P3: Send init attributes to socket process r=dragana

Depends on D82352

Differential Revision: https://phabricator.services.mozilla.com/D82353
This commit is contained in:
Kershaw Chang 2020-07-07 11:51:17 +00:00
Родитель 6cb09fb6f3
Коммит 9c8f0c8d00
4 изменённых файлов: 59 добавлений и 38 удалений

Просмотреть файл

@ -69,6 +69,12 @@ struct SocketDataArgs
SocketInfo[] info;
};
struct SocketPorcessInitAttributes {
bool mOffline;
bool mConnectivity;
FileDescriptor? mSandboxBroker;
};
sync protocol PSocketProcess
{
manages PDNSRequest;
@ -125,6 +131,7 @@ parent:
returns (bool aAccepted);
child:
async Init(SocketPorcessInitAttributes aAttributes);
async PreferenceUpdate(Pref pref);
async RequestMemoryReport(uint32_t generation,
bool anonymize,

Просмотреть файл

@ -187,6 +187,14 @@ void SocketProcessChild::CleanUp() {
NS_ShutdownXPCOM(nullptr);
}
mozilla::ipc::IPCResult SocketProcessChild::RecvInit(
const SocketPorcessInitAttributes& aAttributes) {
Unused << RecvSetOffline(aAttributes.mOffline());
Unused << RecvSetConnectivity(aAttributes.mConnectivity());
Unused << RecvInitLinuxSandbox(aAttributes.mSandboxBroker());
return IPC_OK();
}
IPCResult SocketProcessChild::RecvPreferenceUpdate(const Pref& aPref) {
Preferences::SetPreference(aPref);
return IPC_OK();

Просмотреть файл

@ -38,6 +38,8 @@ class SocketProcessChild final
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvInit(
const SocketPorcessInitAttributes& aAttributes);
mozilla::ipc::IPCResult RecvPreferenceUpdate(const Pref& aPref);
mozilla::ipc::IPCResult RecvRequestMemoryReport(
const uint32_t& generation, const bool& anonymize,

Просмотреть файл

@ -134,48 +134,52 @@ void SocketProcessHost::InitAfterConnect(bool aSucceeded) {
MOZ_ASSERT(NS_IsMainThread());
mLaunchPhase = LaunchPhase::Complete;
if (aSucceeded) {
mSocketProcessParent = MakeUnique<SocketProcessParent>(this);
DebugOnly<bool> rv = mSocketProcessParent->Open(
TakeChannel(), base::GetProcId(GetChildProcessHandle()));
MOZ_ASSERT(rv);
nsCOMPtr<nsIIOService> ioService(do_GetIOService());
MOZ_ASSERT(ioService, "No IO service?");
bool offline = false;
DebugOnly<nsresult> result = ioService->GetOffline(&offline);
MOZ_ASSERT(NS_SUCCEEDED(result), "Failed getting offline?");
Maybe<FileDescriptor> brokerFd;
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
if (GetEffectiveSocketProcessSandboxLevel() > 0) {
auto policy = SandboxBrokerPolicyFactory::GetSocketProcessPolicy(
GetActor()->OtherPid());
if (policy != nullptr) {
brokerFd = Some(FileDescriptor());
mSandboxBroker = SandboxBroker::Create(
std::move(policy), GetActor()->OtherPid(), brokerFd.ref());
// This is unlikely to fail and probably indicates OS resource
// exhaustion.
Unused << NS_WARN_IF(mSandboxBroker == nullptr);
MOZ_ASSERT(brokerFd.ref().IsValid());
}
Unused << GetActor()->SendInitLinuxSandbox(brokerFd);
if (!aSucceeded) {
if (mListener) {
mListener->OnProcessLaunchComplete(this, false);
}
#endif // XP_LINUX && MOZ_SANDBOX
#ifdef MOZ_GECKO_PROFILER
Unused << GetActor()->SendInitProfiler(
ProfilerParent::CreateForProcess(GetActor()->OtherPid()));
#endif
Unused << GetActor()->SendSetOffline(offline);
return;
}
mSocketProcessParent = MakeUnique<SocketProcessParent>(this);
DebugOnly<bool> rv = mSocketProcessParent->Open(
TakeChannel(), base::GetProcId(GetChildProcessHandle()));
MOZ_ASSERT(rv);
SocketPorcessInitAttributes attributes;
nsCOMPtr<nsIIOService> ioService(do_GetIOService());
MOZ_ASSERT(ioService, "No IO service?");
DebugOnly<nsresult> result = ioService->GetOffline(&attributes.mOffline());
MOZ_ASSERT(NS_SUCCEEDED(result), "Failed getting offline?");
result = ioService->GetConnectivity(&attributes.mConnectivity());
MOZ_ASSERT(NS_SUCCEEDED(result), "Failed getting connectivity?");
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
if (GetEffectiveSocketProcessSandboxLevel() > 0) {
auto policy = SandboxBrokerPolicyFactory::GetSocketProcessPolicy(
GetActor()->OtherPid());
if (policy != nullptr) {
attributes.mSandboxBroker() = Some(FileDescriptor());
mSandboxBroker =
SandboxBroker::Create(std::move(policy), GetActor()->OtherPid(),
attributes.mSandboxBroker().ref());
// This is unlikely to fail and probably indicates OS resource
// exhaustion.
Unused << NS_WARN_IF(mSandboxBroker == nullptr);
MOZ_ASSERT(attributes.mSandboxBroker().ref().IsValid());
}
}
#endif // XP_LINUX && MOZ_SANDBOX
Unused << GetActor()->SendInit(attributes);
#ifdef MOZ_GECKO_PROFILER
Unused << GetActor()->SendInitProfiler(
ProfilerParent::CreateForProcess(GetActor()->OtherPid()));
#endif
if (mListener) {
mListener->OnProcessLaunchComplete(this, aSucceeded);
mListener->OnProcessLaunchComplete(this, true);
}
}