/src/mozilla-central/dom/media/doctor/DDLifetime.h
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 | | #ifndef DDLifetime_h_ |
8 | | #define DDLifetime_h_ |
9 | | |
10 | | #include "DDLogObject.h" |
11 | | #include "DDMessageIndex.h" |
12 | | #include "DDTimeStamp.h" |
13 | | |
14 | | namespace mozilla { |
15 | | |
16 | | namespace dom { |
17 | | class HTMLMediaElement; |
18 | | } // namespace dom |
19 | | |
20 | | // This struct records the lifetime of one C++ object. |
21 | | // Note that multiple objects may have the same address and type (at different |
22 | | // times), so the recorded construction/destruction times should be used to |
23 | | // distinguish them. |
24 | | struct DDLifetime |
25 | | { |
26 | | const DDLogObject mObject; |
27 | | const DDMessageIndex mConstructionIndex; |
28 | | const DDTimeStamp mConstructionTimeStamp; |
29 | | // Only valid when mDestructionTimeStamp is not null. |
30 | | DDMessageIndex mDestructionIndex; |
31 | | DDTimeStamp mDestructionTimeStamp; |
32 | | // Associated HTMLMediaElement, initially nullptr until this object can be |
33 | | // linked to its HTMLMediaElement. |
34 | | const dom::HTMLMediaElement* mMediaElement; |
35 | | // If not null, derived object for which this DDLifetime is a base class. |
36 | | // This is used to link messages from the same object, even when they |
37 | | // originate from a method on a base class. |
38 | | // Note: We assume a single-inheritance hierarchy. |
39 | | DDLogObject mDerivedObject; |
40 | | DDMessageIndex mDerivedObjectLinkingIndex; |
41 | | // Unique tag used to identify objects in a log, easier to read than object |
42 | | // pointers. |
43 | | // Negative and unique for unassociated objects. |
44 | | // Positive for associated objects, and unique for that HTMLMediaElement |
45 | | // group. |
46 | | int32_t mTag; |
47 | | |
48 | | DDLifetime(DDLogObject aObject, |
49 | | DDMessageIndex aConstructionIndex, |
50 | | DDTimeStamp aConstructionTimeStamp, |
51 | | int32_t aTag) |
52 | | : mObject(aObject) |
53 | | , mConstructionIndex(aConstructionIndex) |
54 | | , mConstructionTimeStamp(aConstructionTimeStamp) |
55 | | , mDestructionIndex(0) |
56 | | , mMediaElement(nullptr) |
57 | | , mDerivedObjectLinkingIndex(0) |
58 | | , mTag(aTag) |
59 | 0 | { |
60 | 0 | } |
61 | | |
62 | | // Is this lifetime alive at the given index? |
63 | | // I.e.: Constructed before, and destroyed later or not yet. |
64 | | bool IsAliveAt(DDMessageIndex aIndex) const |
65 | 0 | { |
66 | 0 | return aIndex >= mConstructionIndex && |
67 | 0 | (!mDestructionTimeStamp || aIndex <= mDestructionIndex); |
68 | 0 | } |
69 | | |
70 | | // Print the object's pointer, tag and class name (and derived class). E.g.: |
71 | | // "dom::HTMLVideoElement[134073800]#1 (as dom::HTMLMediaElement)" |
72 | | void AppendPrintf(nsCString& aString) const; |
73 | | nsCString Printf() const; |
74 | | }; |
75 | | |
76 | | } // namespace mozilla |
77 | | |
78 | | #endif // DDLifetime_h_ |