/* -*- 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/. */
// Log module for nsObserverService logging... // // To enable logging (see prlog.h for full details): // // set MOZ_LOG=ObserverService:5 // set MOZ_LOG_FILE=service.log // // This enables LogLevel::Debug level information and places all output in // the file service.log. static mozilla::LazyLogModule sObserverServiceLog("ObserverService"); #define LOG(x) MOZ_LOG(sObserverServiceLog, mozilla::LogLevel::Debug, x)
// Keep track of topics that have a suspiciously large number // of referents (symptom of leaks).
size_t topicTotal = topicNumStrong + topicNumWeakAlive + topicNumWeakDead; if (topicTotal > kSuspectReferentCount) {
SuspectObserver suspect(observerList->GetKey(), topicTotal);
suspectObservers.AppendElement(suspect);
}
}
// These aren't privacy-sensitive and so don't need anonymizing. for (uint32_t i = 0; i < suspectObservers.Length(); i++) {
SuspectObserver& suspect = suspectObservers[i];
nsPrintfCString suspectPath("observer-service-suspect/referent(topic=%s)",
suspect.mTopic);
aHandleReport->Callback( /* process */ ""_ns, suspectPath, KIND_OTHER, UNITS_COUNT,
suspect.mReferentCount,
nsLiteralCString("A topic with a suspiciously large number of " "referents. This may be symptomatic of a leak " "if the number of referents is high with " "respect to the number of windows."),
aData);
}
MOZ_COLLECT_REPORT( "observer-service/referent/strong", KIND_OTHER, UNITS_COUNT,
totalNumStrong, "The number of strong references held by the observer service.");
MOZ_COLLECT_REPORT( "observer-service/referent/weak/alive", KIND_OTHER, UNITS_COUNT,
totalNumWeakAlive, "The number of weak references held by the observer service that are " "still alive.");
MOZ_COLLECT_REPORT( "observer-service/referent/weak/dead", KIND_OTHER, UNITS_COUNT,
totalNumWeakDead, "The number of weak references held by the observer service that are " "dead.");
RefPtr<nsObserverService> os = new nsObserverService();
// The memory reporter can not be immediately registered here because // the nsMemoryReporterManager may attempt to get the nsObserverService // during initialization, causing a recursive GetService.
NS_DispatchToCurrentThread(
NewRunnableMethod("nsObserverService::RegisterReporter", os,
&nsObserverService::RegisterReporter));
return os->QueryInterface(aIID, aInstancePtr);
}
nsresult nsObserverService::EnsureValidCall() const { if (!NS_IsMainThread()) {
MOZ_CRASH("Using observer service off the main thread!"); return NS_ERROR_UNEXPECTED;
}
if (mShuttingDown) {
NS_ERROR("Using observer service after XPCOM shutdown!"); return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
}
return NS_OK;
}
nsresult nsObserverService::FilterHttpOnTopics(constchar* aTopic) { // Specifically allow some http-on-* observer notifications in the child // process. if (mozilla::net::IsNeckoChild() && !strncmp(aTopic, "http-on-", 8) &&
strcmp(aTopic, "http-on-before-stop-request") &&
strcmp(aTopic, "http-on-failed-opening-request") &&
strcmp(aTopic, "http-on-resource-cache-response") &&
strcmp(aTopic, "http-on-opening-request") &&
strcmp(aTopic, "http-on-stop-request")) {
nsCOMPtr<nsIConsoleService> console(
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
nsCOMPtr<nsIScriptError> error(
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
error->Init(u"http-on-* observers only work in the parent process"_ns, ""_ns, 0, 0, nsIScriptError::warningFlag, "chrome javascript"_ns, false/* from private window */, true/* from chrome context */);
console->LogMessage(error);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.