mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1200118 - Create a barebones TimelineMarker abstract class, r=tromey
This commit is contained in:
parent
95e78ffe83
commit
6316fd46c1
50
docshell/base/timeline/AbstractTimelineMarker.cpp
Normal file
50
docshell/base/timeline/AbstractTimelineMarker.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "AbstractTimelineMarker.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
AbstractTimelineMarker::AbstractTimelineMarker(const char* aName,
|
||||
MarkerTracingType aTracingType)
|
||||
: mName(aName)
|
||||
, mTracingType(aTracingType)
|
||||
{
|
||||
MOZ_COUNT_CTOR(AbstractTimelineMarker);
|
||||
SetCurrentTime();
|
||||
}
|
||||
|
||||
AbstractTimelineMarker::AbstractTimelineMarker(const char* aName,
|
||||
const TimeStamp& aTime,
|
||||
MarkerTracingType aTracingType)
|
||||
: mName(aName)
|
||||
, mTracingType(aTracingType)
|
||||
{
|
||||
MOZ_COUNT_CTOR(AbstractTimelineMarker);
|
||||
SetCustomTime(aTime);
|
||||
}
|
||||
|
||||
AbstractTimelineMarker::~AbstractTimelineMarker()
|
||||
{
|
||||
MOZ_COUNT_DTOR(AbstractTimelineMarker);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTimelineMarker::SetCurrentTime()
|
||||
{
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
SetCustomTime(now);
|
||||
}
|
||||
|
||||
void
|
||||
AbstractTimelineMarker::SetCustomTime(const TimeStamp& aTime)
|
||||
{
|
||||
bool isInconsistent = false;
|
||||
mTime = (aTime - TimeStamp::ProcessCreation(isInconsistent)).ToMilliseconds();
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
57
docshell/base/timeline/AbstractTimelineMarker.h
Normal file
57
docshell/base/timeline/AbstractTimelineMarker.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_AbstractTimelineMarker_h_
|
||||
#define mozilla_AbstractTimelineMarker_h_
|
||||
|
||||
#include "TimelineMarkerEnums.h" // for MarkerTracingType
|
||||
#include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp
|
||||
|
||||
struct JSContext;
|
||||
|
||||
namespace mozilla {
|
||||
class TimeStamp;
|
||||
|
||||
namespace dom {
|
||||
struct ProfileTimelineMarker;
|
||||
}
|
||||
|
||||
class AbstractTimelineMarker
|
||||
{
|
||||
private:
|
||||
AbstractTimelineMarker() = delete;
|
||||
AbstractTimelineMarker(const AbstractTimelineMarker& aOther) = delete;
|
||||
void operator=(const AbstractTimelineMarker& aOther) = delete;
|
||||
|
||||
public:
|
||||
AbstractTimelineMarker(const char* aName,
|
||||
MarkerTracingType aTracingType);
|
||||
|
||||
AbstractTimelineMarker(const char* aName,
|
||||
const TimeStamp& aTime,
|
||||
MarkerTracingType aTracingType);
|
||||
|
||||
virtual ~AbstractTimelineMarker();
|
||||
|
||||
virtual bool Equals(const AbstractTimelineMarker& aOther) = 0;
|
||||
virtual void AddDetails(JSContext* aCx, dom::ProfileTimelineMarker& aMarker) = 0;
|
||||
|
||||
const char* GetName() const { return mName; }
|
||||
DOMHighResTimeStamp GetTime() const { return mTime; }
|
||||
MarkerTracingType GetTracingType() const { return mTracingType; }
|
||||
|
||||
private:
|
||||
const char* mName;
|
||||
DOMHighResTimeStamp mTime;
|
||||
MarkerTracingType mTracingType;
|
||||
|
||||
void SetCurrentTime();
|
||||
void SetCustomTime(const TimeStamp& aTime);
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_AbstractTimelineMarker_h_ */
|
@ -27,7 +27,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool Equals(const TimelineMarker& aOther) override
|
||||
virtual bool Equals(const AbstractTimelineMarker& aOther) override
|
||||
{
|
||||
if (!TimelineMarker::Equals(aOther)) {
|
||||
return false;
|
||||
|
@ -11,11 +11,8 @@ namespace mozilla {
|
||||
TimelineMarker::TimelineMarker(const char* aName,
|
||||
MarkerTracingType aTracingType,
|
||||
MarkerStackRequest aStackRequest)
|
||||
: mName(aName)
|
||||
, mTracingType(aTracingType)
|
||||
: AbstractTimelineMarker(aName, aTracingType)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TimelineMarker);
|
||||
SetCurrentTime();
|
||||
CaptureStackIfNecessary(aTracingType, aStackRequest);
|
||||
}
|
||||
|
||||
@ -23,31 +20,46 @@ TimelineMarker::TimelineMarker(const char* aName,
|
||||
const TimeStamp& aTime,
|
||||
MarkerTracingType aTracingType,
|
||||
MarkerStackRequest aStackRequest)
|
||||
: mName(aName)
|
||||
, mTracingType(aTracingType)
|
||||
: AbstractTimelineMarker(aName, aTime, aTracingType)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TimelineMarker);
|
||||
SetCustomTime(aTime);
|
||||
CaptureStackIfNecessary(aTracingType, aStackRequest);
|
||||
}
|
||||
|
||||
TimelineMarker::~TimelineMarker()
|
||||
bool
|
||||
TimelineMarker::Equals(const AbstractTimelineMarker& aOther)
|
||||
{
|
||||
MOZ_COUNT_DTOR(TimelineMarker);
|
||||
// Check whether two markers should be considered the same, for the purpose
|
||||
// of pairing start and end markers. Normally this definition suffices.
|
||||
return strcmp(GetName(), aOther.GetName()) == 0;
|
||||
}
|
||||
|
||||
void
|
||||
TimelineMarker::SetCurrentTime()
|
||||
TimelineMarker::AddDetails(JSContext* aCx, dom::ProfileTimelineMarker& aMarker)
|
||||
{
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
SetCustomTime(now);
|
||||
// Nothing to do here for plain markers.
|
||||
}
|
||||
|
||||
JSObject*
|
||||
TimelineMarker::GetStack()
|
||||
{
|
||||
if (mStackTrace.initialized()) {
|
||||
return mStackTrace;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
TimelineMarker::SetCustomTime(const TimeStamp& aTime)
|
||||
TimelineMarker::CaptureStack()
|
||||
{
|
||||
bool isInconsistent = false;
|
||||
mTime = (aTime - TimeStamp::ProcessCreation(isInconsistent)).ToMilliseconds();
|
||||
JSContext* ctx = nsContentUtils::GetCurrentJSContext();
|
||||
if (ctx) {
|
||||
JS::RootedObject stack(ctx);
|
||||
if (JS::CaptureCurrentStack(ctx, &stack)) {
|
||||
mStackTrace.init(ctx, stack.get());
|
||||
} else {
|
||||
JS_ClearPendingException(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -7,21 +7,15 @@
|
||||
#ifndef mozilla_TimelineMarker_h_
|
||||
#define mozilla_TimelineMarker_h_
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "TimelineMarkerEnums.h"
|
||||
|
||||
class nsDocShell;
|
||||
#include "AbstractTimelineMarker.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
struct ProfileTimelineMarker;
|
||||
}
|
||||
|
||||
// Objects of this type can be added to the timeline if there is an interested
|
||||
// consumer. The class can also be subclassed to let a given marker creator
|
||||
// provide custom details.
|
||||
class TimelineMarker
|
||||
class TimelineMarker : public AbstractTimelineMarker
|
||||
{
|
||||
public:
|
||||
TimelineMarker(const char* aName,
|
||||
@ -33,61 +27,21 @@ public:
|
||||
MarkerTracingType aTracingType,
|
||||
MarkerStackRequest aStackRequest = MarkerStackRequest::STACK);
|
||||
|
||||
virtual ~TimelineMarker();
|
||||
virtual bool Equals(const AbstractTimelineMarker& aOther) override;
|
||||
virtual void AddDetails(JSContext* aCx, dom::ProfileTimelineMarker& aMarker) override;
|
||||
|
||||
// Check whether two markers should be considered the same, for the purpose
|
||||
// of pairing start and end markers. Normally this definition suffices.
|
||||
virtual bool Equals(const TimelineMarker& aOther)
|
||||
{
|
||||
return strcmp(mName, aOther.mName) == 0;
|
||||
}
|
||||
|
||||
// Add details specific to this marker type to aMarker. The standard elements
|
||||
// have already been set. This method is called on both the starting and
|
||||
// ending markers of a pair. Ordinarily the ending marker doesn't need to do
|
||||
// anything here.
|
||||
virtual void AddDetails(JSContext* aCx, dom::ProfileTimelineMarker& aMarker)
|
||||
{}
|
||||
|
||||
const char* GetName() const { return mName; }
|
||||
DOMHighResTimeStamp GetTime() const { return mTime; }
|
||||
MarkerTracingType GetTracingType() const { return mTracingType; }
|
||||
|
||||
JSObject* GetStack()
|
||||
{
|
||||
if (mStackTrace.initialized()) {
|
||||
return mStackTrace;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
JSObject* GetStack();
|
||||
|
||||
protected:
|
||||
void CaptureStack()
|
||||
{
|
||||
JSContext* ctx = nsContentUtils::GetCurrentJSContext();
|
||||
if (ctx) {
|
||||
JS::RootedObject stack(ctx);
|
||||
if (JS::CaptureCurrentStack(ctx, &stack)) {
|
||||
mStackTrace.init(ctx, stack.get());
|
||||
} else {
|
||||
JS_ClearPendingException(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
void CaptureStack();
|
||||
|
||||
private:
|
||||
const char* mName;
|
||||
DOMHighResTimeStamp mTime;
|
||||
MarkerTracingType mTracingType;
|
||||
|
||||
// While normally it is not a good idea to make a persistent root,
|
||||
// in this case changing nsDocShell to participate in cycle
|
||||
// collection was deemed too invasive, and the markers are only held
|
||||
// here temporarily to boot.
|
||||
JS::PersistentRooted<JSObject*> mStackTrace;
|
||||
|
||||
void SetCurrentTime();
|
||||
void SetCustomTime(const TimeStamp& aTime);
|
||||
void CaptureStackIfNecessary(MarkerTracingType aTracingType,
|
||||
MarkerStackRequest aStackRequest);
|
||||
};
|
||||
|
@ -5,6 +5,7 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
EXPORTS.mozilla += [
|
||||
'AbstractTimelineMarker.h',
|
||||
'AutoGlobalTimelineMarker.h',
|
||||
'AutoTimelineMarker.h',
|
||||
'ConsoleTimelineMarker.h',
|
||||
@ -20,6 +21,7 @@ EXPORTS.mozilla += [
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'AbstractTimelineMarker.cpp',
|
||||
'AutoGlobalTimelineMarker.cpp',
|
||||
'AutoTimelineMarker.cpp',
|
||||
'ObservedDocShell.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user