Bug 1247056 - Refactor ReportToConsole and ReportAnalysis to be static - r=jwwang draft
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 07 Sep 2016 19:22:25 -0700
changeset 417920 c7bef854434e
parent 417919 0beec5d67050
child 417921 e520e32bd420
push id30524
push usergsquelart@mozilla.com
push dateTue, 27 Sep 2016 09:30:55 +0000
reviewersjwwang
bugs1247056
milestone52.0a1
Bug 1247056 - Refactor ReportToConsole and ReportAnalysis to be static - r=jwwang This will be useful to call them from outside of DecoderDoctorWatcher. MozReview-Commit-ID: C7Hq8kwONQO
dom/media/DecoderDoctorDiagnostics.cpp
--- a/dom/media/DecoderDoctorDiagnostics.cpp
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -75,20 +75,16 @@ private:
   static void DestroyPropertyCallback(void* aObject,
                                       nsIAtom* aPropertyName,
                                       void* aPropertyValue,
                                       void* aData);
 
   static const uint32_t sAnalysisPeriod_ms = 1000;
   void EnsureTimerIsStarted();
 
-  void ReportAnalysis(const NotificationAndReportStringId& aNotification,
-                      bool aIsSolved,
-                      const nsAString& aFormats);
-
   void SynthesizeAnalysis();
 
   // Raw pointer to an nsIDocument.
   // Must be non-null during construction.
   // Nulled when we want to stop watching, because either:
   // 1. The document has been destroyed (notified through
   //    DestroyPropertyCallback).
   // 2. We have not received new diagnostic information within a short time
@@ -306,57 +302,68 @@ DispatchNotification(nsISupports* aSubje
   }
   DD_DEBUG("DecoderDoctorDiagnostics/DispatchEvent() %s", NS_ConvertUTF16toUTF8(json).get());
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (obs) {
     obs->NotifyObservers(aSubject, "decoder-doctor-notification", json.get());
   }
 }
 
-void
-DecoderDoctorDocumentWatcher::ReportAnalysis(
-  const NotificationAndReportStringId& aNotification,
-  bool aIsSolved,
-  const nsAString& aParams)
+static void
+ReportToConsole(nsIDocument* aDocument,
+                const char* aConsoleStringId,
+                const nsAString& aParams)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aDocument);
+
+  // 'params' will only be forwarded for non-empty strings.
+  const char16_t* params[1] = { aParams.Data() };
+  DD_DEBUG("DecoderDoctorDiagnostics.cpp:ReportToConsole(doc=%p) ReportToConsole - aMsg='%s' params[0]='%s'",
+           aDocument, aConsoleStringId,
+           aParams.IsEmpty() ? "<no params>" : NS_ConvertUTF16toUTF8(params[0]).get());
+  nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
+                                  NS_LITERAL_CSTRING("Media"),
+                                  aDocument,
+                                  nsContentUtils::eDOM_PROPERTIES,
+                                  aConsoleStringId,
+                                  aParams.IsEmpty() ? nullptr : params,
+                                  aParams.IsEmpty() ? 0 : 1);
+}
+
+static void
+ReportAnalysis(nsIDocument* aDocument,
+               const NotificationAndReportStringId& aNotification,
+               bool aIsSolved,
+               const nsAString& aParams)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (!mDocument) {
+  if (!aDocument) {
     return;
   }
 
   // Report non-solved issues to console.
   if (!aIsSolved) {
-    // 'params' will only be forwarded for non-empty strings.
-    const char16_t* params[1] = { aParams.Data() };
-    DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::ReportAnalysis() ReportToConsole - aMsg='%s' params[0]='%s'",
-             this, mDocument, aNotification.mReportStringId,
-             aParams.IsEmpty() ? "<no params>" : NS_ConvertUTF16toUTF8(params[0]).get());
-    nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
-                                    NS_LITERAL_CSTRING("Media"),
-                                    mDocument,
-                                    nsContentUtils::eDOM_PROPERTIES,
-                                    aNotification.mReportStringId,
-                                    aParams.IsEmpty() ? nullptr : params,
-                                    aParams.IsEmpty() ? 0 : 1);
+    ReportToConsole(aDocument, aNotification.mReportStringId, aParams);
   }
 
   // "media.decoder-doctor.notifications-allowed" controls which notifications
   // may be dispatched to the front-end. It either contains:
   // - '*' -> Allow everything.
   // - Comma-separater list of ids -> Allow if aReportStringId (from
   //                                  dom.properties) is one of them.
   // - Nothing (missing or empty) -> Disable everything.
   nsAdoptingCString filter =
     Preferences::GetCString("media.decoder-doctor.notifications-allowed");
   filter.StripWhitespace();
   if (filter.EqualsLiteral("*")
       || StringListContains(filter, aNotification.mReportStringId)) {
     DispatchNotification(
-      mDocument->GetInnerWindow(), aNotification, aIsSolved, aParams);
+      aDocument->GetInnerWindow(), aNotification, aIsSolved, aParams);
   }
 }
 
 enum SilverlightPresence {
   eNoSilverlight,
   eSilverlightDisabled,
   eSilverlightEnabled
 };
