Bug 1726804 - Refactor definition and usage of GECKO_PROCESS_TYPE() r=nika,firefox-build-system-reviewers,mhentges
authorAlexandre Lissy <lissyx+mozillians@lissyx.dyndns.org>
Fri, 19 Nov 2021 14:02:55 +0000
changeset 599651 d76685524336cd96790c939eb7d30247bd577b4a
parent 599650 eaecfc3031dcda5a6d9569d816558b04e50b2d92
child 599652 beed6924c87aad0dcf39cfc62712da44bf3f5d22
push id38993
push userncsoregi@mozilla.com
push dateFri, 19 Nov 2021 21:29:37 +0000
treeherdermozilla-central@60627ac79469 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika, firefox-build-system-reviewers, mhentges
bugs1726804
milestone96.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1726804 - Refactor definition and usage of GECKO_PROCESS_TYPE() r=nika,firefox-build-system-reviewers,mhentges Differential Revision: https://phabricator.services.mozilla.com/D121388
build/common_virtualenv_packages.txt
dom/base/ChromeUtils.cpp
ipc/glue/CrashReporterHost.cpp
js/src/make-source-package.py
python/mozbuild/mozbuild/action/test_archive.py
testing/config/mozbase_requirements.txt
testing/config/mozbase_source_requirements.txt
testing/mozbase/mozleak/mozleak/leaklog.py
testing/tools/mach_test_package_initialize.py
toolkit/components/processtools/ProcInfo.h
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
xpcom/build/GeckoProcessTypes.h
xpcom/build/gen_process_types.py
xpcom/build/moz.build
xpcom/build/nsXULAppAPI.h
xpcom/geckoprocesstypes_generator/geckoprocesstypes/__init__.py
xpcom/geckoprocesstypes_generator/geckoprocesstypes/moz.build
xpcom/geckoprocesstypes_generator/setup.py
xpcom/moz.build
xpcom/system/nsIXULRuntime.idl
--- a/build/common_virtualenv_packages.txt
+++ b/build/common_virtualenv_packages.txt
@@ -119,9 +119,10 @@ vendored:third_party/python/voluptuous
 vendored:third_party/python/wheel
 vendored:third_party/python/yamllint
 vendored:third_party/python/yarl
 vendored:third_party/python/zipp
 pth:toolkit/components/telemetry/tests/marionette/harness
 pth:tools
 pth:tools/moztreedocs
 pth:xpcom/ds/tools
+pth:xpcom/geckoprocesstypes_generator
 pth:xpcom/idl-parser
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -859,27 +859,30 @@ static WebIDLProcType ProcTypeToWebIDL(m
     PROCTYPE_TO_WEBIDL_CASE(WebIsolated, WebIsolated);
     PROCTYPE_TO_WEBIDL_CASE(File, File);
     PROCTYPE_TO_WEBIDL_CASE(Extension, Extension);
     PROCTYPE_TO_WEBIDL_CASE(PrivilegedAbout, Privilegedabout);
     PROCTYPE_TO_WEBIDL_CASE(PrivilegedMozilla, Privilegedmozilla);
     PROCTYPE_TO_WEBIDL_CASE(WebCOOPCOEP, WithCoopCoep);
     PROCTYPE_TO_WEBIDL_CASE(WebServiceWorker, WebServiceWorker);
     PROCTYPE_TO_WEBIDL_CASE(WebLargeAllocation, WebLargeAllocation);
-    PROCTYPE_TO_WEBIDL_CASE(Browser, Browser);
-    PROCTYPE_TO_WEBIDL_CASE(IPDLUnitTest, IpdlUnitTest);
-    PROCTYPE_TO_WEBIDL_CASE(GMPlugin, GmpPlugin);
-    PROCTYPE_TO_WEBIDL_CASE(GPU, Gpu);
-    PROCTYPE_TO_WEBIDL_CASE(VR, Vr);
-    PROCTYPE_TO_WEBIDL_CASE(RDD, Rdd);
-    PROCTYPE_TO_WEBIDL_CASE(Socket, Socket);
-    PROCTYPE_TO_WEBIDL_CASE(RemoteSandboxBroker, RemoteSandboxBroker);
-#ifdef MOZ_ENABLE_FORKSERVER
-    PROCTYPE_TO_WEBIDL_CASE(ForkServer, ForkServer);
-#endif
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  PROCTYPE_TO_WEBIDL_CASE(procinfo_typename, webidl_typename);
+#define SKIP_PROCESS_TYPE_CONTENT
+#ifndef MOZ_ENABLE_FORKSERVER
+#  define SKIP_PROCESS_TYPE_FORKSERVER
+#endif  // MOZ_ENABLE_FORKSERVER
+#include "mozilla/GeckoProcessTypes.h"
+#undef SKIP_PROCESS_TYPE_CONTENT
+#ifndef MOZ_ENABLE_FORKSERVER
+#  undef SKIP_PROCESS_TYPE_FORKSERVER
+#endif  // MOZ_ENABLE_FORKSERVER
+#undef GECKO_PROCESS_TYPE
     PROCTYPE_TO_WEBIDL_CASE(Preallocated, Preallocated);
     PROCTYPE_TO_WEBIDL_CASE(Unknown, Unknown);
   }
 
   MOZ_ASSERT(false, "Unhandled case in ProcTypeToWebIDL");
   return WebIDLProcType::Unknown;
 }
 
