blob: ba14e33eac214394d82c7bc9a7a32e2e7d5856e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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<size_t>(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
|