@@ -502,17 +509,17 @@ DecoderDoctorDocumentWatcher::Synthesize
         for (const auto& workingFormat : MakeStringListRange(*workingFormats)) {
           if (FormatsListContains(formatsWithIssues, workingFormat)) {
             // This now-working format used not to work -> Report solved issue.
             DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - %s solved ('%s' now works, it was in pref(%s)='%s')",
                     this, mDocument, id->mReportStringId,
                     NS_ConvertUTF16toUTF8(workingFormat).get(),
                     formatsPref.Data(),
                     NS_ConvertUTF16toUTF8(formatsWithIssues).get());
-            ReportAnalysis(*id, true, workingFormat);
+            ReportAnalysis(mDocument, *id, true, workingFormat);
             // This particular Notification&ReportId has been solved, no need
             // to keep looking at other keysys/formats that might solve it too.
             solved = true;
             break;
           }
         }
         if (solved) {
           break;
@@ -529,18 +536,18 @@ DecoderDoctorDocumentWatcher::Synthesize
   // Look at Key System issues first, as they take precedence over format checks.
   if (!unsupportedKeySystems.IsEmpty() && supportedKeySystems.IsEmpty()) {
     // No supported key systems!
     switch (lastKeySystemIssue) {
       case DecoderDoctorDiagnostics::eWidevineWithNoWMF:
         if (CheckSilverlight() != eSilverlightEnabled) {
           DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unsupported key systems: %s, widevine without WMF nor Silverlight",
                   this, mDocument, NS_ConvertUTF16toUTF8(unsupportedKeySystems).get());
-          ReportAnalysis(
-            sMediaWidevineNoWMFNoSilverlight, false, unsupportedKeySystems);
+          ReportAnalysis(mDocument, sMediaWidevineNoWMFNoSilverlight,
+                         false, unsupportedKeySystems);
           return;
         }
         break;
       default:
         break;
     }
   }
 
@@ -550,44 +557,46 @@ DecoderDoctorDocumentWatcher::Synthesize
     if (playableFormats.IsEmpty()) {
       // No requested formats can be played. See if we can help the user, by
       // going through expected decoders from most to least desirable.
 #if defined(XP_WIN)
       if (!formatsRequiringWMF.IsEmpty()) {
         if (IsVistaOrLater()) {
           DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media because WMF was not found",
                   this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringWMF).get());
-          ReportAnalysis(sMediaWMFNeeded, false, formatsRequiringWMF);
+          ReportAnalysis(mDocument, sMediaWMFNeeded, false, formatsRequiringWMF);
         } else {
           DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media before Windows Vista",
                   this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringWMF).get());
-          ReportAnalysis(sMediaUnsupportedBeforeWindowsVista, false, formatsRequiringWMF);
+          ReportAnalysis(mDocument, sMediaUnsupportedBeforeWindowsVista,
+                         false, formatsRequiringWMF);
         }
         return;
       }
 #endif
 #if defined(MOZ_FFMPEG)
       if (!formatsRequiringFFMpeg.IsEmpty()) {
         DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media because platform decoder was not found",
                 this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringFFMpeg).get());
-        ReportAnalysis(sMediaPlatformDecoderNotFound,
+        ReportAnalysis(mDocument, sMediaPlatformDecoderNotFound,
                        false, formatsRequiringFFMpeg);
         return;
       }
 #endif
       DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Cannot play media, unplayable formats: %s",
               this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get());
-      ReportAnalysis(sMediaCannotPlayNoDecoders, false, unplayableFormats);
+      ReportAnalysis(mDocument, sMediaCannotPlayNoDecoders,
+                     false, unplayableFormats);
       return;
     }
 
     DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, but no decoders for some requested formats: %s",
             this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get());
     if (Preferences::GetBool("media.decoder-doctor.verbose", false)) {
-      ReportAnalysis(sMediaNoDecoders, false, unplayableFormats);
+      ReportAnalysis(mDocument, sMediaNoDecoders, false, unplayableFormats);
     }
     return;
   }
   DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, decoders available for all requested formats",
            this, mDocument);
 }
 
 void