@@ -940,46 +943,38 @@ already_AddRefed<Promise> ChromeUtils::R
         base::ProcessId childPid = base::GetProcId(handle);
         mozilla::ProcType type = mozilla::ProcType::Unknown;
 
         switch (aGeckoProcess->GetProcessType()) {
           case GeckoProcessType::GeckoProcessType_Content: {
             // These processes are handled separately.
             return;
           }
-          case GeckoProcessType::GeckoProcessType_Default:
-            type = mozilla::ProcType::Browser;
-            break;
-          case GeckoProcessType::GeckoProcessType_GMPlugin:
-            type = mozilla::ProcType::GMPlugin;
-            break;
-          case GeckoProcessType::GeckoProcessType_GPU:
-            type = mozilla::ProcType::GPU;
-            break;
-          case GeckoProcessType::GeckoProcessType_VR:
-            type = mozilla::ProcType::VR;
-            break;
-          case GeckoProcessType::GeckoProcessType_RDD:
-            type = mozilla::ProcType::RDD;
-            break;
-          case GeckoProcessType::GeckoProcessType_Socket:
-            type = mozilla::ProcType::Socket;
-            break;
-          case GeckoProcessType::GeckoProcessType_RemoteSandboxBroker:
-            type = mozilla::ProcType::RemoteSandboxBroker;
-            break;
-#ifdef MOZ_ENABLE_FORKSERVER
-          case GeckoProcessType::GeckoProcessType_ForkServer:
-            type = mozilla::ProcType::ForkServer;
-            break;
-#endif
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  case GeckoProcessType::GeckoProcessType_##enum_name: {                      \
+    type = mozilla::ProcType::procinfo_typename;                              \
+    break;                                                                    \
+  }
+#define SKIP_PROCESS_TYPE_CONTENT
+#ifndef MOZ_ENABLE_FORKSERVER
+#  define SKIP_PROCESS_TYPE_FORKSERVER
+#endif  // MOZ_ENABLE_FORKSERVER
+#include "mozilla/GeckoProcessTypes.h"
+#ifndef MOZ_ENABLE_FORKSERVER
+#  undef SKIP_PROCESS_TYPE_FORKSERVER
+#endif  // MOZ_ENABLE_FORKSERVER
+#undef SKIP_PROCESS_TYPE_CONTENT
+#undef GECKO_PROCESS_TYPE
           default:
             // Leave the default Unknown value in |type|.
             break;
         }
