Bug 1407810 - Enable DDLogging from the beginning if MOZ_LOG contains DDLogger - r?jwwang draft
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 04 Dec 2017 10:52:51 +1100
changeset 708715 bacf05323ce51184976c71081b5d82b65e7a9fef
parent 708714 85f6bf26fb34d4bd9016de4c087a40120d7c52bc
child 708716 6a7b0120b715697eb74c93a819729b7cd92fd22a
push id92413
push usergsquelart@mozilla.com
push dateWed, 06 Dec 2017 23:54:05 +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();