tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DDLifetime.h (2698B)


      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  const DDLogObject mObject;
     26  const DDMessageIndex mConstructionIndex;
     27  const DDTimeStamp mConstructionTimeStamp;
     28  // Only valid when mDestructionTimeStamp is not null.
     29  DDMessageIndex mDestructionIndex;
     30  DDTimeStamp mDestructionTimeStamp;
     31  // Associated HTMLMediaElement, initially nullptr until this object can be
     32  // linked to its HTMLMediaElement.
     33  const dom::HTMLMediaElement* mMediaElement;
     34  // If not null, derived object for which this DDLifetime is a base class.
     35  // This is used to link messages from the same object, even when they
     36  // originate from a method on a base class.
     37  // Note: We assume a single-inheritance hierarchy.
     38  DDLogObject mDerivedObject;
     39  DDMessageIndex mDerivedObjectLinkingIndex;
     40  // Unique tag used to identify objects in a log, easier to read than object
     41  // pointers.
     42  // Negative and unique for unassociated objects.
     43  // Positive for associated objects, and unique for that HTMLMediaElement
     44  // group.
     45  int32_t mTag;
     46 
     47  DDLifetime(DDLogObject aObject, DDMessageIndex aConstructionIndex,
     48             DDTimeStamp aConstructionTimeStamp, int32_t aTag)
     49      : mObject(aObject),
     50        mConstructionIndex(aConstructionIndex),
     51        mConstructionTimeStamp(aConstructionTimeStamp),
     52        mDestructionIndex(0),
     53        mMediaElement(nullptr),
     54        mDerivedObjectLinkingIndex(0),
     55        mTag(aTag) {}
     56 
     57  // Is this lifetime alive at the given index?
     58  // I.e.: Constructed before, and destroyed later or not yet.
     59  bool IsAliveAt(DDMessageIndex aIndex) const {
     60    return aIndex >= mConstructionIndex &&
     61           (!mDestructionTimeStamp || aIndex <= mDestructionIndex);
     62  }
     63 
     64  // Print the object's pointer, tag and class name (and derived class). E.g.:
     65  // "dom::HTMLVideoElement[134073800]#1 (as dom::HTMLMediaElement)"
     66  void AppendPrintf(nsCString& aString) const;
     67  nsCString Printf() const;
     68 };
     69 
     70 }  // namespace mozilla
     71 
     72 #endif  // DDLifetime_h_