Bug 1183229 - Add a way to count the number of timeline-observed docshells outside of nsDocShell, r=smaug

This commit is contained in:
Victor Porof 2015-07-18 09:35:59 -04:00
Родитель 6c5bb0422e
Коммит 58593a8714
9 изменённых файлов: 77 добавлений и 14 удалений

Просмотреть файл

@ -2929,8 +2929,6 @@ nsDocShell::HistoryTransactionRemoved(int32_t aIndex)
return NS_OK;
}
unsigned long nsDocShell::gProfileTimelineRecordingsCount = 0;
mozilla::LinkedList<nsDocShell::ObservedDocShell>* 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);

Просмотреть файл

@ -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<TimelineMarker>&& aMarker);
// Global counter for how many docShells are currently recording profile
// timeline markers
static unsigned long gProfileTimelineRecordingsCount;
class ObservedDocShell : public mozilla::LinkedListElement<ObservedDocShell>
{
public:

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -15,7 +15,7 @@ bool
AutoTimelineMarker::DocShellIsRecording(nsDocShell& aDocShell)
{
bool isRecording = false;
if (nsDocShell::gProfileTimelineRecordingsCount > 0) {
if (!TimelineConsumers::IsEmpty()) {
aDocShell.GetRecordProfileTimelineMarkers(&isRecording);
}
return isRecording;

Просмотреть файл

@ -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

Просмотреть файл

@ -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_ */

Просмотреть файл

@ -7,11 +7,13 @@
EXPORTS.mozilla += [
'AutoGlobalTimelineMarker.h',
'AutoTimelineMarker.h',
'TimelineConsumers.h',
]
UNIFIED_SOURCES += [
'AutoGlobalTimelineMarker.cpp',
'AutoTimelineMarker.cpp',
'TimelineConsumers.cpp',
'TimelineMarker.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<nsIDocShell> docShell;
bool isTimelineRecording = false;
if (mIsMainThreadELM &&
nsDocShell::gProfileTimelineRecordingsCount > 0 &&
!TimelineConsumers::IsEmpty() &&
listener->mListenerType != Listener::eNativeListener) {
docShell = GetDocShellForTarget();
if (docShell) {

Просмотреть файл

@ -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"
@ -1436,7 +1437,7 @@ HasPendingAnimations(nsIPresShell* aShell)
static void GetProfileTimelineSubDocShells(nsDocShell* aRootDocShell,
nsTArray<nsDocShell*>& aShells)
{
if (!aRootDocShell || nsDocShell::gProfileTimelineRecordingsCount == 0) {
if (!aRootDocShell || TimelineConsumers::IsEmpty()) {
return;
}