From 58593a87143d77694bed68a95f482638abc3c94a Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Sat, 18 Jul 2015 09:35:59 -0400 Subject: [PATCH] Bug 1183229 - Add a way to count the number of timeline-observed docshells outside of nsDocShell, r=smaug --- docshell/base/nsDocShell.cpp | 6 ++-- docshell/base/nsDocShell.h | 5 +-- .../timeline/AutoGlobalTimelineMarker.cpp | 3 +- docshell/base/timeline/AutoTimelineMarker.cpp | 2 +- docshell/base/timeline/TimelineConsumers.cpp | 31 ++++++++++++++++++ docshell/base/timeline/TimelineConsumers.h | 32 +++++++++++++++++++ docshell/base/timeline/moz.build | 2 ++ dom/events/EventListenerManager.cpp | 3 +- layout/base/nsRefreshDriver.cpp | 7 ++-- 9 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 docshell/base/timeline/TimelineConsumers.cpp create mode 100644 docshell/base/timeline/TimelineConsumers.h diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 6ded2df52eb7..05d61cb297a0 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 27e7197c6a64..6c1a1b943d61 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" @@ -1122,7 +1123,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; }