Bug 1635255 - Flesh out FOG IPC one additional layer r=janerik

Introducing FOGIPC, the central clearinghouse for the C++ layer between
PContent and FOG's Rust impl.

Gotta add tests.

Differential Revision: https://phabricator.services.mozilla.com/D79742
This commit is contained in:
Chris H-C 2020-06-23 21:20:12 +00:00
Родитель 48dd24675c
Коммит b876426809
5 изменённых файлов: 161 добавлений и 1 удалений

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

@ -19,6 +19,7 @@
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/BenchmarkStorageChild.h"
#include "mozilla/ContentBlocking.h"
#include "mozilla/FOGIPC.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/MemoryTelemetry.h"
#include "mozilla/NullPrincipal.h"
@ -4236,6 +4237,7 @@ already_AddRefed<mozilla::dom::JSProcessActorChild> ContentChild::GetActor(
}
IPCResult ContentChild::RecvFlushFOGData(FlushFOGDataResolver&& aResolver) {
glean::FlushFOGData(std::move(aResolver));
return IPC_OK();
}

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

@ -52,6 +52,7 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Components.h"
#include "mozilla/DataStorage.h"
#include "mozilla/FOGIPC.h"
#include "mozilla/GlobalStyleSheetCache.h"
#include "mozilla/HangDetails.h"
#include "mozilla/LoginReputationIPC.h"
@ -6902,7 +6903,10 @@ NS_IMETHODIMP ContentParent::GetActor(const nsACString& aName,
return NS_OK;
}
IPCResult ContentParent::RecvFOGData(ByteBuf&& buf) { return IPC_OK(); }
IPCResult ContentParent::RecvFOGData(ByteBuf&& buf) {
glean::FOGData(std::move(buf));
return IPC_OK();
}
} // namespace dom
} // namespace mozilla

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

@ -0,0 +1,85 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* 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 "FOGIPC.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/MozPromise.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
using mozilla::dom::ContentParent;
using FlushFOGDataPromise = mozilla::dom::ContentParent::FlushFOGDataPromise;
namespace mozilla {
namespace glean {
/**
* The parent process is asking you to flush your data ASAP.
*
* @param aResolver - The function you need to call with the bincoded,
* serialized payload that the Rust impl hands you.
*/
void FlushFOGData(std::function<void(ipc::ByteBuf&&)>&& aResolver) {}
/**
* Called by FOG on the parent process when it wants to flush all its
* children's data.
* @param aResolver - The function that'll be called with the results.
*/
void FlushAllChildData(
std::function<void(const nsTArray<ipc::ByteBuf>&&)>&& aResolver) {
nsTArray<ContentParent*> parents;
ContentParent::GetAll(parents);
if (parents.Length() == 0) {
nsTArray<ipc::ByteBuf> results;
aResolver(std::move(results));
return;
}
nsTArray<RefPtr<FlushFOGDataPromise>> promises;
for (auto parent : parents) {
promises.EmplaceBack(parent->SendFlushFOGData());
}
// TODO: Don't throw away resolved data if some of the promises reject.
// (not sure how, but it'll mean not using ::All... maybe a custom copy of
// AllPromiseHolder? Might be impossible outside MozPromise.h)
FlushFOGDataPromise::All(GetCurrentThreadSerialEventTarget(), promises)
->Then(GetCurrentThreadSerialEventTarget(), __func__,
[&aResolver](
FlushFOGDataPromise::AllPromiseType::ResolveOrRejectValue&&
aValue) {
if (aValue.IsResolve()) {
aResolver(std::move(aValue.ResolveValue()));
} else {
nsTArray<ipc::ByteBuf> results;
aResolver(std::move(results));
}
});
}
/**
* A child process has sent you this buf as a treat.
* @param buf - a bincoded serialized payload that the Rust impl understands.
*/
void FOGData(ipc::ByteBuf&& buf) {}
/**
* Called by FOG on a child process when it wants to send a buf to the parent.
* @param buf - a bincoded serialized payload that the Rust impl understands.
*/
void SendFOGData(ipc::ByteBuf&& buf) {
switch (XRE_GetProcessType()) {
case GeckoProcessType_Content:
mozilla::dom::ContentChild::GetSingleton()->SendFOGData(std::move(buf));
break;
default:
MOZ_ASSERT_UNREACHABLE("Unsuppored process type");
}
}
} // namespace glean
} // namespace mozilla

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

@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* 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/. */
#ifndef FOGIPC_h__
#define FOGIPC_h__
#include <functional>
#include "mozilla/Maybe.h"
#include "nsTArrayForwardDeclare.h"
namespace mozilla {
namespace ipc {
class ByteBuf;
} // namespace ipc
} // namespace mozilla
// This module provides the interface for FOG to communicate between processes.
namespace mozilla {
namespace glean {
/**
* The parent process is asking you to flush your data ASAP.
*
* @param aResolver - The function you need to call with the bincoded,
* serialized payload that the Rust impl hands you.
*/
void FlushFOGData(std::function<void(ipc::ByteBuf&&)>&& aResolver);
/**
* Called by FOG on the parent process when it wants to flush all its
* children's data.
* @param aResolver - The function that'll be called with the results.
*/
void FlushAllChildData(
std::function<void(const nsTArray<ipc::ByteBuf>&&)>&& aResolver);
/**
* A child process has sent you this buf as a treat.
* @param buf - a bincoded serialized payload that the Rust impl understands.
*/
void FOGData(ipc::ByteBuf&& buf);
/**
* Called by FOG on a child process when it wants to send a buf to the parent.
* @param buf - a bincoded serialized payload that the Rust impl understands.
*/
void SendFOGData(ipc::ByteBuf&& buf);
} // namespace glean
} // namespace mozilla
#endif // FOGIPC_h__

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

@ -6,6 +6,19 @@
SPHINX_TREES['/toolkit/components/glean'] = 'docs'
# Needed so that we can include IPC things.
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
EXPORTS.mozilla += [
'ipc/FOGIPC.h',
]
UNIFIED_SOURCES += [
'ipc/FOGIPC.cpp',
]
TEST_DIRS += [
'gtest',
]