diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 46ed81514252..568a3c1f7d7e 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -2929,8 +2929,6 @@ nsDocShell::HistoryTransactionRemoved(int32_t aIndex) return NS_OK; } -unsigned long nsDocShell::gProfileTimelineRecordingsCount = 0; - mozilla::LinkedList* nsDocShell::gObservedDocShells = nullptr; NS_IMETHODIMP @@ -2939,14 +2937,14 @@ nsDocShell::SetRecordProfileTimelineMarkers(bool aValue) bool currentValue = nsIDocShell::GetRecordProfileTimelineMarkers(); if (currentValue != aValue) { if (aValue) { - ++gProfileTimelineRecordingsCount; + TimelineConsumers::AddConsumer(); UseEntryScriptProfiling(); MOZ_ASSERT(!mObserved); mObserved.reset(new ObservedDocShell(this)); GetOrCreateObservedDocShells().insertFront(mObserved.get()); } else { - --gProfileTimelineRecordingsCount; + TimelineConsumers::RemoveConsumer(); UnuseEntryScriptProfiling(); mObserved.reset(nullptr); diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 9f2f82af82d3..103cc0497fbf 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -34,6 +34,7 @@ #include "nsThreadUtils.h" #include "nsContentUtils.h" #include "timeline/TimelineMarker.h" +#include "timeline/TimelineConsumers.h" // Threshold value in ms for META refresh based redirects #define REFRESH_REDIRECT_TIMER 15000 @@ -262,10 +263,6 @@ public: void AddProfileTimelineMarker(const char* aName, TracingMetadata aMetaData); void AddProfileTimelineMarker(mozilla::UniquePtr&& aMarker); - // Global counter for how many docShells are currently recording profile - // timeline markers - static unsigned long gProfileTimelineRecordingsCount; - class ObservedDocShell : public mozilla::LinkedListElement { public: diff --git a/docshell/base/timeline/AutoGlobalTimelineMarker.cpp b/docshell/base/timeline/AutoGlobalTimelineMarker.cpp index 4e0721c0d940..c4120d422e6a 100644 --- a/docshell/base/timeline/AutoGlobalTimelineMarker.cpp +++ b/docshell/base/timeline/AutoGlobalTimelineMarker.cpp @@ -6,6 +6,7 @@ #include "mozilla/AutoGlobalTimelineMarker.h" +#include "mozilla/TimelineConsumers.h" #include "MainThreadUtils.h" #include "nsDocShell.h" @@ -37,7 +38,7 @@ AutoGlobalTimelineMarker::AutoGlobalTimelineMarker(const char* aName MOZ_GUARD_OBJECT_NOTIFIER_INIT; MOZ_ASSERT(NS_IsMainThread()); - if (nsDocShell::gProfileTimelineRecordingsCount == 0) { + if (TimelineConsumers::IsEmpty()) { return; } diff --git a/docshell/base/timeline/AutoTimelineMarker.cpp b/docshell/base/timeline/AutoTimelineMarker.cpp index 82fcd1de8b0c..33b9ba17a7e2 100644 --- a/docshell/base/timeline/AutoTimelineMarker.cpp +++ b/docshell/base/timeline/AutoTimelineMarker.cpp @@ -15,7 +15,7 @@ bool AutoTimelineMarker::DocShellIsRecording(nsDocShell& aDocShell) { bool isRecording = false; - if (nsDocShell::gProfileTimelineRecordingsCount > 0) { + if (!TimelineConsumers::IsEmpty()) { aDocShell.GetRecordProfileTimelineMarkers(&isRecording); } return isRecording; diff --git a/docshell/base/timeline/TimelineConsumers.cpp b/docshell/base/timeline/TimelineConsumers.cpp new file mode 100644 index 000000000000..d3c0aa33dbbd --- /dev/null +++ b/docshell/base/timeline/TimelineConsumers.cpp @@ -0,0 +1,31 @@ +/* -*- 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; + +void +TimelineConsumers::AddConsumer() +{ + sActiveConsumers++; +} + +void +TimelineConsumers::RemoveConsumer() +{ + sActiveConsumers--; +} + +bool +TimelineConsumers::IsEmpty() +{ + return sActiveConsumers == 0; +} + +} // namespace mozilla diff --git a/docshell/base/timeline/TimelineConsumers.h b/docshell/base/timeline/TimelineConsumers.h new file mode 100644 index 000000000000..e9c8cbe0af93 --- /dev/null +++ b/docshell/base/timeline/TimelineConsumers.h @@ -0,0 +1,32 @@ +/* -*- 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_TimelineConsumers_h_ +#define mozilla_TimelineConsumers_h_ + +class nsDocShell; + +namespace mozilla { + +// # TimelineConsumers +// +// A class to trace how many frontends are interested in markers. Whenever +// interest is expressed in markers, these fields will keep track of that. +class TimelineConsumers +{ +private: + // Counter for how many timelines are currently interested in markers. + static unsigned long sActiveConsumers; + +public: + static void AddConsumer(); + static void RemoveConsumer(); + static bool IsEmpty(); +}; + +} // namespace mozilla + +#endif /* mozilla_TimelineConsumers_h_ */ diff --git a/docshell/base/timeline/moz.build b/docshell/base/timeline/moz.build index 7c06af163099..bbdefa6b48fa 100644 --- a/docshell/base/timeline/moz.build +++ b/docshell/base/timeline/moz.build @@ -7,11 +7,13 @@ EXPORTS.mozilla += [ 'AutoGlobalTimelineMarker.h', 'AutoTimelineMarker.h', + 'TimelineConsumers.h', ] UNIFIED_SOURCES += [ 'AutoGlobalTimelineMarker.cpp', 'AutoTimelineMarker.cpp', + 'TimelineConsumers.cpp', 'TimelineMarker.cpp', ] diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 3c4ce1a28b54..26e7eb8ff9dc 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -23,6 +23,7 @@ #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/Event.h" +#include "mozilla/TimelineConsumers.h" #include "EventListenerService.h" #include "nsCOMArray.h" @@ -1124,7 +1125,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext, nsCOMPtr docShell; bool isTimelineRecording = false; if (mIsMainThreadELM && - nsDocShell::gProfileTimelineRecordingsCount > 0 && + !TimelineConsumers::IsEmpty() && listener->mListenerType != Listener::eNativeListener) { docShell = GetDocShellForTarget(); if (docShell) { diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index 6bdd020908ec..f51b111af220 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -64,6 +64,7 @@ #include "mozilla/VsyncDispatcher.h" #include "nsThreadUtils.h" #include "mozilla/unused.h" +#include "mozilla/TimelineConsumers.h" #ifdef MOZ_NUWA_PROCESS #include "ipc/Nuwa.h" @@ -993,7 +994,7 @@ RefreshDriverTimer* nsRefreshDriver::ChooseTimer() const { if (mThrottled) { - if (!sThrottledRateTimer) + if (!sThrottledRateTimer) sThrottledRateTimer = new InactiveRefreshDriverTimer(GetThrottledTimerInterval(), DEFAULT_INACTIVE_TIMER_DISABLE_SECONDS * 1000.0); return sThrottledRateTimer; @@ -1051,7 +1052,7 @@ nsRefreshDriver::~nsRefreshDriver() MOZ_ASSERT(ObserverCount() == 0, "observers should have unregistered"); MOZ_ASSERT(!mActiveTimer, "timer should be gone"); - + if (mRootRefresh) { mRootRefresh->RemoveRefreshObserver(this, Flush_Style); mRootRefresh = nullptr; @@ -1436,7 +1437,7 @@ HasPendingAnimations(nsIPresShell* aShell) static void GetProfileTimelineSubDocShells(nsDocShell* aRootDocShell, nsTArray& aShells) { - if (!aRootDocShell || nsDocShell::gProfileTimelineRecordingsCount == 0) { + if (!aRootDocShell || TimelineConsumers::IsEmpty()) { return; }