Bug 1514044 - part 1 - macro-ify process enums, strings, and XRE functions; r=mccr8
authorNathan Froyd <froydnj@mozilla.com>
Thu, 10 Jan 2019 10:52:51 -0500
changeset 510371 1abd03bcbfa3520c8c0263606c792183ddaa073d
parent 510370 6d7562d605900b71a5553e368ababe8abb0b7d43
child 510372 65f14286370124a5dd07b810c1bb967cf3b181f1
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1514044
milestone66.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 1514044 - part 1 - macro-ify process enums, strings, and XRE functions; r=mccr8 Having this information all defined in a single header will make life easier if we ever add new process types.
toolkit/xre/nsAppRunner.cpp
xpcom/build/GeckoProcessTypes.h
xpcom/build/moz.build
xpcom/build/nsXULAppAPI.h
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -4922,41 +4922,26 @@ nsresult XRE_DeinitCommandLine() {
 
   return rv;
 }
 
 GeckoProcessType XRE_GetProcessType() {
   return mozilla::startup::sChildProcessType;
 }
 
-bool XRE_IsGPUProcess() { return XRE_GetProcessType() == GeckoProcessType_GPU; }
-
-bool XRE_IsRDDProcess() { return XRE_GetProcessType() == GeckoProcessType_RDD; }
-
-bool XRE_IsVRProcess() { return XRE_GetProcessType() == GeckoProcessType_VR; }
-
-/**
- * Returns true in the e10s parent process and in the main process when e10s
- * is disabled.
- */
-bool XRE_IsParentProcess() {
-  return XRE_GetProcessType() == GeckoProcessType_Default;
-}
-
 bool XRE_IsE10sParentProcess() {
   return XRE_IsParentProcess() && BrowserTabsRemoteAutostart();
 }
 
-bool XRE_IsContentProcess() {
-  return XRE_GetProcessType() == GeckoProcessType_Content;
-}
-
-bool XRE_IsPluginProcess() {
-  return XRE_GetProcessType() == GeckoProcessType_Plugin;
-}
+#define GECKO_PROCESS_TYPE(enum_name, string_name, xre_name)     \
+  bool XRE_Is##xre_name##Process() {                             \
+    return XRE_GetProcessType() == GeckoProcessType_##enum_name; \
+  }
+#include "mozilla/GeckoProcessTypes.h"
+#undef GECKO_PROCESS_TYPE
 
 bool XRE_UseNativeEventProcessing() {
 #ifdef XP_MACOSX
   if (XRE_IsRDDProcess()) {
     return false;
   }
 #endif
   if (XRE_IsContentProcess()) {
new file mode 100644
--- /dev/null
+++ b/xpcom/build/GeckoProcessTypes.h
@@ -0,0 +1,28 @@
+/* -*- 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/. */
+
+// GECKO_PROCESS_TYPE(enum-name, string-name, XRE_Is${NAME}Process)
+// Note that string-name is exposed to various things like telemetry
+// and the crash reporter, so it should not be changed casually.
+//
+// The values generated for the GeckoProcessType enum are dependent on
+// the ordering of the GECKO_PROCESS_TYPE invocations in this file, and
+// said values are exposed to things like telemetry as well, so please
+// do not reorder lines in this file.
+//
+// Please add new process types at the end of this list.
+GECKO_PROCESS_TYPE(Default, "default", Parent)
+GECKO_PROCESS_TYPE(Plugin, "plugin", Plugin)
+GECKO_PROCESS_TYPE(Content, "tab", Content)
+GECKO_PROCESS_TYPE(IPDLUnitTest, "ipdlunittest", IPDLUnitTest)
+// Gecko Media Plugin process.
+GECKO_PROCESS_TYPE(GMPlugin, "gmplugin", GMPlugin)
+// GPU and compositor process.
+GECKO_PROCESS_TYPE(GPU, "gpu", GPU)
+// VR process.
+GECKO_PROCESS_TYPE(VR, "vr", VR)
+// Remote Data Decoder process.
+GECKO_PROCESS_TYPE(RDD, "rdd", RDD)
--- a/xpcom/build/moz.build
+++ b/xpcom/build/moz.build
@@ -12,16 +12,17 @@ EXPORTS += [
     'XREChildData.h',
     'xrecore.h',
     'XREShellData.h',
 ]
 
 EXPORTS.mozilla += [
     '!Services.h',
     'FileLocation.h',
+    'GeckoProcessTypes.h',
     'IOInterposer.h',
     'LateWriteChecks.h',
     'Omnijar.h',
     'PoisonIOInterposer.h',
     'XPCOM.h',
     'XREAppData.h',
 ]
 
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -360,35 +360,30 @@ 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))
 
 enum GeckoProcessType {
-  GeckoProcessType_Default = 0,
-
-  GeckoProcessType_Plugin,
-  GeckoProcessType_Content,
-
-  GeckoProcessType_IPDLUnitTest,
-
-  GeckoProcessType_GMPlugin,  // Gecko Media Plugin
-
-  GeckoProcessType_GPU,  // GPU and compositor process
-  GeckoProcessType_VR,   // VR process
-  GeckoProcessType_RDD,  // RDD (RemoteDataDecoder process)
+#define GECKO_PROCESS_TYPE(enum_name, string_name, xre_name) \
+  GeckoProcessType_##enum_name,
+#include "mozilla/GeckoProcessTypes.h"
+#undef GECKO_PROCESS_TYPE
   GeckoProcessType_End,
   GeckoProcessType_Invalid = GeckoProcessType_End
 };
 
 static const char* const kGeckoProcessTypeString[] = {
-    "default",  "plugin", "tab", "ipdlunittest",
-    "gmplugin", "gpu",    "vr",  "rdd"};
+#define GECKO_PROCESS_TYPE(enum_name, string_name, xre_name) \
+  string_name,
+#include "mozilla/GeckoProcessTypes.h"
+#undef GECKO_PROCESS_TYPE
+};
 
 static_assert(MOZ_ARRAY_LENGTH(kGeckoProcessTypeString) == GeckoProcessType_End,
               "Array length mismatch");
 
 XRE_API(const char*, XRE_ChildProcessTypeToString,
         (GeckoProcessType aProcessType))
 
 #if defined(MOZ_WIDGET_ANDROID)
@@ -433,30 +428,26 @@ XRE_API(GeckoProcessType, XRE_GetProcess
 
 /**
  * Returns true when called in the e10s parent process.  Does *NOT* return true
  * when called in the main process if e10s is disabled.
  */
 XRE_API(bool, XRE_IsE10sParentProcess, ())
 
 /**
- * Returns true when called in the e10s parent process or called in the main
- * process when e10s is disabled.
+ * 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.
  */
-XRE_API(bool, XRE_IsParentProcess, ())
-
-XRE_API(bool, XRE_IsContentProcess, ())
-
-XRE_API(bool, XRE_IsGPUProcess, ())
-
-XRE_API(bool, XRE_IsRDDProcess, ())
-
-XRE_API(bool, XRE_IsVRProcess, ())
-
-XRE_API(bool, XRE_IsPluginProcess, ())
+#define GECKO_PROCESS_TYPE(enum_name, string_name, xre_name) \
+  XRE_API(bool, XRE_Is##xre_name##Process, ())
+#include "mozilla/GeckoProcessTypes.h"
+#undef GECKO_PROCESS_TYPE
 
 /**
  * Returns true if the appshell should run its own native event loop. Returns
  * false if we should rely solely on the Gecko event loop.
  */
 XRE_API(bool, XRE_UseNativeEventProcessing, ())
 
 typedef void (*MainFunction)(void* aData);