+
         requests.EmplaceBack(
             /* aPid = */ childPid,
             /* aProcessType = */ type,
             /* aOrigin = */ ""_ns,
             /* aWindowInfo = */ nsTArray<WindowInfo>(),  // Without a
                                                          // ContentProcess, no
                                                          // DOM windows.
             /* aChild = */ 0  // Without a ContentProcess, no ChildId.
--- a/ipc/glue/CrashReporterHost.cpp
+++ b/ipc/glue/CrashReporterHost.cpp
@@ -135,20 +135,21 @@ void CrashReporterHost::RecordCrash(Geck
 }
 
 /* static */
 void CrashReporterHost::RecordCrashWithTelemetry(GeckoProcessType aProcessType,
                                                  int32_t aCrashType) {
   nsCString key;
 
   switch (aProcessType) {
-#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, xre_name, \
-                           bin_type)                                     \
-  case GeckoProcessType_##enum_name:                                     \
-    key.AssignLiteral(string_name);                                      \
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  case GeckoProcessType_##enum_name:                                          \
+    key.AssignLiteral(string_name);                                           \
     break;
 #include "mozilla/GeckoProcessTypes.h"
 #undef GECKO_PROCESS_TYPE
     // We can't really hit this, thanks to the above switch, but having it
     // here will placate the compiler.
     default:
       MOZ_ASSERT_UNREACHABLE("unknown process type");
   }
--- a/js/src/make-source-package.py
+++ b/js/src/make-source-package.py
@@ -192,16 +192,18 @@ rsync_filter_list = """
 + /testing/web-platform/mozilla/**
 + /testing/web-platform/tests/resources/**
 + /testing/web-platform/tests/streams/**
 + /testing/web-platform/tests/tools/**
 
 + /toolkit/crashreporter/tools/symbolstore.py
 + /toolkit/mozapps/installer/package-name.mk
 
++ /xpcom/geckoprocesstypes_generator/**
+
 # SpiderMonkey itself
 
 + /js/src/**
 + /js/app.mozbuild
 + /js/*.configure
 + /js/examples/**
 + /js/public/**
 
--- a/python/mozbuild/mozbuild/action/test_archive.py
+++ b/python/mozbuild/mozbuild/action/test_archive.py
@@ -161,16 +161,22 @@ ARCHIVE_FILES = {
         {
             "source": buildconfig.topsrcdir,
             "base": "python/mozterm",
             "pattern": "**",
             "dest": "tools/mozterm",
         },
         {
             "source": buildconfig.topsrcdir,
+            "base": "xpcom/geckoprocesstypes_generator",
+            "pattern": "**",
+            "dest": "tools/geckoprocesstypes_generator",
+        },
+        {
+            "source": buildconfig.topsrcdir,
             "base": "third_party/python/six",
             "pattern": "**",
             "dest": "tools/six",
         },
         {
             "source": buildconfig.topsrcdir,
             "base": "third_party/python/distro",
             "pattern": "**",
--- a/testing/config/mozbase_requirements.txt
+++ b/testing/config/mozbase_requirements.txt
@@ -1,9 +1,10 @@
 ../tools/mozterm
+../tools/geckoprocesstypes_generator
 
 ../mozbase/manifestparser
 ../mozbase/mozcrash
 ../mozbase/mozdebug
 ../mozbase/mozdevice
 ../mozbase/mozfile
 ../mozbase/mozgeckoprofiler
 ../mozbase/mozhttpd
--- a/testing/config/mozbase_source_requirements.txt
+++ b/testing/config/mozbase_source_requirements.txt
@@ -1,9 +1,10 @@
 --editable ../../python/mozterm
+--editable ../../xpcom/geckoprocesstypes_generator
 
 --editable ../mozbase/manifestparser
 --editable ../mozbase/mozcrash
 --editable ../mozbase/mozdebug
 --editable ../mozbase/mozdevice
 --editable ../mozbase/mozfile
 --editable ../mozbase/mozgeckoprofiler
 --editable ../mozbase/mozhttpd
--- a/testing/mozbase/mozleak/mozleak/leaklog.py
+++ b/testing/mozbase/mozleak/mozleak/leaklog.py
@@ -2,16 +2,18 @@
 # 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/.
 
 from __future__ import absolute_import
 
 import os
 import re
 
+from geckoprocesstypes import process_types
+
 
 def _get_default_logger():
     from mozlog import get_default_logger
 
     log = get_default_logger(component="mozleak")
 
     if not log:
         import logging
@@ -178,26 +180,19 @@ def process_leak_log(
         % (leakLogFile, (" for scope %s" % scope) if scope is not None else "")
     )
 
     leakThresholds = leak_thresholds or {}
     ignoreMissingLeaks = ignore_missing_leaks or []
 
     # This list is based on XRE_GeckoProcessTypeToString. ipdlunittest processes likely
     # are not going to produce leak logs we will ever see.
+
     knownProcessTypes = [
-        "default",
-        "forkserver",
-        "gmplugin",
-        "gpu",
-        "plugin",
-        "rdd",
-        "socket",
-        "tab",
-        "vr",
+        p.string_name for p in process_types if p.string_name != "ipdlunittest"
     ]
 
     for processType in knownProcessTypes:
         log.info(
             "TEST-INFO | leakcheck | %s process: leak threshold set at %d bytes"
             % (processType, leakThresholds.get(processType, 0))
         )
 
--- a/testing/tools/mach_test_package_initialize.py
+++ b/testing/tools/mach_test_package_initialize.py
@@ -33,16 +33,17 @@ SEARCH_PATHS = [
     "mozbase/mozrunner",
     "mozbase/mozscreenshot",
     "mozbase/mozsystemmonitor",
     "mozbase/moztest",
     "mozbase/mozversion",
     "reftest",
     "tools/mach",
     "tools/mozterm",
+    "tools/geckoprocesstypes_generator",
     "tools/six",
     "tools/wptserve",
     "web-platform",
     "web-platform/tests/tools/wptrunner",
     "xpcshell",
 ]
 
 # Individual files providing mach commands.
--- a/toolkit/components/processtools/ProcInfo.h
+++ b/toolkit/components/processtools/ProcInfo.h
@@ -36,28 +36,31 @@ enum class ProcType {
   WebIsolated,
   File,
   Extension,
   PrivilegedAbout,
   PrivilegedMozilla,
   WebLargeAllocation,
   WebCOOPCOEP,
   WebServiceWorker,
-  // the rest matches GeckoProcessTypes.h
-  Browser,  // Default is named Browser here
-  IPDLUnitTest,
-  GMPlugin,
-  GPU,
-  VR,
-  RDD,
-  Socket,
-  RemoteSandboxBroker,
-#ifdef MOZ_ENABLE_FORKSERVER
-  ForkServer,
-#endif
+// the rest matches GeckoProcessTypes.h
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  procinfo_typename,
+#define SKIP_PROCESS_TYPE_CONTENT
+#ifndef MOZ_ENABLE_FORKSERVER
+#  define SKIP_PROCESS_TYPE_FORKSERVER
+#endif  // MOZ_ENABLE_FORKSERVER
+#include "mozilla/GeckoProcessTypes.h"
+#undef SKIP_PROCESS_TYPE_CONTENT
+#ifndef MOZ_ENABLE_FORKSERVER
+#  undef SKIP_PROCESS_TYPE_FORKSERVER
+#endif  // MOZ_ENABLE_FORKSERVER
+#undef GECKO_PROCESS_TYPE
   Preallocated,
   // Unknown type of process
   Unknown,
   Max = Unknown,
 };
 
 struct ThreadInfo {
   // Thread Id.
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -968,32 +968,25 @@ NS_IMETHODIMP
 nsXULAppInfo::GetWidgetToolkit(nsACString& aResult) {
   aResult.AssignLiteral(MOZ_WIDGET_TOOLKIT);
   return NS_OK;
 }
 
 // Ensure that the GeckoProcessType enum, defined in xpcom/build/nsXULAppAPI.h,
 // is synchronized with the const unsigned longs defined in
 // xpcom/system/nsIXULRuntime.idl.
-#define SYNC_ENUMS(a, b)                                                   \
-  static_assert(nsIXULRuntime::PROCESS_TYPE_##a ==                         \
-                    static_cast<int>(GeckoProcessType_##b),                \
-                "GeckoProcessType in nsXULAppAPI.h not synchronized with " \
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  static_assert(nsIXULRuntime::PROCESS_TYPE_##allcaps_name ==                 \
+                    static_cast<int>(GeckoProcessType_##enum_name),           \
+                "GeckoProcessType in nsXULAppAPI.h not synchronized with "    \
                 "nsIXULRuntime.idl");
-
-SYNC_ENUMS(DEFAULT, Default)
-SYNC_ENUMS(CONTENT, Content)
-SYNC_ENUMS(IPDLUNITTEST, IPDLUnitTest)
-SYNC_ENUMS(GMPLUGIN, GMPlugin)
-SYNC_ENUMS(GPU, GPU)
-SYNC_ENUMS(VR, VR)
-SYNC_ENUMS(RDD, RDD)
-SYNC_ENUMS(SOCKET, Socket)
-SYNC_ENUMS(SANDBOX_BROKER, RemoteSandboxBroker)
-SYNC_ENUMS(FORKSERVER, ForkServer)
+#include "mozilla/GeckoProcessTypes.h"
+#undef GECKO_PROCESS_TYPE
 
 // .. and ensure that that is all of them:
 static_assert(GeckoProcessType_ForkServer + 1 == GeckoProcessType_End,
               "Did not find the final GeckoProcessType");
 
 NS_IMETHODIMP
 nsXULAppInfo::GetProcessType(uint32_t* aResult) {
   NS_ENSURE_ARG_POINTER(aResult);
@@ -5625,20 +5618,21 @@ bool XRE_IsE10sParentProcess() {
 #ifdef MOZ_WIDGET_ANDROID
   return XRE_IsParentProcess() && BrowserTabsRemoteAutostart() &&
          mozilla::jni::IsAvailable();
 #else
   return XRE_IsParentProcess() && BrowserTabsRemoteAutostart();
 #endif
 }
 
-#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, xre_name, \
-                           bin_type)                                     \
-  bool XRE_Is##xre_name##Process() {                                     \
-    return XRE_GetProcessType() == GeckoProcessType_##enum_name;         \
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  bool XRE_Is##proc_typename##Process() {                                     \
+    return XRE_GetProcessType() == GeckoProcessType_##enum_name;              \
   }
 #include "mozilla/GeckoProcessTypes.h"
 #undef GECKO_PROCESS_TYPE
 
 bool XRE_UseNativeEventProcessing() {
 #if defined(XP_MACOSX) || defined(XP_WIN)
   if (XRE_IsRDDProcess() || XRE_IsSocketProcess()) {
     return false;
@@ -5733,20 +5727,21 @@ mozilla::BinPathType XRE_GetChildProcBin
     GeckoProcessType aProcessType) {
   MOZ_ASSERT(aProcessType != GeckoProcessType_Default);
 
   if (!gRunSelfAsContentProc) {
     return BinPathType::PluginContainer;
   }
 
   switch (aProcessType) {
-#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, xre_name, \
-                           bin_type)                                     \
-  case GeckoProcessType_##enum_name:                                     \
-    return BinPathType::bin_type;
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  case GeckoProcessType_##enum_name:                                          \
+    return BinPathType::process_bin_type;
 #include "mozilla/GeckoProcessTypes.h"
 #undef GECKO_PROCESS_TYPE
     default:
       return BinPathType::PluginContainer;
   }
 }
 
 // From mozglue/static/rust/lib.rs
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -216,19 +216,20 @@ void XRE_TermEmbedding() {
 
   gDirServiceProvider->DoShutdown();
   NS_ShutdownXPCOM(nullptr);
   delete gDirServiceProvider;
 }
 
 const char* XRE_GeckoProcessTypeToString(GeckoProcessType aProcessType) {
   switch (aProcessType) {
-#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, xre_name, \
-                           bin_type)                                     \
-  case GeckoProcessType::GeckoProcessType_##enum_name:                   \
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  case GeckoProcessType::GeckoProcessType_##enum_name:                        \
     return string_name;
 #include "mozilla/GeckoProcessTypes.h"
 #undef GECKO_PROCESS_TYPE
     default:
       return "invalid";
   }
 }
 
deleted file mode 100644
--- a/xpcom/build/GeckoProcessTypes.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-// The entries in this file define support functions for each of the process
-// types present in Gecko.  The format is:
-//
-// GECKO_PROCESS_TYPE(enum-value, enum-name, string-name, proc-typename,
-// process-bin-type)
-//
-// enum-value: Unsigned int value the enum will use to identify the process
-// type.  This value must not be shared by different process types and should
-// never be changed since it is used e.g. in telemetry reporting.  These
-// values should be mirrored in nsIXULRuntime.idl.
-//
-// enum-name: used to name the GeckoChildProcess enum.  E.g. `Foo` will
-// become `GeckoChildProcess_Foo`.  The enum's value will be the enum-value
-// above.
-//
-// string-name: Human-readable name.  It is exposed to things like
-// telemetry and the crash reporter, so it should not be changed casually.
-//
-// proc-typename: Used as NAME in the `XRE_Is${NAME}Process` function.
-// Ideally, this should match the enum-name.  This is included since there
-// are legacy exceptions to that rule.
-//
-// process-bin-type: either Self or PluginContainer.  Determines
-// whether the child process may be started using the same binary as the parent
-// process, or whether to use plugin-container (Note that whether or not this
-// value is actually obeyed depends on platform and build configuration. Do not
-// use this value directly, but rather use XRE_GetChildProcBinPathType to
-// resolve this).
-
-GECKO_PROCESS_TYPE(0, Default, "default", Parent, Self)
-GECKO_PROCESS_TYPE(2, Content, "tab", Content, Self)
-GECKO_PROCESS_TYPE(3, IPDLUnitTest, "ipdlunittest", IPDLUnitTest,
-                   PluginContainer)
-// Gecko Media Plugin process.
-GECKO_PROCESS_TYPE(4, GMPlugin, "gmplugin", GMPlugin, PluginContainer)
-// GPU and compositor process.
-GECKO_PROCESS_TYPE(5, GPU, "gpu", GPU, Self)
-// VR process.
-GECKO_PROCESS_TYPE(6, VR, "vr", VR, Self)
-// Remote Data Decoder process.
-GECKO_PROCESS_TYPE(7, RDD, "rdd", RDD, Self)
-// Socket process
-GECKO_PROCESS_TYPE(8, Socket, "socket", Socket, Self)
-GECKO_PROCESS_TYPE(9, RemoteSandboxBroker, "sandboxbroker", RemoteSandboxBroker,
-                   PluginContainer)
-GECKO_PROCESS_TYPE(10, ForkServer, "forkserver", ForkServer, Self)
-
-// Please add new process types at the end of this list.  You will also need
-// to maintain consistency with:
-//
-// * toolkit/components/processtools/ProcInfo.h (ProcType),
-// * xpcom/system/nsIXULRuntime.idl (PROCESS_TYPE constants),
-// * toolkit/xre/nsAppRunner.cpp (SYNC_ENUMS),
-// * dom/base/ChromeUtils.cpp (ProcTypeToWebIDL and
-//   ChromeUtils::RequestProcInfo)
-// * dom/chrome-webidl/ChromeUtils.webidl (WebIDLProcType)
-// * toolkit/components/crashes/nsICrashService.idl and
-//   CrashService.jsm (PROCESS_TYPE constants)
-// * ipc/glue/CrashReporterHost.cpp (assertions)
-// * toolkit/locales/en-US/toolkit/global/processTypes.ftl and
-//   toolkit/modules/ProcessType.jsm
-//
-// Also, please ensure that any new sandbox environment variables are added
-// in build/pgo/profileserver.py to ensure your new process participates in
-// PGO profile generation.
new file mode 100644
--- /dev/null
+++ b/xpcom/build/gen_process_types.py
@@ -0,0 +1,34 @@
+# 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/.
+
+from geckoprocesstypes import process_types
+
+
+def main(output):
+    output.write(
+        """\
+/* THIS FILE IS GENERATED BY GeckoProcessTypes - DO NOT EDIT */
+"""
+    )
+
+    for p in process_types:
+        output.write(
+            """
+#ifndef SKIP_PROCESS_TYPE_%(allcaps_name)s
+GECKO_PROCESS_TYPE(%(enum_value)d, %(enum_name)s, "%(string_name)s", """
+            """%(proc_typename)s, %(process_bin_type)s, %(procinfo_typename)s, """
+            """%(webidl_typename)s, %(allcaps_name)s)
+#endif // SKIP_PROCESS_TYPE_%(allcaps_name)s
+"""
+            % {
+                "enum_value": p.enum_value,
+                "enum_name": p.enum_name,
+                "string_name": p.string_name,
+                "proc_typename": p.proc_typename,
+                "process_bin_type": p.process_bin_type,
+                "procinfo_typename": p.procinfo_typename,
+                "webidl_typename": p.webidl_typename,
+                "allcaps_name": p.allcaps_name,
+            }
+        )
--- a/xpcom/build/moz.build
+++ b/xpcom/build/moz.build
@@ -10,19 +10,19 @@ EXPORTS += [
     "nsXPCOMCIDInternal.h",
     "nsXULAppAPI.h",
     "XREChildData.h",
     "xrecore.h",
     "XREShellData.h",
 ]
 
 EXPORTS.mozilla += [
+    "!GeckoProcessTypes.h",
     "!Services.h",
     "FileLocation.h",
-    "GeckoProcessTypes.h",
     "IOInterposer.h",
     "LateWriteChecks.h",
     "Omnijar.h",
     "PoisonIOInterposer.h",
     "SmallArrayLRUCache.h",
     "XPCOM.h",
     "XREAppData.h",
 ]
@@ -70,16 +70,21 @@ SOURCES += ["!Services.cpp"]
 if CONFIG["OS_ARCH"] != "WINNT":
     SOURCES += [
         "NSPRInterposer.cpp",
     ]
 
 GeneratedFile("Services.cpp", script="Services.py", entry_point="services_cpp")
 GeneratedFile("Services.h", script="Services.py", entry_point="services_h")
 GeneratedFile("services.rs", script="Services.py", entry_point="services_rs")
+GeneratedFile(
+    "GeckoProcessTypes.h",
+    script="gen_process_types.py",
+    entry_point="main",
+)
 
 include("/ipc/chromium/chromium-config.mozbuild")
 
 FINAL_LIBRARY = "xul"
 
 DEFINES["_IMPL_NS_STRINGAPI"] = True
 DEFINES["OMNIJAR_NAME"] = CONFIG["OMNIJAR_NAME"]
 
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -355,18 +355,19 @@ XRE_API(void, XRE_TermEmbedding, ())
  * @param aINIFile The INI file to parse
  * @param aAppData The nsXREAppData structure to fill.
  */
 XRE_API(nsresult, XRE_ParseAppData,
         (nsIFile * aINIFile, mozilla::XREAppData& aAppData))
 
 // This enum is not dense.  See GeckoProcessTypes.h for details.
 enum GeckoProcessType {
-#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, xre_name, \
-                           bin_type)                                     \
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
   GeckoProcessType_##enum_name = enum_value,
 #include "mozilla/GeckoProcessTypes.h"
 #undef GECKO_PROCESS_TYPE
   GeckoProcessType_End,
   GeckoProcessType_Invalid = GeckoProcessType_End
 };
 
 XRE_API(const char*, XRE_GeckoProcessTypeToString,
@@ -411,19 +412,20 @@ XRE_API(bool, XRE_IsE10sParentProcess, (
 
 /**
  * Defines XRE_IsParentProcess, XRE_IsContentProcess, etc.
  *
  * XRE_IsParentProcess is unique in that it returns true when called in
  * the e10s parent process or called in the main process when e10s is
  * disabled.
  */
-#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, xre_name, \
-                           bin_type)                                     \
-  XRE_API(bool, XRE_Is##xre_name##Process, ())
+#define GECKO_PROCESS_TYPE(enum_value, enum_name, string_name, proc_typename, \
+                           process_bin_type, procinfo_typename,               \
+                           webidl_typename, allcaps_name)                     \
+  XRE_API(bool, XRE_Is##proc_typename##Process, ())
 #include "mozilla/GeckoProcessTypes.h"
 #undef GECKO_PROCESS_TYPE
 
 XRE_API(bool, XRE_IsSocketProcess, ())
 
 /**
  * Returns true if the appshell should run its own native event loop. Returns
  * false if we should rely solely on the Gecko event loop.
new file mode 100644
--- /dev/null
+++ b/xpcom/geckoprocesstypes_generator/geckoprocesstypes/__init__.py
@@ -0,0 +1,311 @@
+# 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/.
+
+from collections import namedtuple
+
+# Besides adding a new process type to this file, a bit of extra work is
+# required for places where generated code has not yet been implemented.
+# TODO: Bug 1740268: Move this piece into doc and link doc from here.
+#
+# Basic requirements:
+#  dom/chrome-webidl/ChromeUtils.webidl
+#   - Add a new entry to the enum WebIDLProcType
+#
+#  gfx/thebes/gfxPlatform.cpp
+#   - (if you need GFX related stuff ?)
+#   - Add a call to your process manager init in gfxPlatform::Init()
+#   - Add a call to your process manager shutdown in gfxPlatform::Shutdown()
+#
+#  mobile/android/geckoview/src/main/AndroidManifest.xml
+#   - Add a new <service> entry targetting
+#     org.mozilla.gecko.process.GeckoChildProcessServices$XXX
+#
+#  mobile/android/geckoview/src/main/java/org/mozilla/gecko/process/GeckoChildProcessServices.jinja
+#   - Add matching class inheritance from GeckoChildProcessServices
+#
+#  mobile/android/geckoview/src/main/java/org/mozilla/gecko/process/GeckoProcessType.java
+#   - Add new entry in public enum GeckoProcessType
+#
+#  toolkit/crashreporter/CrashAnnotations.yaml
+#   - Add new Xxx*Status entry for your new process type description
+#
+#  toolkit/locales/en-US/toolkit/global/processTypes.ftl
+#   - Add a user-facing localizable name for your process, if needed
+#
+#  toolkit/modules/ProcessType.jsm
+#   - Hashmap from process type to user-facing string above in const ProcessType
+#
+#  toolkit/xre/nsAppRunner.cpp
+#   - Update the static_assert call checking for boundary against
+#     GeckoProcessType_End
+#
+#  toolkit/xre/nsEmbedFunctions.cpp
+#   - Add your process to the correct MessageLoop::TYPE_x in the first
+#     switch(XRE_GetProcessType()) in XRE_InitChildProcess
+#   - Instantiate your child within the second switch (XRE_GetProcessType())
+#     in XRE_InitChildProcess
+#
+#  xpcom/system/nsIXULRuntime.idl
+#   - Add a new entry PROCESS_TYPE_x in nsIXULRuntime interface
+#
+#
+# For static components:
+#  modules/libpref/components.conf
+#  toolkit/components/telemetry/core/components.conf
+#  widget/android/components.conf
+#  widget/gtk/components.conf
+#  widget/windows/components.conf
+#  xpcom/base/components.conf
+#  xpcom/build/components.conf
+#  xpcom/components/components.conf
+#  xpcom/ds/components.conf
+#  xpcom/threads/components.conf
+#  widget/cocoa/nsWidgetFactory.mm
+#  xpcom/build/XPCOMInit.cpp
+#   - Update allowance in those config file to match new process selector
+#     including your new process
+#
+#  xpcom/components/gen_static_components.py
+#   - Add new definition in ProcessSelector for your new process
+#     ALLOW_IN_x_PROCESS = 0x..
+#   - Add new process selector masks including your new process definition
+#   - Also add those into the PROCESSES structure
+#
+#  xpcom/components/Module.h
+#   - Add new definition in enum ProcessSelector
+#   - Add new process selector mask including the new definition
+#   - Update kMaxProcessSelector
+#
+#  xpcom/components/nsComponentManager.cpp
+#   - Add new selector match in ProcessSelectorMatches for your new process
+#     (needed?)
+#   - Add new process selector for gProcessMatchTable
+#     in nsComponentManagerImpl::Init()
+#  xpcom/build/XPCOMInit.cpp
+#
+#
+# For sandbox:
+#  Sandbox Linux:
+#   security/sandbox/linux/Sandbox.cpp
+#    - Add new SetXXXSandbox() function
+#   security/sandbox/linux/SandboxFilter.cpp
+#    - Add new helper GetXXXSandboxPolicy() called by SetXXXSandbox()
+#    - Derive new class inheriting SandboxPolicyCommon or SandboxPolicyBase and
+#      defining the sandboxing policy
+#   security/sandbox/linux/broker/SandboxBrokerPolicyFactory.cpp
+#    - Add new SandboxBrokerPolicyFactory::GetXXXProcessPolicy()
+#   security/sandbox/linux/launch/SandboxLaunch.cpp
+#    - Add new case handling in GetEffectiveSandboxLevel()
+#   security/sandbox/linux/reporter/SandboxReporter.cpp
+#    - Add new case handling in SubmitToTelemetry()
+#   security/sandbox/linux/reporter/SandboxReporterCommon.h
+#    - Add new entry in enum class ProcType
+#   security/sandbox/linux/reporter/SandboxReporterWrappers.cpp
+#    - Add new case handling in SandboxReportWrapper::GetProcType()
+#
+#  Sandbox Mac:
+#   ipc/glue/GeckoChildProcessHost.cpp
+#    - Add new case handling in GeckoChildProcessHost::StartMacSandbox()
+#   security/sandbox/mac/Sandbox.h
+#    - Add new entry in enum MacSandboxType
+#   security/sandbox/mac/Sandbox.mm
+#    - Handle the new MacSandboxType in MacSandboxInfo::AppendAsParams()
+#    - Handle the new MacSandboxType in StartMacSandbox()
+#    - Handle the new MacSandboxType in StartMacSandboxIfEnabled()
+#   security/sandbox/mac/SandboxPolicy<XXX>.h
+#    - Create this new file for your new process <XXX>, it defines the new
+#      sandbox
+#   security/sandbox/mac/moz.build
+#    - Add the previous new file
+#
+#  Sandbox Win:
+#   ipc/glue/GeckoChildProcessHost.cpp
+#    - Add new case handling in WindowsProcessLauncher::DoSetup() calling
+#      SandboxBroker::SetSecurityLevelForXXXProcess()
+#   security/sandbox/win/src/remotesandboxbroker/remoteSandboxBroker.cpp
+#    - Introduce a new SandboxBroker::SetSecurityLevelForXXXProcess()
+#   security/sandbox/win/src/sandboxbroker/sandboxBroker.cpp
+#    - Introduce a new SandboxBroker::SetSecurityLevelForXXXProcess() that
+#      defines the new sandbox
+#
+#  Sandbox tests:
+#   - Your new process needs to implement PSandboxTesting.ipdl
+#   security/sandbox/test/browser_sandbox_test.js
+#    - Add your new process string_name in the processTypes list
+#   security/sandbox/common/test/SandboxTest.cpp
+#    - Add a new case in SandboxTest::StartTests() to handle your new process
+#   security/sandbox/common/test/SandboxTestingChild.cpp
+#    - Add a new if branch for your new process in SandboxTestingChild::Bind()
+#   security/sandbox/common/test/SandboxTestingChildTests.h
+#    - Add a new RunTestsXXX function for your new process (called by Bind() above)
+#
+# ~~~~~
+#
+# The entries in this file define support functions for each of the process
+# types present in Gecko.
+#
+# GECKO_PROCESS_TYPE(
+#   enum-value,
+#   enum-name,
+#   string-name,
+#   proc-typename,
+#   process-bin-type,
+#   procinfo-typename,
+#   webidl-typename,
+#   allcaps-name,
+# )
+#
+# enum-value:
+#   Unsigned int value the enum will use to identify the process type.  This
+#   value must not be shared by different process types and should never be
+#   changed since it is used e.g. in telemetry reporting.
+#
+#   ***These values should be mirrored in nsIXULRuntime.idl.***
+#
+# enum-name:
+#   Used to name the GeckoChildProcess enum.  E.g. `Foo` will become
+#   `GeckoChildProcess_Foo`.  The enum's value will be the enum-value above.
+#
+# string-name:
+#   Human-readable name.  It is exposed to things like telemetry and the crash
+#   reporter, so it should not be changed casually.
+#
+# proc-typename:
+#   Used as NAME in the `XRE_Is${NAME}Process` function.  Ideally, this should
+#   match the enum-name.  This is included since there are legacy exceptions to
+#   that rule.
+#
+# process-bin-type:
+#   Either Self or PluginContainer.  Determines whether the child process may
+#   be started using the same binary as the parent process, or whether to use
+#   plugin-container (Note that whether or not this value is actually obeyed
+#   depends on platform and build configuration. Do not use this value
+#   directly, but rather use XRE_GetChildProcBinPathType to resolve this).
+#
+# procinfo-typename:
+#   Used as NAME in the ProcType enum defined by ProcInfo.h.
+#
+# webidl-typename:
+#   Used as NAME in the ChromeUtils.cpp code
+#
+# allcaps-name:
+#   Used as NAME for checking SYNC_ENUM in nsXULAppAPI.h
+
+
+GeckoProcessType = namedtuple(
+    "GeckoProcessType",
+    [
+        "enum_value",
+        "enum_name",
+        "string_name",
+        "proc_typename",
+        "process_bin_type",
+        "procinfo_typename",
+        "webidl_typename",
+        "allcaps_name",
+    ],
+)
+
+process_types = [
+    GeckoProcessType(
+        0,
+        "Default",
+        "default",
+        "Parent",
+        "Self",
+        "Browser",
+        "Browser",
+        "DEFAULT",
+    ),
+    GeckoProcessType(
+        2,
+        "Content",
+        "tab",
+        "Content",
+        "Self",
+        "Content",
+        "Content",
+        "CONTENT",
+    ),
+    GeckoProcessType(
+        3,
+        "IPDLUnitTest",
+        "ipdlunittest",
+        "IPDLUnitTest",
+        "PluginContainer",
+        "IPDLUnitTest",
+        "IpdlUnitTest",
+        "IPDLUNITTEST",
+    ),
+    GeckoProcessType(
+        4,
+        "GMPlugin",
+        "gmplugin",
+        "GMPlugin",
+        "PluginContainer",
+        "GMPlugin",
+        "GmpPlugin",
+        "GMPLUGIN",
+    ),
+    GeckoProcessType(
+        5,
+        "GPU",
+        "gpu",
+        "GPU",
+        "Self",
+        "GPU",
+        "Gpu",
+        "GPU",
+    ),
+    GeckoProcessType(
+        6,
+        "VR",
+        "vr",
+        "VR",
+        "Self",
+        "VR",
+        "Vr",
+        "VR",
+    ),
+    GeckoProcessType(
+        7,
+        "RDD",
+        "rdd",
+        "RDD",
+        "Self",
+        "RDD",
+        "Rdd",
+        "RDD",
+    ),
+    GeckoProcessType(
+        8,
+        "Socket",
+        "socket",
+        "Socket",
+        "Self",
+        "Socket",
+        "Socket",
+        "SOCKET",
+    ),
+    GeckoProcessType(
+        9,
+        "RemoteSandboxBroker",
+        "sandboxbroker",
+        "RemoteSandboxBroker",
+        "PluginContainer",
+        "RemoteSandboxBroker",
+        "RemoteSandboxBroker",
+        "REMOTESANDBOXBROKER",
+    ),
+    GeckoProcessType(
+        10,
+        "ForkServer",
+        "forkserver",
+        "ForkServer",
+        "Self",
+        "ForkServer",
+        "ForkServer",
+        "FORKSERVER",
+    ),
+]
new file mode 100644
--- /dev/null
+++ b/xpcom/geckoprocesstypes_generator/geckoprocesstypes/moz.build
@@ -0,0 +1,5 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
new file mode 100644
--- /dev/null
+++ b/xpcom/geckoprocesstypes_generator/setup.py
@@ -0,0 +1,18 @@
+# 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/.
+
+from setuptools import setup, find_packages
+
+
+setup(
+    name="geckoprocesstypes",
+    version="1.0",
+    description="Generator for GeckoProcessTypes related resources.",
+    author="Mozilla Foundation",
+    license="MPL 2.0",
+    packages=find_packages(),
+    install_requires=[],
+    entry_points={"console_scripts": ["GeckoProcessTypes.py = geckoprocesstypes:main"]},
+    keywords=["geckoprocesstypes"],
+)
--- a/xpcom/moz.build
+++ b/xpcom/moz.build
@@ -4,16 +4,17 @@
 # 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/.
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "XPCOM")
 
 DIRS += [
     "idl-parser/xpidl",
+    "geckoprocesstypes_generator/geckoprocesstypes",
 ]
 
 DIRS += [
     "string",
     "glue",
     "base",
     "ds",
     "io",
--- a/xpcom/system/nsIXULRuntime.idl
+++ b/xpcom/system/nsIXULRuntime.idl
@@ -183,17 +183,17 @@ interface nsIXULRuntime : nsISupports
   const unsigned long PROCESS_TYPE_DEFAULT = 0;
   const unsigned long PROCESS_TYPE_CONTENT = 2;
   const unsigned long PROCESS_TYPE_IPDLUNITTEST = 3;
   const unsigned long PROCESS_TYPE_GMPLUGIN = 4;
   const unsigned long PROCESS_TYPE_GPU = 5;
   const unsigned long PROCESS_TYPE_VR = 6;
   const unsigned long PROCESS_TYPE_RDD = 7;
   const unsigned long PROCESS_TYPE_SOCKET = 8;
-  const unsigned long PROCESS_TYPE_SANDBOX_BROKER = 9;
+  const unsigned long PROCESS_TYPE_REMOTESANDBOXBROKER = 9;
   const unsigned long PROCESS_TYPE_FORKSERVER = 10;
 
   /**
    * The type of the caller's process.  Returns one of the values above.
    */
   readonly attribute unsigned long processType;
 
   /**