Bug 1407810 - Enable DDLogging from the beginning if MOZ_LOG contains DDLogger - r=jwwang
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 04 Dec 2017 10:52:51 +1100
changeset 708983 ce2d2aa44948bf070b7ae8e9fab13c11d3d2b2a9
parent 708982 11d29f2ac55d2223ff18ba843deefea7c18ea703
child 708984 ee5648a75a04332ddeaa2ad244d55e5bf9cd64d6
push id92501
push userdgottwald@mozilla.com
push dateThu, 07 Dec 2017 11:26:02 +0000
reviewersjwwang
bugs1407810
milestone59.0a1
Bug 1407810 - Enable DDLogging from the beginning if MOZ_LOG contains DDLogger - r=jwwang This allows logging from the command line without using a webextension. MozReview-Commit-ID: 6pkDbLXzz3X
dom/media/doctor/DecoderDoctorLogger.cpp
dom/media/doctor/DecoderDoctorLogger.h
layout/build/nsLayoutStatics.cpp
--- a/dom/media/doctor/DecoderDoctorLogger.cpp
+++ b/dom/media/doctor/DecoderDoctorLogger.cpp
@@ -16,16 +16,26 @@ namespace mozilla {
 
 /* static */ Atomic<DecoderDoctorLogger::LogState, ReleaseAcquire>
   DecoderDoctorLogger::sLogState{ DecoderDoctorLogger::scDisabled };
 
 /* static */ const char* DecoderDoctorLogger::sShutdownReason = nullptr;
 
 static DDMediaLogs* sMediaLogs;
 
+/* static */ void
+DecoderDoctorLogger::Init()
+{
+  MOZ_ASSERT(static_cast<LogState>(sLogState) == scDisabled);
+  if (MOZ_LOG_TEST(sDecoderDoctorLoggerLog, LogLevel::Error) ||
+      MOZ_LOG_TEST(sDecoderDoctorLoggerEndLog, LogLevel::Error)) {
+    EnableLogging();
+  }
+}
+
 // First DDLogShutdowner sets sLogState to scShutdown, to prevent further
 // logging.
 struct DDLogShutdowner
 {
   ~DDLogShutdowner()
   {
     DDL_INFO("Shutting down");
     // Prevent further logging, some may racily seep in, it's fine as the
--- a/dom/media/doctor/DecoderDoctorLogger.h
+++ b/dom/media/doctor/DecoderDoctorLogger.h
@@ -32,16 +32,20 @@ namespace mozilla {
 //
 // A separate thread processes log messages, and can asynchronously retrieve
 // processed messages that correspond to a given HTMLMediaElement.
 // That thread is also responsible for removing dated messages, so as not to
 // take too much memory.
 class DecoderDoctorLogger
 {
 public:
+  // Called by nsLayoutStatics::Initialize() before any other media work.
+  // Pre-enables logging if MOZ_LOG requires DDLogger.
+  static void Init();
+
   // Is logging currently enabled? This is tested anyway in all public `Log...`
   // functions, but it may be used to prevent logging-only work in clients.
   static inline bool IsDDLoggingEnabled()
   {
     return MOZ_UNLIKELY(static_cast<LogState>(sLogState) == scEnabled);
   }
 
   // Shutdown logging. This will prevent more messages to be queued, but the
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -111,16 +111,17 @@
 #include "nsCookieService.h"
 #include "nsApplicationCacheService.h"
 #include "mozilla/dom/CustomElementRegistry.h"
 #include "mozilla/dom/time/DateCacheCleaner.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/dom/HTMLVideoElement.h"
 #include "TouchManager.h"
+#include "DecoderDoctorLogger.h"
 #include "MediaDecoder.h"
 #include "MediaPrefs.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/StaticPresData.h"
 #include "mozilla/StylePrefs.h"
 #include "mozilla/dom/WebIDLGlobalNameHash.h"
 #include "mozilla/dom/ipc/IPCBlobInputStreamStorage.h"
 #include "mozilla/dom/U2FTokenManager.h"
@@ -249,16 +250,17 @@ nsLayoutStatics::Initialize()
 
   rv = nsFocusManager::Init();
   if (NS_FAILED(rv)) {
     NS_ERROR("Could not initialize nsFocusManager");
     return rv;
   }
 
   AsyncLatencyLogger::InitializeStatics();
+  DecoderDoctorLogger::Init();
   MediaManager::StartupInit();
   CubebUtils::InitLibrary();
 
   nsContentSink::InitializeStatics();
   nsHtml5Module::InitializeStatics();
   mozilla::dom::FallbackEncoding::Initialize();
   nsLayoutUtils::Initialize();
   PointerEventHandler::InitializeStatics();