MojoIpcz: Enable by default for most platforms

This enables MojoIpcz by default for most platforms, with or without an
initialized FeatureList.

Not enabled on macOS since that's controlled by an ongoing Finch
experiment. Not enabled on Chrome OS since that's delayed until some
more work can be done on the Chrome OS side.

This also fixes several small issues around the tree which were
surfaced by the Mojo impl change:

- ipc_tests and chrome_cleaner_unittests properly configure
  broker/non-broker processes
- some blob storage tests pump tasks on teardown to avoid new leaks
- a now-invalid Mojo Java test has been deleted
- a global tracking table has added for internal ipcz API objects
  and MojoIpcz driver objects to avoid LSan detection of existing
  leaks in various test suites around the tree.
- stricter enforcement of platform handle serialization to
  avoid situations where non-optional platform handle fields
  were accepting null platform handles
- fixes to chrome_cleaner, and gfx tests, to address bad
  platform handle usage
- fix to TransferableSocket mojom to make the internal handle
  optional, since that's how it's used in practice.

Bug: 1299283,1415046
Change-Id: Ied45f4ac1c64753d204695f08852352d34aa367b
Reviewed-by: Ayu Ishii <>
Reviewed-by: Joe Mason <>
Reviewed-by: Daniel Cheng <>
Commit-Queue: Ken Rockot <>
Cr-Commit-Position: refs/heads/main@{#1105863}
GitOrigin-RevId: dd70bafb499e62df396d34c82959ed2d424eb09e
diff --git a/src/ipcz/ b/src/ipcz/
index 0a6784b..a9f7a59 100644
--- a/src/ipcz/
+++ b/src/ipcz/
@@ -4,11 +4,72 @@
 #include "ipcz/api_object.h"
+#include <cstdint>
+#include "third_party/abseil-cpp/absl/container/flat_hash_set.h"
+#include "third_party/abseil-cpp/absl/synchronization/mutex.h"
 namespace ipcz {
-APIObject::APIObject(ObjectType type) : type_(type) {}
+namespace {
-APIObject::~APIObject() = default;
+#if defined(LEAK_SANITIZER)
+// When LSan is enabled, we keep all living API objects tracked within a global
+// hash set so that they're always reachable and never detected as leaks. This
+// is to work around the fact that Chromium has amassed hundreds of tests across
+// more than a dozen test suites which leak Mojo handles; and prior to MojoIpcz
+// the leaks were masked from LSan by Mojo's use of a global handle table.
+// TODO( Remove this once all of the leaky tests are
+// fixed.
+class TrackedObjectSet {
+ public:
+  TrackedObjectSet() = default;
+  ~TrackedObjectSet() = default;
+  void Add(APIObject* object) {
+    absl::MutexLock lock(&mutex_);
+    tracked_objects_.insert(reinterpret_cast<uintptr_t>(object));
+  }
+  void Remove(APIObject* object) {
+    absl::MutexLock lock(&mutex_);
+    tracked_objects_.erase(reinterpret_cast<uintptr_t>(object));
+  }
+ private:
+  absl::Mutex mutex_;
+  // Use a uintptr_t to track since these aren't meant to be usable as pointers.
+  absl::flat_hash_set<uintptr_t> tracked_objects_ ABSL_GUARDED_BY(mutex_);
+TrackedObjectSet& GetTrackedObjectSet() {
+  static auto* set = new TrackedObjectSet();
+  return *set;
+void TrackObject(APIObject* object) {
+  GetTrackedObjectSet().Add(object);
+void UntrackObject(APIObject* object) {
+  GetTrackedObjectSet().Remove(object);
+void TrackObject(APIObject*) {}
+void UntrackObject(APIObject*) {}
+}  // namespace
+APIObject::APIObject(ObjectType type) : type_(type) {
+  TrackObject(this);
+APIObject::~APIObject() {
+  UntrackObject(this);
 bool APIObject::CanSendFrom(Portal& sender) {
   return false;