/* -*- 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; LinkedList* TimelineConsumers::sObservedDocShells = nullptr; LinkedList& TimelineConsumers::GetOrCreateObservedDocShellsList() { if (!sObservedDocShells) { sObservedDocShells = new LinkedList(); } return *sObservedDocShells; } void TimelineConsumers::AddConsumer(nsDocShell* aDocShell) { UniquePtr& observed = aDocShell->mObserved; MOZ_ASSERT(!observed); sActiveConsumers++; observed.reset(new ObservedDocShell(aDocShell)); GetOrCreateObservedDocShellsList().insertFront(observed.get()); } void TimelineConsumers::RemoveConsumer(nsDocShell* aDocShell) { UniquePtr& observed = aDocShell->mObserved; MOZ_ASSERT(observed); sActiveConsumers--; observed.get()->ClearMarkers(); observed.get()->remove(); observed.reset(nullptr); } bool TimelineConsumers::IsEmpty() { return sActiveConsumers == 0; } bool TimelineConsumers::GetKnownDocShells(Vector>& aStore) { const LinkedList& docShells = GetOrCreateObservedDocShellsList(); for (const ObservedDocShell* rds = docShells.getFirst(); rds != nullptr; rds = rds->getNext()) { if (!aStore.append(**rds)) { return false; } } return true; } void TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell, const char* aName, MarkerTracingType aTracingType) { if (aDocShell->IsObserved()) { aDocShell->mObserved->AddMarker(Move(MakeUnique(aName, aTracingType))); } } void TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell, const char* aName, const TimeStamp& aTime, MarkerTracingType aTracingType) { if (aDocShell->IsObserved()) { aDocShell->mObserved->AddMarker(Move(MakeUnique(aName, aTime, aTracingType))); } } void TimelineConsumers::AddMarkerForDocShell(nsDocShell* aDocShell, UniquePtr&& aMarker) { if (aDocShell->IsObserved()) { aDocShell->mObserved->AddMarker(Move(aMarker)); } } void TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell, const char* aName, MarkerTracingType aTracingType) { AddMarkerForDocShell(static_cast(aDocShell), aName, aTracingType); } void TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell, const char* aName, const TimeStamp& aTime, MarkerTracingType aTracingType) { AddMarkerForDocShell(static_cast(aDocShell), aName, aTime, aTracingType); } void TimelineConsumers::AddMarkerForDocShell(nsIDocShell* aDocShell, UniquePtr&& aMarker) { AddMarkerForDocShell(static_cast(aDocShell), Move(aMarker)); } void TimelineConsumers::AddMarkerForDocShellsList(Vector>& aDocShells, const char* aName, MarkerTracingType aTracingType) { for (Vector>::Range range = aDocShells.all(); !range.empty(); range.popFront()) { AddMarkerForDocShell(range.front(), aName, aTracingType); } } void TimelineConsumers::AddMarkerForAllObservedDocShells(const char* aName, MarkerTracingType aTracingType) { Vector> 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; } AddMarkerForDocShellsList(docShells, aName, aTracingType); } } // namespace mozilla