From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/doctor/DDLifetimes.cpp | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 dom/media/doctor/DDLifetimes.cpp (limited to 'dom/media/doctor/DDLifetimes.cpp') diff --git a/dom/media/doctor/DDLifetimes.cpp b/dom/media/doctor/DDLifetimes.cpp new file mode 100644 index 0000000000..ba14e33eac --- /dev/null +++ b/dom/media/doctor/DDLifetimes.cpp @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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 "DDLifetimes.h" + +#include "DDLogUtils.h" + +namespace mozilla { + +DDLifetime* DDLifetimes::FindLifetime(const DDLogObject& aObject, + const DDMessageIndex& aIndex) { + LifetimesForObject* lifetimes = mLifetimes.Get(aObject); + if (lifetimes) { + for (DDLifetime& lifetime : *lifetimes) { + if (lifetime.mObject == aObject && lifetime.IsAliveAt(aIndex)) { + return &lifetime; + } + } + } + return nullptr; +} + +const DDLifetime* DDLifetimes::FindLifetime( + const DDLogObject& aObject, const DDMessageIndex& aIndex) const { + const LifetimesForObject* lifetimes = mLifetimes.Get(aObject); + if (lifetimes) { + for (const DDLifetime& lifetime : *lifetimes) { + if (lifetime.mObject == aObject && lifetime.IsAliveAt(aIndex)) { + return &lifetime; + } + } + } + return nullptr; +} + +DDLifetime& DDLifetimes::CreateLifetime( + const DDLogObject& aObject, DDMessageIndex aIndex, + const DDTimeStamp& aConstructionTimeStamp) { + // Use negative tags for yet-unclassified messages. + static int32_t sTag = 0; + if (--sTag > 0) { + sTag = -1; + } + LifetimesForObject* lifetimes = mLifetimes.GetOrInsertNew(aObject, 1); + DDLifetime& lifetime = *lifetimes->AppendElement( + DDLifetime(aObject, aIndex, aConstructionTimeStamp, sTag)); + return lifetime; +} + +void DDLifetimes::RemoveLifetime(const DDLifetime* aLifetime) { + LifetimesForObject* lifetimes = mLifetimes.Get(aLifetime->mObject); + MOZ_ASSERT(lifetimes); + DDL_LOG(aLifetime->mMediaElement ? mozilla::LogLevel::Debug + : mozilla::LogLevel::Warning, + "Remove lifetime %s", aLifetime->Printf().get()); + // We should have been given a pointer inside this lifetimes array. + auto arrayIndex = aLifetime - lifetimes->Elements(); + MOZ_ASSERT(static_cast(arrayIndex) < lifetimes->Length()); + lifetimes->RemoveElementAt(arrayIndex); +} + +void DDLifetimes::RemoveLifetimesFor( + const dom::HTMLMediaElement* aMediaElement) { + for (const auto& lifetimes : mLifetimes.Values()) { + lifetimes->RemoveElementsBy([aMediaElement](const DDLifetime& lifetime) { + return lifetime.mMediaElement == aMediaElement; + }); + } +} + +void DDLifetimes::Clear() { mLifetimes.Clear(); } + +size_t DDLifetimes::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { + size_t size = mLifetimes.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (const auto& lifetimes : mLifetimes.Values()) { + size += lifetimes->ShallowSizeOfExcludingThis(aMallocSizeOf); + } + return size; +} + +} // namespace mozilla -- cgit v1.2.3