Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/doctor/DDLifetimes.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "DDLifetimes.h"
8
9
#include "DDLogUtils.h"
10
11
namespace mozilla {
12
13
DDLifetime*
14
DDLifetimes::FindLifetime(const DDLogObject& aObject,
15
                          const DDMessageIndex& aIndex)
16
0
{
17
0
  LifetimesForObject* lifetimes = mLifetimes.Get(aObject);
18
0
  if (lifetimes) {
19
0
    for (DDLifetime& lifetime : *lifetimes) {
20
0
      if (lifetime.mObject == aObject && lifetime.IsAliveAt(aIndex)) {
21
0
        return &lifetime;
22
0
      }
23
0
    }
24
0
  }
25
0
  return nullptr;
26
0
}
27
28
const DDLifetime*
29
DDLifetimes::FindLifetime(const DDLogObject& aObject,
30
                          const DDMessageIndex& aIndex) const
31
0
{
32
0
  const LifetimesForObject* lifetimes = mLifetimes.Get(aObject);
33
0
  if (lifetimes) {
34
0
    for (const DDLifetime& lifetime : *lifetimes) {
35
0
      if (lifetime.mObject == aObject && lifetime.IsAliveAt(aIndex)) {
36
0
        return &lifetime;
37
0
      }
38
0
    }
39
0
  }
40
0
  return nullptr;
41
0
}
42
43
DDLifetime&
44
DDLifetimes::CreateLifetime(const DDLogObject& aObject,
45
                            DDMessageIndex aIndex,
46
                            const DDTimeStamp& aConstructionTimeStamp)
47
0
{
48
0
  // Use negative tags for yet-unclassified messages.
49
0
  static int32_t sTag = 0;
50
0
  if (--sTag > 0) {
51
0
    sTag = -1;
52
0
  }
53
0
  LifetimesForObject* lifetimes = mLifetimes.LookupOrAdd(aObject, 1);
54
0
  DDLifetime& lifetime = *lifetimes->AppendElement(
55
0
    DDLifetime(aObject, aIndex, aConstructionTimeStamp, sTag));
56
0
  return lifetime;
57
0
}
58
59
void
60
DDLifetimes::RemoveLifetime(const DDLifetime* aLifetime)
61
0
{
62
0
  LifetimesForObject* lifetimes = mLifetimes.Get(aLifetime->mObject);
63
0
  MOZ_ASSERT(lifetimes);
64
0
  DDL_LOG(aLifetime->mMediaElement ? mozilla::LogLevel::Debug
65
0
                                   : mozilla::LogLevel::Warning,
66
0
          "Remove lifetime %s",
67
0
          aLifetime->Printf().get());
68
0
  // We should have been given a pointer inside this lifetimes array.
69
0
  auto arrayIndex = aLifetime - lifetimes->Elements();
70
0
  MOZ_ASSERT(static_cast<size_t>(arrayIndex) < lifetimes->Length());
71
0
  lifetimes->RemoveElementAt(arrayIndex);
72
0
}
73
74
void
75
DDLifetimes::RemoveLifetimesFor(const dom::HTMLMediaElement* aMediaElement)
76
0
{
77
0
  for (auto iter = mLifetimes.Iter(); !iter.Done(); iter.Next()) {
78
0
    iter.UserData()->RemoveElementsBy(
79
0
      [aMediaElement](const DDLifetime& lifetime) {
80
0
        return lifetime.mMediaElement == aMediaElement;
81
0
      });
82
0
  }
83
0
}
84
85
void
86
DDLifetimes::Clear()
87
0
{
88
0
  mLifetimes.Clear();
89
0
}
90
91
size_t
92
DDLifetimes::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
93
0
{
94
0
  size_t size = mLifetimes.ShallowSizeOfExcludingThis(aMallocSizeOf);
95
0
  for (auto iter = mLifetimes.ConstIter(); !iter.Done(); iter.Next()) {
96
0
    size += iter.UserData()->ShallowSizeOfExcludingThis(aMallocSizeOf);
97
0
  }
98
0
  return size;
99
0
}
100
101
} // namespace mozilla