Bug 1562021 - part1 : modify debug log for WebVTTListener. r=jya
authorAlastor Wu <alwu@mozilla.com>
Wed, 03 Jul 2019 23:07:43 +0000
changeset 481449 602865e4e969900b82d0fc740fabd9ef34c01d2f
parent 481448 c7e91f614eb78c4447a623f1c88a66421113ab07
child 481450 da1f4f3f0c5c27d5fe228b7e0c8c8ef05ca010ac
push id36246
push usermalexandru@mozilla.com
push dateSat, 06 Jul 2019 03:34:49 +0000
treeherdermozilla-central@ea6af5ad89e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1562021
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1562021 - part1 : modify debug log for WebVTTListener. r=jya Refactor these log by using the `WebVTT` log module and adding address info in the log. Differential Revision: https://phabricator.services.mozilla.com/D36405
dom/media/WebVTTListener.cpp
--- a/dom/media/WebVTTListener.cpp
+++ b/dom/media/WebVTTListener.cpp
@@ -9,54 +9,58 @@
 #include "mozilla/dom/TextTrackCue.h"
 #include "mozilla/dom/TextTrackRegion.h"
 #include "mozilla/dom/VTTRegionBinding.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsIInputStream.h"
 #include "nsIWebVTTParserWrapper.h"
 
+extern mozilla::LazyLogModule gTextTrackLog;
+#define LOG(msg, ...)                     \
+  MOZ_LOG(gTextTrackLog, LogLevel::Debug, \
+          ("WebVTTListener=%p, " msg, this, ##__VA_ARGS__))
+#define LOG_WIHTOUT_ADDRESS(msg, ...) \
+  MOZ_LOG(gTextTrackLog, LogLevel::Debug, (msg, ##__VA_ARGS__))
+
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION(WebVTTListener, mElement, mParserWrapper)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebVTTListener)
   NS_INTERFACE_MAP_ENTRY(nsIWebVTTListener)
   NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
   NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
   NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebVTTListener)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebVTTListener)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebVTTListener)
 
-LazyLogModule gTextTrackLog("TextTrack");
-#define VTT_LOG(...) MOZ_LOG(gTextTrackLog, LogLevel::Debug, (__VA_ARGS__))
-
 WebVTTListener::WebVTTListener(HTMLTrackElement* aElement)
     : mElement(aElement), mParserWrapperError(NS_OK) {
   MOZ_ASSERT(mElement, "Must pass an element to the callback");
-  VTT_LOG("WebVTTListener created.");
+  LOG("Created listener for track element %p", aElement);
   MOZ_DIAGNOSTIC_ASSERT(
       CycleCollectedJSContext::Get() &&
       !CycleCollectedJSContext::Get()->IsInStableOrMetaStableState());
   mParserWrapper = do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID,
                                      &mParserWrapperError);
   if (NS_SUCCEEDED(mParserWrapperError)) {
     nsPIDOMWindowInner* window = mElement->OwnerDoc()->GetInnerWindow();
     mParserWrapperError = mParserWrapper->LoadParser(window);
   }
   if (NS_SUCCEEDED(mParserWrapperError)) {
     mParserWrapperError = mParserWrapper->Watch(this);
   }
 }
 
-WebVTTListener::~WebVTTListener() { VTT_LOG("WebVTTListener destroyed."); }
+WebVTTListener::~WebVTTListener() { LOG("destroyed."); }
 
 NS_IMETHODIMP
 WebVTTListener::GetInterface(const nsIID& aIID, void** aResult) {
   return QueryInterface(aIID, aResult);
 }
 
 nsresult WebVTTListener::LoadResource() {
   // Exit if we failed to create the WebVTTParserWrapper (vtt.jsm)
@@ -74,24 +78,25 @@ WebVTTListener::AsyncOnChannelRedirect(n
     mElement->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
   }
   cb->OnRedirectVerifyCallback(NS_OK);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebVTTListener::OnStartRequest(nsIRequest* aRequest) {
-  VTT_LOG("WebVTTListener::OnStartRequest\n");
+  LOG("OnStartRequest");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebVTTListener::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
-  VTT_LOG("WebVTTListener::OnStopRequest\n");
+  LOG("OnStopRequest");
   if (NS_FAILED(aStatus)) {
+    LOG("Got error status");
     mElement->SetReadyState(TextTrackReadyState::FailedToLoad);
   }
   // Attempt to parse any final data the parser might still have.
   mParserWrapper->Flush();
   if (mElement->ReadyState() != TextTrackReadyState::FailedToLoad) {
     mElement->SetReadyState(TextTrackReadyState::Loaded);
   }
 
@@ -103,29 +108,31 @@ WebVTTListener::OnStopRequest(nsIRequest
 nsresult WebVTTListener::ParseChunk(nsIInputStream* aInStream, void* aClosure,
                                     const char* aFromSegment,
                                     uint32_t aToOffset, uint32_t aCount,
                                     uint32_t* aWriteCount) {
   nsCString buffer(aFromSegment, aCount);
   WebVTTListener* listener = static_cast<WebVTTListener*>(aClosure);
 
   if (NS_FAILED(listener->mParserWrapper->Parse(buffer))) {
-    VTT_LOG("Unable to parse chunk of WEBVTT text. Aborting.");
+    LOG_WIHTOUT_ADDRESS(
+        "WebVTTListener=%p, Unable to parse chunk of WEBVTT text. Aborting.",
+        listener);
     *aWriteCount = 0;
     return NS_ERROR_FAILURE;
   }
 
   *aWriteCount = aCount;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebVTTListener::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* aStream,
                                 uint64_t aOffset, uint32_t aCount) {
-  VTT_LOG("WebVTTListener::OnDataAvailable\n");
+  LOG("OnDataAvailable");
   uint32_t count = aCount;
   while (count > 0) {
     uint32_t read;
     nsresult rv = aStream->ReadSegments(ParseChunk, this, count, &read);
     NS_ENSURE_SUCCESS(rv, rv);
     if (!read) {
       return NS_ERROR_FAILURE;
     }
@@ -158,15 +165,16 @@ WebVTTListener::OnRegion(JS::Handle<JS::
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WebVTTListener::OnParsingError(int32_t errorCode, JSContext* cx) {
   // We only care about files that have a bad WebVTT file signature right now
   // as that means the file failed to load.
   if (errorCode == ErrorCodes::BadSignature) {
+    LOG("parsing error");
     mElement->SetReadyState(TextTrackReadyState::FailedToLoad);
   }
   return NS_OK;
 }
 
 }  // namespace dom
 }  // namespace mozilla