Commit 3d0d39d8 authored by Nick Alexander's avatar Nick Alexander
Browse files

Bug 1675848 - Part 2: Add "BackgroundTasksSelector" to static component...

Bug 1675848 - Part 2: Add "BackgroundTasksSelector" to static component category registration. r=mhentges,nika

For simplicity, this implements just on in `NO_TASKS` (the default) or
on in `ALL_TASKS` (opt-in).  This disables all category registrations
when in background task mode; we'll selectively re-enable things as
appropriate.

The flag constants were chosen to smoothly extend to a (16-)bit set in
the future, should we want to add a `JUST_TASKS("task", "other-task")`
option in the future.

This also adds ython tests for gen_static_components.py exercising
categories, simply 'cuz it's easiest to see what this adds in such
tests.  Functional tests will follow in patches that actually
implement the new background tasks functionality.

Differential Revision: https://phabricator.services.mozilla.com/D96654
parent dc4f4226
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -85,7 +85,11 @@ Class definitions may have the following properties:
``categories`` (optional)
  A dict of category entries to register for this component's contract ID.
  Each key in the dict is the name of the category. Each value is either a
  string containing a single entry name, or a list of entry name strings.
  string containing a single entry, or a list of entries.  Each entry is either
  a string name, or a dictionary of the form ``{'name': 'value', 'backgroundtasks':
  BackgroundTasksSelector.ALL_TASKS}``.  By default, category entries are registered
  for **no background tasks**: they have
  ``'backgroundtasks': BackgroundTasksSelector.NO_TASKS``.

``type`` (optional, default=``nsISupports``)
  The fully-qualified type of the class implementing this component. Defaults
+2 −0
Original line number Diff line number Diff line
@@ -548,6 +548,8 @@ xpcom:
    when:
        files-changed:
            - 'third_party/python/ply/**'
            - 'xpcom/components/*.py'
            - 'xpcom/components/test/**'
            - 'xpcom/ds/tools/**'
            - 'xpcom/ds/test/**'
            - 'xpcom/idl-parser/**'
+11 −0
Original line number Diff line number Diff line
@@ -72,6 +72,17 @@ struct Module {
  static constexpr size_t kMaxProcessSelector =
      size_t(ProcessSelector::ALLOW_IN_GPU_RDD_VR_AND_SOCKET_PROCESS);

  /**
   * This allows category entries to be marked so that they are or are
   * not loaded when in backgroundtask mode.
   */
  // Note: This must be kept in sync with the selector matching in
  // StaticComponents.cpp.in.
  enum BackgroundTasksSelector {
    NO_TASKS = 0x0,
    ALL_TASKS = 0xFFFF,
  };

  /**
   * The constructor callback is an implementation detail of the default binary
   * loader and may be null.
+14 −1
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@
#include "StaticComponents.h"

#include "mozilla/ArrayUtils.h"
#ifdef MOZ_BACKGROUNDTASKS
#  include "mozilla/BackgroundTasks.h"
#endif
#include "mozilla/PerfectHash.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/StaticPtr.h"
@@ -256,11 +259,21 @@ void StaticModule::SetServiceInstance(
nsCString StaticCategoryEntry::Entry() const {
  return GetString(mEntry);
}

nsCString StaticCategoryEntry::Value() const {
  return GetString(mValue);
}

bool StaticCategoryEntry::Active() const {
  return FastProcessSelectorMatches(mProcessSelector);
  if (!FastProcessSelectorMatches(mProcessSelector)) {
    return false;
  }
#ifdef MOZ_BACKGROUNDTASKS
  if (MOZ_UNLIKELY(BackgroundTasks::IsBackgroundTaskMode())) {
    return mBackgroundTasksSelector != Module::BackgroundTasksSelector::NO_TASKS;
  }
#endif /* MOZ_BACKGROUNDTASKS */
  return true;
}

nsCString StaticCategory::Name() const {
+1 −0
Original line number Diff line number Diff line
@@ -187,6 +187,7 @@ struct ContractEntry final {
struct StaticCategoryEntry final {
  StringOffset mEntry;
  StringOffset mValue;
  Module::BackgroundTasksSelector mBackgroundTasksSelector;
  Module::ProcessSelector mProcessSelector;

  nsCString Entry() const;
Loading