2015-07-18 06:35:59 -07:00
|
|
|
/* -*- 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 "mozilla/TimelineConsumers.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
unsigned long TimelineConsumers::sActiveConsumers = 0;
|
2015-07-18 06:35:59 -07:00
|
|
|
LinkedList<ObservedDocShell>* TimelineConsumers::sObservedDocShells = nullptr;
|
|
|
|
|
|
|
|
LinkedList<ObservedDocShell>&
|
|
|
|
TimelineConsumers::GetOrCreateObservedDocShellsList()
|
|
|
|
{
|
|
|
|
if (!sObservedDocShells) {
|
|
|
|
sObservedDocShells = new LinkedList<ObservedDocShell>();
|
|
|
|
}
|
|
|
|
return *sObservedDocShells;
|
|
|
|
}
|
2015-07-18 06:35:59 -07:00
|
|
|
|
|
|
|
void
|
2015-07-18 06:35:59 -07:00
|
|
|
TimelineConsumers::AddConsumer(nsDocShell* aDocShell)
|
2015-07-18 06:35:59 -07:00
|
|
|
{
|
2015-07-18 06:35:59 -07:00
|
|
|
UniquePtr<ObservedDocShell>& observed = aDocShell->mObserved;
|
|
|
|
|
|
|
|
MOZ_ASSERT(!observed);
|
2015-07-18 06:35:59 -07:00
|
|
|
sActiveConsumers++;
|
2015-07-18 06:35:59 -07:00
|
|
|
observed.reset(new ObservedDocShell(aDocShell));
|
|
|
|
GetOrCreateObservedDocShellsList().insertFront(observed.get());
|
2015-07-18 06:35:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-18 06:35:59 -07:00
|
|
|
TimelineConsumers::RemoveConsumer(nsDocShell* aDocShell)
|
2015-07-18 06:35:59 -07:00
|
|
|
{
|
2015-07-18 06:35:59 -07:00
|
|
|
UniquePtr<ObservedDocShell>& observed = aDocShell->mObserved;
|
|
|
|
|
|
|
|
MOZ_ASSERT(observed);
|
2015-07-18 06:35:59 -07:00
|
|
|
sActiveConsumers--;
|
2015-07-18 06:35:59 -07:00
|
|
|
observed.get()->ClearMarkers();
|
|
|
|
observed.get()->remove();
|
|
|
|
observed.reset(nullptr);
|
2015-07-18 06:35:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TimelineConsumers::IsEmpty()
|
|
|
|
{
|
|
|
|
return sActiveConsumers == 0;
|
|
|
|
}
|
|
|
|
|
2015-07-18 06:35:59 -07:00
|
|
|
bool
|
|
|
|
TimelineConsumers::GetKnownDocShells(Vector<nsRefPtr<nsDocShell>>& aStore)
|
|
|
|
{
|
|
|
|
const LinkedList<ObservedDocShell>& docShells = GetOrCreateObservedDocShellsList();
|
|
|
|
|
|
|
|
for (const ObservedDocShell* rds = docShells.getFirst();
|
|
|
|
rds != nullptr;
|
|
|
|
rds = rds->getNext()) {
|
|
|
|
if (!aStore.append(**rds)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-18 06:35:59 -07:00
|
|
|
void
|
|
|
|
TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
|
2015-08-24 22:51:58 -07:00
|
|
|
const char* aName,
|
|
|
|
TracingMetadata aMetaData)
|
2015-07-18 06:35:59 -07:00
|
|
|
{
|
|
|
|
if (aDocShell->IsObserved()) {
|
2015-08-31 02:42:35 -07:00
|
|
|
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aName, aMetaData)));
|
2015-08-24 22:51:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
|
|
|
|
const char* aName,
|
|
|
|
const TimeStamp& aTime,
|
|
|
|
TracingMetadata aMetaData)
|
|
|
|
{
|
|
|
|
if (aDocShell->IsObserved()) {
|
2015-08-31 02:42:35 -07:00
|
|
|
aDocShell->mObserved->AddMarker(Move(MakeUnique<TimelineMarker>(aName, aTime, aMetaData)));
|
2015-07-18 06:35:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell,
|
2015-08-24 22:51:58 -07:00
|
|
|
UniquePtr<TimelineMarker>&& aMarker)
|
2015-07-18 06:35:59 -07:00
|
|
|
{
|
|
|
|
if (aDocShell->IsObserved()) {
|
2015-08-24 22:51:58 -07:00
|
|
|
aDocShell->mObserved->AddMarker(Move(aMarker));
|
2015-07-18 06:35:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-24 22:51:58 -07:00
|
|
|
void
|
|
|
|
TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell,
|
|
|
|
const char* aName,
|
|
|
|
TracingMetadata aMetaData)
|
|
|
|
{
|
|
|
|
AddMarkerForDocShell(static_cast<nsDocShell*>(aDocShell), aName, aMetaData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell,
|
|
|
|
const char* aName,
|
|
|
|
const TimeStamp& aTime,
|
|
|
|
TracingMetadata aMetaData)
|
|
|
|
{
|
|
|
|
AddMarkerForDocShell(static_cast<nsDocShell*>(aDocShell), aName, aTime, aMetaData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell,
|
|
|
|
UniquePtr<TimelineMarker>&& aMarker)
|
|
|
|
{
|
|
|
|
AddMarkerForDocShell(static_cast<nsDocShell*>(aDocShell), Move(aMarker));
|
|
|
|
}
|
|
|
|
|
2015-07-18 06:35:59 -07:00
|
|
|
void
|
2015-08-05 03:32:24 -07:00
|
|
|
TimelineConsumers::AddMarkerForDocShellsList(Vector<nsRefPtr<nsDocShell>>& aDocShells,
|
2015-08-24 22:51:58 -07:00
|
|
|
const char* aName,
|
|
|
|
TracingMetadata aMetaData)
|
2015-07-18 06:35:59 -07:00
|
|
|
{
|
|
|
|
for (Vector<nsRefPtr<nsDocShell>>::Range range = aDocShells.all();
|
|
|
|
!range.empty();
|
|
|
|
range.popFront()) {
|
|
|
|
AddMarkerForDocShell(range.front(), aName, aMetaData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-24 22:51:58 -07:00
|
|
|
TimelineConsumers::AddMarkerForAllObservedDocShells(const char* aName,
|
|
|
|
TracingMetadata aMetaData)
|
2015-07-18 06:35:59 -07:00
|
|
|
{
|
|
|
|
Vector<nsRefPtr<nsDocShell>> docShells;
|
|
|
|
if (!GetKnownDocShells(docShells)) {
|
|
|
|
// If we don't successfully populate our vector with *all* docshells being
|
|
|
|
// observed, don't add the marker to *any* of them.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-05 03:32:24 -07:00
|
|
|
AddMarkerForDocShellsList(docShells, aName, aMetaData);
|
2015-07-18 06:35:59 -07:00
|
|
|
}
|
|
|
|
|
2015-07-18 06:35:59 -07:00
|
|
|
} // namespace mozilla
|